Subversion Repositories eFlore/Applications.coel

Rev

Rev 446 | Rev 461 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
127 gduche 1
package org.tela_botanica.client.vues;
2
 
283 gduche 3
import java.util.ArrayList;
352 gduche 4
import java.util.Collection;
376 gduche 5
import java.util.Date;
276 gduche 6
import java.util.HashMap;
283 gduche 7
import java.util.Iterator;
352 gduche 8
import java.util.LinkedList;
283 gduche 9
import java.util.List;
276 gduche 10
 
11
import org.tela_botanica.client.ComposantClass;
12
import org.tela_botanica.client.Mediateur;
13
import org.tela_botanica.client.RegistreId;
127 gduche 14
import org.tela_botanica.client.interfaces.Rafraichissable;
283 gduche 15
import org.tela_botanica.client.modeles.Configuration;
280 gduche 16
import org.tela_botanica.client.modeles.InterneValeur;
293 gduche 17
 
352 gduche 18
import org.tela_botanica.client.modeles.Information;
286 gduche 19
import org.tela_botanica.client.modeles.Personne;
352 gduche 20
import org.tela_botanica.client.modeles.PersonneListe;
456 gduche 21
import org.tela_botanica.client.modeles.Projet;
22
import org.tela_botanica.client.modeles.ProjetListe;
280 gduche 23
import org.tela_botanica.client.modeles.Valeur;
283 gduche 24
import org.tela_botanica.client.modeles.ValeurListe;
127 gduche 25
 
446 gduche 26
import com.extjs.gxt.ui.client.Events;
276 gduche 27
import com.extjs.gxt.ui.client.Registry;
28
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
283 gduche 29
import com.extjs.gxt.ui.client.Style.Scroll;
386 gduche 30
 
376 gduche 31
import com.extjs.gxt.ui.client.binding.FormBinding;
386 gduche 32
 
276 gduche 33
import com.extjs.gxt.ui.client.event.ComponentEvent;
34
import com.extjs.gxt.ui.client.event.KeyListener;
446 gduche 35
import com.extjs.gxt.ui.client.event.Listener;
280 gduche 36
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
37
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 38
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 39
import com.extjs.gxt.ui.client.store.ListStore;
127 gduche 40
import com.extjs.gxt.ui.client.widget.LayoutContainer;
319 gduche 41
import com.extjs.gxt.ui.client.widget.MessageBox;
338 gduche 42
 
386 gduche 43
import com.extjs.gxt.ui.client.widget.Info;
276 gduche 44
import com.extjs.gxt.ui.client.widget.TabItem;
45
import com.extjs.gxt.ui.client.widget.TabPanel;
293 gduche 46
import com.extjs.gxt.ui.client.widget.Text;
283 gduche 47
 
356 gduche 48
import com.extjs.gxt.ui.client.widget.button.Button;
49
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
319 gduche 50
import com.extjs.gxt.ui.client.widget.button.IconButton;
280 gduche 51
import com.extjs.gxt.ui.client.widget.form.ComboBox;
52
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 53
import com.extjs.gxt.ui.client.widget.form.FieldSet;
352 gduche 54
import com.extjs.gxt.ui.client.widget.form.FormPanel;
293 gduche 55
import com.extjs.gxt.ui.client.widget.form.HiddenField;
276 gduche 56
import com.extjs.gxt.ui.client.widget.form.LabelField;
446 gduche 57
import com.extjs.gxt.ui.client.widget.form.Radio;
58
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
286 gduche 59
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 60
import com.extjs.gxt.ui.client.widget.form.TextField;
456 gduche 61
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
276 gduche 62
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
63
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
64
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
319 gduche 65
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 66
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
356 gduche 67
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
276 gduche 68
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
69
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
386 gduche 70
import com.google.gwt.core.client.GWT;
339 gduche 71
import com.google.gwt.i18n.client.DateTimeFormat;
276 gduche 72
import com.google.gwt.user.client.ui.Widget;
127 gduche 73
 
446 gduche 74
public class PersonneForm extends FormPanel implements Rafraichissable {
127 gduche 75
 
276 gduche 76
	/*--------------------------------------------------------------------------------------
77
	 * 		VARIABLES
78
	 * -------------------------------------------------------------------------------------
79
	 */
80
 
81
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
283 gduche 82
	private Mediateur mediateur = Registry.get(RegistreId.MEDIATEUR);
83
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
376 gduche 84
	private Personne personneSelectionnee, personneSauvegarde = null;
456 gduche 85
	private String mode = "";
276 gduche 86
 
456 gduche 87
	public static final String MODE_AJOUTER = "AJOUT";
88
	public static final String MODE_MODIFIER = "MODIF";
89
 
90
 
376 gduche 91
	private FormBinding binding = null;
92
 
276 gduche 93
	/*--------------------------------------------------------------------------------------
94
	 * 		CONSTRUCTEUR
95
	 * -------------------------------------------------------------------------------------
96
	 */
446 gduche 97
 
276 gduche 98
	/**
99
	 * Constructeur du panneau
100
	 *
101
	 * Initialise le panneau et ajoute une barre d'outils à deux boutons (réinitialiser le
102
	 * formulaire et annuler la saisie).
103
	 *
104
	 * */
456 gduche 105
	public PersonneForm(String mode) {
106
 
107
		this.mode = mode;
386 gduche 108
		initialiserComposants();
352 gduche 109
	}
110
 
386 gduche 111
	public void initialiserComposants()	{
352 gduche 112
 
376 gduche 113
		personneSelectionnee = new Personne();
114
		personneSauvegarde = new Personne();
115
 
283 gduche 116
		initialiserPanneau();
276 gduche 117
 
356 gduche 118
		ButtonBar barreOutilsBas = new ButtonBar();
119
		barreOutilsBas.setButtonAlign(HorizontalAlignment.CENTER);
276 gduche 120
 
352 gduche 121
		ajouterBoutonEnregistrer(barreOutilsBas);
122
		ajouterBoutonEnregistrerEtRevenir(barreOutilsBas);
123
		ajouterBoutonAnnuler(barreOutilsBas);
276 gduche 124
 
352 gduche 125
		setBottomComponent(barreOutilsBas);
276 gduche 126
 
352 gduche 127
		ToolBar barreOutilsHaut = new ToolBar();
128
		ajouterBoutonReinitialiser(barreOutilsHaut);
129
		setTopComponent(barreOutilsHaut);
338 gduche 130
 
276 gduche 131
		initialiserOnglets();
132
 
133
		creerComposantsIdentite();
293 gduche 134
		creerComposantsAdresse();
280 gduche 135
 
352 gduche 136
		layout();
338 gduche 137
 
376 gduche 138
		binderPersonne(personneSelectionnee);
276 gduche 139
	}
140
 
141
	/*---------------------------------------------------------------------------------------
142
	 * 		SOUS-METHODES
143
	 * --------------------------------------------------------------------------------------
144
	 */
145
	/**
146
	 * Inialise le panneau donné
147
	 *
148
	 * @param contentPanel le panneau à initialiser
149
	 * */
283 gduche 150
	public void initialiserPanneau()	{
276 gduche 151
 
283 gduche 152
		setIconStyle("icone-form-ajouter");
153
		setCollapsible(false);
154
		setHeading("Ajouter une personne");
155
		setButtonAlign(HorizontalAlignment.CENTER);
386 gduche 156
		setLayout(new FitLayout());
376 gduche 157
		setBodyBorder(false);
158
		setBorders(false);
159
		setPadding(0);
160
		setWidth("100%");
446 gduche 161
 
276 gduche 162
	}
163
 
164
	/**
165
	 * Crée les onglets identité, adresse et informations naturaliste
166
	 *
167
	 * */
168
	public void initialiserOnglets()	{
169
		//TabPanel
170
		TabPanel formulaireOnglets = new TabPanel();
171
 
172
		//Tab 1 : identite
173
		tiIdentite = new TabItem("Identité");
174
		tiIdentite.setLayout(new FormLayout());
283 gduche 175
		tiIdentite.setScrollMode(Scroll.AUTO);
446 gduche 176
 
276 gduche 177
		formulaireOnglets.add(tiIdentite);
293 gduche 178
		hmIdentite.put("tiIdentite", tiIdentite);
276 gduche 179
 
180
		//Tab 2 : Adresse
181
		tiAdresses = new TabItem("Adresse");
304 gduche 182
		tiAdresses.setLayout(new FormLayout());
283 gduche 183
		tiAdresses.setScrollMode(Scroll.AUTO);
446 gduche 184
 
276 gduche 185
		formulaireOnglets.add(tiAdresses);
186
 
187
		//Tab 3 : Infos Naturalistes
188
		tiInfosNat = new TabItem("Informations Naturalistes");
189
		tiInfosNat.setLayout(new FormLayout());
283 gduche 190
		tiInfosNat.setScrollMode(Scroll.AUTO);
446 gduche 191
 
276 gduche 192
		formulaireOnglets.add(tiInfosNat);
193
		add(formulaireOnglets);
194
	}
195
 
196
	/**
197
	 * Crée les widgets pour l'onglet identité
198
	 *
199
	 * */
200
 
293 gduche 201
	//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite
276 gduche 202
	private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();
293 gduche 203
	private HashMap<String, Widget>hmAdresse = new HashMap<String, Widget>();
204
	private HashMap<String, Widget>hmInfosNat = new HashMap<String, Widget>();
319 gduche 205
	private FormData fd100 = new FormData("1");
276 gduche 206
 
207
	public void creerComposantsIdentite()	{
208
 
456 gduche 209
 
376 gduche 210
			// Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite
276 gduche 211
			LayoutContainer left = new LayoutContainer();
212
			left.setLayout(new FormLayout());
213
 
214
			LayoutContainer right = new LayoutContainer();
215
			right.setLayout(new FormLayout());
216
 
217
			LayoutContainer main = new LayoutContainer();
218
			main.setLayout(new ColumnLayout());
219
 
456 gduche 220
			main.add(left, new ColumnData(.5));
221
			main.add(right, new ColumnData(.5));
276 gduche 222
 
223
			// Création des champs
224
			FormLayout formLayout = new FormLayout();
225
			formLayout.setLabelAlign(LabelAlign.LEFT);
226
 
456 gduche 227
				FieldSet fsProjet = new FieldSet();
228
				fsProjet.setHeading("Projet");
229
				fsProjet.setLayout(new FormLayout());
230
 
231
					ListStore<Projet> storeProjets = new ListStore<Projet>();
232
					ComboBox cbProjets = new ComboBox<Projet>();
233
					cbProjets.setFieldLabel("Projet:");
234
					cbProjets.setLabelSeparator("");
235
					cbProjets.setDisplayField("nom");
236
					cbProjets.setEditable(false);
237
					cbProjets.setTriggerAction(TriggerAction.ALL);
238
					cbProjets.setStore(storeProjets);
239
					cbProjets.setAllowBlank(false);
240
					fsProjet.add(cbProjets);
241
 
242
					hmIdentite.put("cbProjets", cbProjets);
243
 
244
					mediateur.selectionnerProjets(this);
245
 
246
				left.add(fsProjet);
247
 
248
 
376 gduche 249
				FieldSet fsNoms = new FieldSet();
250
				fsNoms.setHeading("Noms");
251
				fsNoms.setLayout(formLayout);
456 gduche 252
 
376 gduche 253
					// Nom complet : Affiché que si valeurs saisies
254
					LabelField nomComplet = new LabelField();
255
					nomComplet.setFieldLabel("Nom complet:");
256
					nomComplet.hide();
257
 
258
					fsNoms.add(nomComplet);
259
					hmIdentite.put("nomComplet", nomComplet);
276 gduche 260
 
376 gduche 261
					//Préfixe
262
					ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
263
					ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
264
					cbPrefixe.setStore(storePrefixe);
265
					cbPrefixe.setDisplayField("nom");
266
					cbPrefixe.setEmptyText("Choisissez le préfixe:");
267
					cbPrefixe.setFieldLabel("Prefix");
268
 
269
					fsNoms.add(cbPrefixe);
270
					hmIdentite.put("cbPrefixe", cbPrefixe);
271
 
272
					mediateur.obtenirListeValeurEtRafraichir(this, "prefixe");
352 gduche 273
 
376 gduche 274
					//Prénom
275
					TextField<String> tfPrenom = new TextField<String>();
276
					tfPrenom.setFieldLabel("Prénom");
277
					tfPrenom.setName("prenom");
352 gduche 278
 
376 gduche 279
					fsNoms.add(tfPrenom);
280
					hmIdentite.put("tfPrenom", tfPrenom);
352 gduche 281
 
376 gduche 282
					//Nom
283
					TextField<String> tfNom = new TextField<String>();
284
					tfNom.setFieldLabel("Nom");
456 gduche 285
					tfNom.setAllowBlank(false);
376 gduche 286
					tfNom.setName("nom");
287
 
288
					fsNoms.add(tfNom);
289
					hmIdentite.put("tfNom", tfNom);
290
 
291
					//Suffixe
292
					ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
293
					ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
294
					cbSuffixe.setStore(storeSuffixe);
295
					cbSuffixe.setFieldLabel("Suffixe");
296
					cbSuffixe.setDisplayField("nom");
297
					cbSuffixe.setEmptyText("Choisissez un suffixe:");
298
 
299
					fsNoms.add(cbSuffixe);
300
					hmIdentite.put("cbSuffixe", cbSuffixe);
301
 
302
					mediateur.obtenirListeValeurEtRafraichir(this, "suffixes");
352 gduche 303
 
376 gduche 304
					TextField<String> tfNomAutre = new TextField();
305
					tfNomAutre.setFieldLabel("Autres noms");
386 gduche 306
					tfNomAutre.setName("truk_nom_autre");
376 gduche 307
 
308
					fsNoms.add(tfNomAutre);
309
					hmIdentite.put("tfNomAutre", tfNomAutre);
310
 
311
					TextField<String> tfAbreviation = new TextField<String>();
312
					tfAbreviation.setFieldLabel("Abréviation");
313
					tfAbreviation.setName("abreviation");
314
 
315
					fsNoms.add(tfAbreviation);
316
					hmIdentite.put("tfAbreviation", tfAbreviation);
446 gduche 317
 
376 gduche 318
					//Abréviation autres
319
					TextField<String> tfAbreviationAutre = new TextField<String>();
320
					tfAbreviationAutre.setFieldLabel("Autres Abrév.");
321
					tfAbreviationAutre.setName("truk_abreviation_autre");
322
 
323
					fsNoms.add(tfAbreviationAutre);
324
					hmIdentite.put("tfAbreviationAutre", tfAbreviationAutre);
325
 
326
				left.add(fsNoms);
276 gduche 327
 
376 gduche 328
				formLayout = new FormLayout();
329
				formLayout.setLabelAlign(LabelAlign.LEFT);
276 gduche 330
 
376 gduche 331
				FieldSet fsNaissance = new FieldSet();
332
				fsNaissance.setHeading("Naissance");
333
				fsNaissance.setLayout(formLayout);
352 gduche 334
 
376 gduche 335
					DateField dfDateNaissance = new DateField();
336
					dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
337
					dfDateNaissance.setFieldLabel("Date");
338
					dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
339
 
340
					fsNaissance.add(dfDateNaissance);
341
					hmIdentite.put("dfDateNaissance", dfDateNaissance);
342
 
343
					// Lieu naissance
344
					TextField<String> tfLieuNaissance = new TextField();
345
					tfLieuNaissance.setFieldLabel("Lieu");
346
					tfLieuNaissance.setName("naissance_lieu");
347
 
348
					fsNaissance.add(tfLieuNaissance);
349
					hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
350
 
351
				left.add(fsNaissance);
276 gduche 352
 
376 gduche 353
				formLayout = new FormLayout();
354
				formLayout.setLabelAlign(LabelAlign.LEFT);
276 gduche 355
 
376 gduche 356
				FieldSet fsDeces = new FieldSet();
357
				fsDeces.setHeading("Décès");
358
				fsDeces.setLayout(formLayout);
446 gduche 359
 
360
					Radio rbEstDecedee = new Radio();
361
					rbEstDecedee.setBoxLabel("oui");
362
 
363
					rbEstDecedee.addListener(Events.Change, new Listener<ComponentEvent>() {
364
 
365
						public void handleEvent(ComponentEvent be) {
366
							if(((Radio) be.component).getValue().equals(true))	{
367
								((DateField) hmIdentite.get("dfDateDeces")).setVisible(true);
368
								((TextField) hmIdentite.get("tfLieuDeces")).setVisible(true);
369
							} else	{
370
								((DateField) hmIdentite.get("dfDateDeces")).setVisible(false);
371
								((TextField) hmIdentite.get("tfLieuDeces")).setVisible(false);
372
							}
456 gduche 373
						}
446 gduche 374
					});
375
 
456 gduche 376
					hmIdentite.put("rbEstDecedee", rbEstDecedee);
446 gduche 377
 
378
					Radio rbNestPasDecedee = new Radio();
379
					rbNestPasDecedee.setBoxLabel("non");
380
					rbNestPasDecedee.setValue(true);
381
 
382
					RadioGroup rbgDeces = new RadioGroup();
383
					rbgDeces.setFieldLabel("Est décédée");
384
					rbgDeces.add(rbEstDecedee);
385
					rbgDeces.add(rbNestPasDecedee);
386
 
387
					fsDeces.add(rbgDeces);
388
 
376 gduche 389
					DateField dfDateDeces = new DateField();
390
					dfDateDeces.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
391
					dfDateDeces.setFormatValue(true);
392
					dfDateDeces.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
393
					dfDateDeces.setFieldLabel("Date");
446 gduche 394
					dfDateDeces.setVisible(false);
276 gduche 395
 
376 gduche 396
					fsDeces.add(dfDateDeces);
397
					hmIdentite.put("dfDateDeces", dfDateDeces);
446 gduche 398
 
376 gduche 399
					TextField<String> tfLieuDeces = new TextField();
400
					tfLieuDeces.setFieldLabel("Lieu");
401
					tfLieuDeces.setName("deces_lieu");
446 gduche 402
					tfLieuDeces.setVisible(false);
376 gduche 403
 
404
					fsDeces.add(tfLieuDeces);
405
					hmIdentite.put("tfLieuDeces", tfLieuDeces);
406
 
407
				left.add(fsDeces);
276 gduche 408
 
376 gduche 409
			tiIdentite.add(main);
283 gduche 410
 
376 gduche 411
				FieldSet fsContactTel = new FieldSet();
412
				fsContactTel.setHeading("Contact - Téléphones");
413
				fsContactTel.setLayout(new RowLayout());
414
 
415
				right.add(fsContactTel);
416
				hmIdentite.put("fsContactTel", fsContactTel);
417
 
418
					LayoutContainer lcTelephone = new LayoutContainer();
419
					lcTelephone.setLayout(new ColumnLayout());
420
 
421
						TextField tfTelephone = new TextField();
422
						tfTelephone.setFieldLabel("tel");
423
						lcTelephone.add(tfTelephone, new ColumnData(0.40));
424
 
425
						hmIdentite.put("tfTelephone", tfTelephone);
426
 
427
						ListStore<Valeur> storeTel = new ListStore<Valeur>();
428
						ComboBox<Valeur> cbTelephone = new ComboBox<Valeur>();
429
						cbTelephone.setDisplayField("nom");
430
						cbTelephone.setEmptyText("Choisissez:");
431
						cbTelephone.setStore(storeTel);
432
 
433
						lcTelephone.add(cbTelephone, new ColumnData(0.40));
434
						hmIdentite.put("cbTelephone", cbTelephone);
283 gduche 435
 
376 gduche 436
						mediateur.obtenirListeValeurEtRafraichir(this, "tel");
276 gduche 437
 
376 gduche 438
						IconButton bAjouter = new IconButton(ComposantClass.ICONE_AJOUTER);
439
						bAjouter.addSelectionListener(
440
								new SelectionListener<ComponentEvent>() {
441
									public void componentSelected(ComponentEvent ce) {
446 gduche 442
 
376 gduche 443
										String strTelephone = ((TextField<String>) hmIdentite.get("tfTelephone")).getValue();
444
										if ((strTelephone==null)||(strTelephone.trim().equals("")))	{
445
											MessageBox.alert("Erreur de saisie", "Vous devez saisir un numéro de téléphone", null);
446
										} else if (hmIdentite.get("tel-" + strTelephone) != null){
447
											MessageBox.alert("Erreur de saisie", "Le numéro saisi est déjà présent dans la liste", null);
448
										} else {
449
												String strValeurTypeTel = "";
450
												String idTel = "";
451
												Valeur valeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getValue();
452
 
453
												if (valeurTypeTel != null)	{
454
													strValeurTypeTel = valeurTypeTel.getNom();
455
													idTel = valeurTypeTel.get("abreviation");
456
												}	else {
457
													strValeurTypeTel = ((ComboBox<Valeur>) hmIdentite.get("cbTelephone")).getRawValue();
458
													idTel = strValeurTypeTel;
459
												}
446 gduche 460
 
376 gduche 461
												if (strValeurTypeTel.trim().equals(""))	{
462
													MessageBox.alert("Erreur de saisie", "Vous devez saisir un type de téléphone", null);
463
												}	else {
464
													ajouterTelephone(strTelephone, strValeurTypeTel, idTel);
465
												}
466
											}
467
										}
468
									}
469
								);
276 gduche 470
 
376 gduche 471
						lcTelephone.add(bAjouter, new ColumnData(0.15));
472
 
473
						HiddenField<String> hfTelephone = new HiddenField<String>();
474
						add(hfTelephone);
475
						hmIdentite.put("hfTelephone", hfTelephone);
476
 
477
					fsContactTel.add(lcTelephone);
276 gduche 478
 
376 gduche 479
					FieldSet fsContact = new FieldSet();
480
					fsContact.setHeading("Contact - Autres");
481
					fsContact.setId("fsContact");
482
					fsContact.setLayout(new RowLayout());
276 gduche 483
 
376 gduche 484
					right.add(fsContact);
485
					hmIdentite.put("fsContact", fsContact);
276 gduche 486
 
376 gduche 487
					LabelField lfCourriel = new LabelField();
488
					lfCourriel.setText("<b>Courriels:</b>");
276 gduche 489
 
376 gduche 490
					fsContact.add(lfCourriel);
276 gduche 491
 
376 gduche 492
					LayoutContainer lcCourriel = new LayoutContainer();
493
					lcCourriel.setLayout(new ColumnLayout());
276 gduche 494
 
376 gduche 495
						TextField tfCourriel = new TextField();
496
						lcCourriel.add(tfCourriel, new ColumnData(0.80));
497
 
498
						HiddenField hfHiddenCourriel = new HiddenField();
499
						hfHiddenCourriel.setId("tfHiddenCourriel");
500
						hfHiddenCourriel.setValue("");
446 gduche 501
 
376 gduche 502
						add(hfHiddenCourriel);
503
						hmIdentite.put("hfHiddenCourriel", hfHiddenCourriel);
504
						hmIdentite.put("tfCourriel", tfCourriel);
276 gduche 505
 
376 gduche 506
						IconButton bAjouterCourriel = new IconButton(ComposantClass.ICONE_AJOUTER);
507
						bAjouterCourriel.addSelectionListener(
508
								new SelectionListener<ComponentEvent>() {
509
 
510
									public void componentSelected(ComponentEvent ce) {
511
 
512
										String strEmail = ((TextField<String>) hmIdentite.get("tfCourriel")).getValue();
513
										if ((strEmail==null)||(strEmail.trim().equals("")))	{
514
											MessageBox.alert("Erreur de saisie", "Vous devez saisir une adresse", null);
515
										} else if (hmIdentite.get("email-" + strEmail) != null){
516
											MessageBox.alert("Erreur de saisie", "L'adresse saisie est déjà dans la liste", null);
517
										} else {
518
 
519
											if (!strEmail.matches("(\\w+)@(\\w+\\.)(\\w+)(\\.\\w+)*"))	{
520
												MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: me@domain.com)", null);
521
											} else if (strEmail.length()>255){
522
												MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
523
											} else {
524
												ajouterCourriel(strEmail);
525
											}
526
 
527
										}
528
 
529
 
530
									}
531
								});
276 gduche 532
 
376 gduche 533
						lcCourriel.add(bAjouterCourriel, new ColumnData(0.15));
534
 
535
					fsContact.add(lcCourriel);
276 gduche 536
 
376 gduche 537
					LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout());
538
 
539
					fsContact.add(lcCourrielContainer);
540
					hmIdentite.put("lcCourrielContainer", lcCourrielContainer);
280 gduche 541
 
376 gduche 542
 
543
					LabelField lfUrl = new LabelField();
544
					lfUrl.setText("<b>Sites Web:</b>");
545
 
546
					fsContact.add(lfUrl);
280 gduche 547
 
376 gduche 548
					LayoutContainer lcUrl = new LayoutContainer(new ColumnLayout());
549
					hmIdentite.put("lcUrl", lcUrl);
286 gduche 550
 
386 gduche 551
					HiddenField<String> hfUrl = new HiddenField<String>();
552
					hmIdentite.put("hfUrl", hfUrl);
553
					add(hfUrl);
554
 
376 gduche 555
						TextField tfUrl = new TextField();
556
						tfUrl.setValue("http://");
286 gduche 557
 
376 gduche 558
						lcUrl.add(tfUrl, new ColumnData(0.8));
559
						hmIdentite.put("tfUrl", tfUrl);
286 gduche 560
 
376 gduche 561
						IconButton ibAjouterUrl = new IconButton(ComposantClass.ICONE_AJOUTER);
562
						ibAjouterUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
563
 
564
							public void componentSelected(ComponentEvent ce) {
293 gduche 565
 
376 gduche 566
								TextField<String> tfUrl = (TextField) hmIdentite.get("tfUrl");
567
								String strUrl = tfUrl.getValue();
293 gduche 568
 
376 gduche 569
								if ((strUrl == null)||(strUrl.trim().equals("http://"))||(strUrl.trim().equals("")))	{
570
									MessageBox.alert("Erreur de saisie", "Vous devez saisir un URL", null);
571
								} else if(hmIdentite.get("url-" + strUrl) != null)	{
572
									MessageBox.alert("Erreur de saisie", "L'url est déjà présente dans la liste.", null);
573
								}	else	{
574
									tfUrl.setValue("");
439 gduche 575
										//if (!strUrl.matches("[a-z]{3,}://[a-z0-9-]+.[.a-z0-9-]+(?::[0-9]*)?"))	{
576
										if (!strUrl.startsWith("http://"))	{
376 gduche 577
											MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: http://www.domain.com)", null);
578
										} else if (strUrl.length()>255){
579
											MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
580
										} else {
581
											ajouterUrl(strUrl);
582
										}
583
 
293 gduche 584
								}
585
 
586
							}
376 gduche 587
						});
286 gduche 588
 
376 gduche 589
						lcUrl.add(ibAjouterUrl, new ColumnData(0.15));
590
					fsContact.add(lcUrl);
286 gduche 591
 
376 gduche 592
					LayoutContainer lcUrlContainer = new LayoutContainer(new RowLayout());
593
 
594
					fsContact.add(lcUrlContainer);
595
					hmIdentite.put("lcUrlContainer", lcUrlContainer);
596
 
597
					FieldSet fsAutresInfos = new FieldSet();
598
					fsAutresInfos.setHeading("Autres informations");
286 gduche 599
 
376 gduche 600
					formLayout = new FormLayout();
601
					formLayout.setLabelAlign(LabelAlign.LEFT);
602
					fsAutresInfos.setLayout(formLayout);
286 gduche 603
 
376 gduche 604
 
386 gduche 605
			formLayout = new FormLayout();
606
			formLayout.setLabelAlign(LabelAlign.TOP);
607
			LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout);
608
 
609
			//Civilité
610
			ListStore<Valeur> storeSexe = new ListStore<Valeur>();
611
			ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
612
			cbSexe.setStore(storeSexe);
613
			cbSexe.setFieldLabel("Sexe");
614
			cbSexe.setDisplayField("nom");
615
			cbSexe.setEmptyText("Choisissez le sexe:");
616
 
617
			lcAutreInformations1.add(cbSexe, fd100);
618
			hmIdentite.put("cbSexe", cbSexe);
619
 
620
			mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
356 gduche 621
 
293 gduche 622
			//Description
623
			TextArea taDescription = new TextArea();
624
			taDescription.setEmptyText("Saisissez une description");
625
			taDescription.setFieldLabel("Description");
319 gduche 626
			taDescription.setWidth("100%");
376 gduche 627
			taDescription.setName("description");
293 gduche 628
 
386 gduche 629
			lcAutreInformations1.add(taDescription, fd100);
293 gduche 630
			hmIdentite.put("taDescription", taDescription);
631
 
386 gduche 632
			fsAutresInfos.add(lcAutreInformations1);
376 gduche 633
 
293 gduche 634
			// Logo
386 gduche 635
			LayoutContainer lcAutreInformations2 = new LayoutContainer();
636
			hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
637
 
638
			LabelField lfUrlLogo = new LabelField();
639
			lfUrlLogo.setText("<b>Logo:</b>");
640
			lcAutreInformations2.add(lfUrlLogo);
641
 
642
			LayoutContainer lcUrlLogo = new LayoutContainer(new ColumnLayout());
643
			hmIdentite.put("lcUrlLogo", lcUrlLogo);
644
 
645
				TextField tfUrlLogo = new TextField();
646
				tfUrlLogo.setValue("http://");
647
 
648
				HiddenField<String> hfUrlLogo = new HiddenField<String>();
649
				hmIdentite.put("hfUrlLogo", hfUrlLogo);
650
 
651
				lcUrlLogo.add(tfUrlLogo, new ColumnData(0.8));
652
				hmIdentite.put("tfUrlLogo", tfUrlLogo);
653
 
654
				IconButton ibAjouterUrlLogo = new IconButton(ComposantClass.ICONE_AJOUTER);
655
				ibAjouterUrlLogo.addSelectionListener(new SelectionListener<ComponentEvent>() {
656
 
657
					public void componentSelected(ComponentEvent ce) {
658
 
659
						TextField<String> tfUrlLogo = (TextField) hmIdentite.get("tfUrlLogo");
660
						String strUrl = tfUrlLogo.getValue();
661
 
662
						if ((strUrl == null)||(strUrl.trim().equals("http://"))||(strUrl.trim().equals("")))	{
663
							MessageBox.alert("Erreur de saisie", "Vous devez saisir un URL", null);
664
						} else if(hmIdentite.get("url-" + strUrl) != null)	{
665
							MessageBox.alert("Erreur de saisie", "L'url est déjà présente dans la liste.", null);
666
						}	else	{
667
							tfUrlLogo.setValue("");
439 gduche 668
							//if (!strUrl.matches("[a-z]{3,}://[a-z0-9-]+.[.a-z0-9-]+(?::[0-9]*)?"))	{
669
							if (!strUrl.startsWith("http://"))	{
386 gduche 670
									MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: http://www.domain.com)", null);
671
								} else if (strUrl.length()>255){
672
									MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
673
								} else {
674
									ajouterUrlLogo(strUrl);
675
								}
676
 
677
						}
678
 
679
					}
680
				});
681
 
682
				lcUrlLogo.add(ibAjouterUrlLogo, new ColumnData(0.15));
683
				lcAutreInformations2.add(lcUrlLogo);
684
 
685
			fsAutresInfos.add(lcAutreInformations2);
686
 
293 gduche 687
			TextArea taLogo = new TextArea();
688
			taLogo.setFieldLabel("Logos");
319 gduche 689
			taLogo.setWidth("100%");
293 gduche 690
			taLogo.setEmptyText("Saisissez les adresses des logos séparées par un saut de ligne");
386 gduche 691
			//fsAutresInfos.add(taLogo, fd100);
293 gduche 692
 
693
			hmIdentite.put("taLogo", taLogo);
694
 
376 gduche 695
			right.add(fsAutresInfos);
293 gduche 696
 
276 gduche 697
			// Ajout des évènements saisi
698
			KeyListener klNoms = new KeyListener()	{
699
				public void componentKeyUp(ComponentEvent ev)	{
283 gduche 700
					rafraichir(null);
280 gduche 701
				}
276 gduche 702
			};
703
 
283 gduche 704
			SelectionChangedListener<InterneValeur> selectionChange = new SelectionChangedListener<InterneValeur>() {
705
				public void selectionChanged(SelectionChangedEvent se) {
706
						rafraichir(null);
707
					}
708
			};
709
 
319 gduche 710
			cbPrefixe.addSelectionChangedListener(selectionChange);
711
			cbPrefixe.addKeyListener(klNoms);
276 gduche 712
			tfPrenom.addKeyListener(klNoms);
713
			tfNom.addKeyListener(klNoms);
283 gduche 714
			cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 715
 
716
	}
717
 
293 gduche 718
	public void creerComposantsAdresse()	{
719
 
720
		// Gauche
721
		LayoutContainer left = new LayoutContainer();
722
		left.setLayout(new FormLayout());
723
 
724
		// Droite
725
		LayoutContainer right = new LayoutContainer();
726
		right.setLayout(new FormLayout());
727
 
728
		// Principal
729
		LayoutContainer main = new LayoutContainer();
730
		main.setLayout(new ColumnLayout());
731
 
732
		// Ajout au principal
733
		main.add(left, new ColumnData(.49));
734
		main.add(right, new ColumnData(.49));
735
 
736
		TextField<String> tfAdresse1 = new TextField();
737
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 738
		tfAdresse1.setName("adresse_01");
319 gduche 739
		left.add(tfAdresse1, fd100);
293 gduche 740
		hmAdresse.put("tfAdresse1", tfAdresse1);
741
 
742
		TextField<String> tfAdresse2 = new TextField();
743
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 744
		tfAdresse2.setName("adresse_02");
319 gduche 745
		left.add(tfAdresse2, fd100);
293 gduche 746
		hmAdresse.put("tfAdresse2", tfAdresse2);
747
 
748
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
749
		cbPays.setFieldLabel("Pays");
750
		cbPays.setDisplayField("nom");
751
		cbPays.setEmptyText("Sélectionnez le pays:");
752
 
753
		ListStore<Valeur> storePays = new ListStore<Valeur>();
754
		cbPays.setStore(storePays);
755
 
319 gduche 756
		right.add(cbPays, fd100);
293 gduche 757
		hmAdresse.put("cbPays", cbPays);
758
 
759
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
760
			public void selectionChanged(SelectionChangedEvent se) {
761
					// Rafraichir avec le pays sélectionné
762
					obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
763
 
764
				}
765
		};
766
 
767
		cbPays.addSelectionChangedListener(selectionChange);
768
 
769
 
770
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
771
		cbRegion.setFieldLabel("Region");
772
		cbRegion.setDisplayField("nom");
773
		cbRegion.setEmptyText("Sélectionnez la région:");
774
		cbRegion.setVisible(false);
775
 
776
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
777
		cbRegion.setStore(storeRegion);
778
 
352 gduche 779
 
319 gduche 780
		right.add(cbRegion, fd100);
293 gduche 781
		hmAdresse.put("cbRegion", cbRegion);
782
 
783
		TextField<String> tfBoitePostale = new TextField<String>();
784
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 785
		tfBoitePostale.setName("bp");
786
 
319 gduche 787
		left.add(tfBoitePostale, fd100);
293 gduche 788
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
789
 
790
		TextField<Integer> tfCodePostal = new TextField<Integer>();
791
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 792
		tfCodePostal.setName("code_postal");
793
 
319 gduche 794
		right.add(tfCodePostal, fd100);
293 gduche 795
		hmAdresse.put("tfCodePostal", tfCodePostal);
796
 
797
		TextField tfVille = new TextField();
798
		tfVille.setFieldLabel("Ville");
376 gduche 799
		tfVille.setName("ville");
293 gduche 800
 
319 gduche 801
		right.add(tfVille, fd100);
293 gduche 802
		hmAdresse.put("tfVille", tfVille);
803
 
804
		// MAJ ComboBox
805
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
806
 
304 gduche 807
		FieldSet fsAdresse = new FieldSet();
808
		fsAdresse.setHeading("Adresse personnelle");
809
		fsAdresse.add(main);
293 gduche 810
 
304 gduche 811
		tiAdresses.add(fsAdresse);
812
 
352 gduche 813
		((ComboBox) hmIdentite.get("cbPrefixe")).setRawValue("ljkhlkj");
814
 
815
 
293 gduche 816
	}
338 gduche 817
 
276 gduche 818
	/**
819
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
820
	 *
821
	 * @param barreOutils la barre d'outils à modifier
822
	 * */
376 gduche 823
	public void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
276 gduche 824
 
825
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
352 gduche 826
		TextToolItem reinitialiser = new TextToolItem("Réinitialiser le formulaire");
276 gduche 827
		reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
828
		reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
829
			public void componentSelected(ComponentEvent ce) {
376 gduche 830
				//((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
831
				reinitialiser();
832
				//System.out.println(personneSelectionnee);
276 gduche 833
			}
834
		});
835
		barreOutils.add(reinitialiser);
836
	}
837
 
838
	/**
338 gduche 839
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
840
	 *
841
	 * @param barreOutils la barre d'outils à modifier
842
	 * */
456 gduche 843
	private void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils)	{
338 gduche 844
 
845
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
356 gduche 846
		Button enregistrer = new Button("Enregistrer et revenir à la liste");
338 gduche 847
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
848
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
849
			public void componentSelected(ComponentEvent ce) {
850
				// TODO : Enregistrer le formulaire
851
			}
852
		});
456 gduche 853
		enregistrer.setEnabled(false);
854
 
855
		hmIdentite.put("btnEnregistrerRevenir", enregistrer);
338 gduche 856
		barreOutils.add(enregistrer);
456 gduche 857
 
338 gduche 858
	}
859
 
860
	/**
276 gduche 861
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
862
	 *
863
	 * @param barreOutils la barre d'outils à modifier
864
	 * */
456 gduche 865
	private void ajouterBoutonEnregistrer(ButtonBar barreOutils)	{
276 gduche 866
 
867
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
356 gduche 868
		Button enregistrer = new Button("Enregistrer");
286 gduche 869
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
352 gduche 870
		enregistrer.setId("main-button");
286 gduche 871
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
276 gduche 872
			public void componentSelected(ComponentEvent ce) {
376 gduche 873
				enregistrer();
276 gduche 874
			}
875
		});
456 gduche 876
		enregistrer.setEnabled(false);
877
 
878
		hmIdentite.put("btnEnregistrer", enregistrer);
286 gduche 879
		barreOutils.add(enregistrer);
276 gduche 880
	}
881
 
882
	/**
883
	 * Ajouter le bouton annuler à la barre d'outils donnée
884
	 *
885
	 * @param barreOutils la barre d'outils à modifier
886
	 * */
356 gduche 887
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 888
 
889
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 890
		Button annuler = new Button("Revenir à la liste");
276 gduche 891
		annuler.addSelectionListener(new SelectionListener<ComponentEvent>() {
892
			public void componentSelected(ComponentEvent ce) {
893
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
894
			}
895
		});
896
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
897
		barreOutils.add(annuler);
898
	}
899
 
293 gduche 900
	public void obtenirListeRegionParPays(String strPays)	{
901
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
902
	}
276 gduche 903
 
904
 
293 gduche 905
 
276 gduche 906
	/*---------------------------------------------------------------------------------------
907
	 * 		RAFRAICHISSEMENT DU PANNEAU
908
	 * --------------------------------------------------------------------------------------
909
	 */
283 gduche 910
	public void rafraichir(Object nouvellesDonnees) {
386 gduche 911
 
912
 
913
 
456 gduche 914
		if (nouvellesDonnees instanceof ValeurListe) {
283 gduche 915
 
916
 
917
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
918
 
919
			// Créer une liste de valeurs
920
			List<Valeur> liste = new ArrayList<Valeur>();
921
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
922
				liste.add(listeValeurs.get(it.next()));
923
			}
924
 
925
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
926
 
319 gduche 927
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 928
 
929
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
930
 
931
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
932
 
933
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
934
 
935
				remplirCombobox("cbSexe", liste, "hmIdentite");
283 gduche 936
 
293 gduche 937
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
938
 
939
				remplirCombobox("cbTelephone", liste, "hmIdentite");
319 gduche 940
 
941
				//Préselection du tél
942
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
943
				cbTelephone.setValue(liste.get(1));
293 gduche 944
 
945
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
283 gduche 946
 
293 gduche 947
				remplirCombobox("cbPays", liste, "hmAdresse");
283 gduche 948
 
293 gduche 949
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
283 gduche 950
 
293 gduche 951
				remplirCombobox("cbRegion", liste, "hmAdresse");
283 gduche 952
 
293 gduche 953
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 954
			}
293 gduche 955
 
956
 
456 gduche 957
		} else if (nouvellesDonnees instanceof ProjetListe) {
958
 
959
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
960
 
961
			List<Projet> liste = new ArrayList<Projet>();
962
			for (Iterator<String> it = projets.keySet().iterator(); it.hasNext();) {
963
				liste.add(projets.get(it.next()));
964
			}
965
			ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
966
			ListStore<Projet> storeProjets= cbProjets.getStore();
967
			storeProjets.removeAll();
968
			storeProjets.add(liste);
969
			cbProjets.setStore(storeProjets);
970
 
352 gduche 971
		} else if (nouvellesDonnees instanceof Information)	{
286 gduche 972
 
352 gduche 973
			Information info = (Information) nouvellesDonnees;
386 gduche 974
			if (info.getType().equals("ajout_personne"))	{
352 gduche 975
 
386 gduche 976
				personneSelectionnee.set("id_personne", info.toString());
977
				GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
376 gduche 978
 
433 gduche 979
				Info.display("Enregistrement", "La personne a été ajoutée (PID:" + personneSelectionnee.getId() + ")");
386 gduche 980
				//Passer en mode modifier
376 gduche 981
 
433 gduche 982
			} else if (info.getType().equals("modification_personne"))	{
983
 
984
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
985
 
386 gduche 986
			} else if (info.getType().equals("suppression_personne"))	{
433 gduche 987
 
386 gduche 988
				GWT.log(info.toString(), null);
989
				Info.display("lk", info.getMessages().toString());
990
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
991
 
992
 
993
					Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
994
					Iterator itPersonneListe = colPersonneListe.iterator();
995
					Personne personne = (Personne) itPersonneListe.next();
376 gduche 996
 
386 gduche 997
					personneSauvegarde = new Personne();
998
					personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
376 gduche 999
 
386 gduche 1000
					binderPersonne(personne);
1001
					//Mise à jour de la personne
1002
					//Personne personne = (Personne) nouvellesDonnees;
1003
 
456 gduche 1004
					ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
1005
					cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
386 gduche 1006
 
1007
					//Prefixe
1008
					String prefixe = personne.get("ce_truk_prefix");
1009
					ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
1010
 
1011
 
1012
					String prefixeCourant = personne.get("ce_truk_prefix");
1013
					if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
1014
						cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
1015
					}	else	{
1016
						cbPrefixe.setRawValue(prefixeCourant);
376 gduche 1017
					}
1018
 
1019
 
386 gduche 1020
					((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
1021
					((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
1022
 
1023
					//Suffixe
1024
					String suffixe = personne.get("ce_truk_suffixe");
1025
					ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
1026
 
1027
					String suffixeCourant = personne.get("ce_truk_suffix");
1028
					if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
1029
						cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
1030
					}	else	{
1031
						cbSuffixe.setRawValue(suffixeCourant);
1032
					}
1033
 
1034
					((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
1035
					((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
1036
					((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
1037
 
1038
 
1039
					(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
1040
					((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
1041
 
1042
					(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
1043
					((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
1044
 
1045
					// Telephone
1046
					HashMap<String, String> hmTelephone = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
1047
					if (hmTelephone!=null)	{
1048
 
1049
 
1050
						ListStore storeTelephone = ((ComboBox) hmIdentite.get("cbTelephone")).getStore();
1051
						List lstModelsTelephone = storeTelephone.getModels();
1052
						Iterator<Valeur> itStore = lstModelsTelephone.iterator();
1053
						HashMap<String, String> hmTel = new HashMap();
1054
						while (itStore.hasNext())	{
1055
							Valeur v = itStore.next();
1056
							hmTel.put(v.getAbreviation(), v.getNom());
376 gduche 1057
						}
1058
 
386 gduche 1059
 
1060
						Collection<String> colTelephone = hmTelephone.keySet();
1061
						Iterator<String> itTelephone = colTelephone.iterator();
1062
 
1063
						while (itTelephone.hasNext())	{
1064
							String strTypeTelephone = itTelephone.next();
1065
							String strTelephone = hmTelephone.get(strTypeTelephone);
1066
							String idTel = hmTel.get(strTypeTelephone);
1067
							if (idTel == null)	{
1068
								idTel = strTypeTelephone;
1069
							}
1070
 
1071
							ajouterTelephone(strTelephone, idTel, strTypeTelephone);
1072
						}
376 gduche 1073
					}
352 gduche 1074
 
386 gduche 1075
					//Courriel
1076
					LinkedList<String> lCourriels = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
440 gduche 1077
					if (lCourriels != null) {
1078
						Iterator<String> itCourriels = lCourriels.iterator();
386 gduche 1079
 
440 gduche 1080
						while (itCourriels.hasNext())	{
1081
							String strEmail = itCourriels.next();
1082
							ajouterCourriel(strEmail);
1083
						}
386 gduche 1084
					}
1085
 
1086
					// Sites
1087
					LinkedList<String> lUrl = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_url");
433 gduche 1088
					if (lUrl!=null) {
1089
						Iterator<String> itUrl = lUrl.iterator();
1090
						while (itUrl.hasNext())	{
1091
							String strUrl = itUrl.next();
1092
							ajouterUrl(strUrl);
1093
						}
386 gduche 1094
					}
1095
 
1096
					// Sexe
1097
					String strSexe = personne.get("ce_sexe");
1098
					ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
1099
 
1100
 
1101
					//FIXME : le lien avec la bdd ne peut pas se faire
1102
					if (cbSexe.getStore().findModel("abreviation", strSexe) != null)	{
1103
						cbSexe.setValue(cbSexe.getStore().findModel("abreviation", strSexe));
352 gduche 1104
					}	else	{
386 gduche 1105
						cbSexe.setRawValue(strSexe);
352 gduche 1106
					}
386 gduche 1107
 
1108
					((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
1109
 
1110
					// Logos
1111
					TextArea taLogo = (TextArea) hmIdentite.get("taLogo");
1112
					LinkedList<String> lLogo = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
433 gduche 1113
					if (lLogo!=null)	{
1114
						Iterator<String> itLogo = lLogo.iterator();
1115
						String strValeurLogo = "";
1116
						while (itLogo.hasNext())	{
1117
							strValeurLogo += itLogo.next() + "\n";
1118
						}
386 gduche 1119
 
433 gduche 1120
						if (!strValeurLogo.trim().equals(""))	{
439 gduche 1121
							ajouterUrlLogo(strValeurLogo);
433 gduche 1122
						}
386 gduche 1123
					}
1124
 
1125
					/*--------------------------------------------------
1126
					                      Adresse
1127
					 ---------------------------------------------------*/
1128
 
1129
					// Adresse
1130
					((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
1131
 
1132
					// Complément
1133
					((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
1134
 
1135
					//Boite postale
1136
					((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
1137
 
1138
					//Pays
1139
					String strPays = personne.get("pays");
1140
					ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
1141
 
1142
 
1143
					if (cbPays.getStore().findModel("nom", strPays) != null)	{
1144
						cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
1145
					}	else	{
1146
						cbPays.setRawValue(strPays);
1147
					}
1148
 
1149
 
1150
					//Région
1151
					String strRegion = personne.get("region");
1152
					if ((strRegion!=null)&&(!strRegion.equals("")))	{
1153
						ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
1154
						cbRegion.setVisible(true);
1155
 
1156
						if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
1157
							cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
1158
						}	else	{
1159
							cbRegion.setRawValue(strRegion);
1160
						}
1161
					}
1162
 
1163
					//Cp
1164
					((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
1165
 
1166
					//Ville
1167
					((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
1168
 
1169
 
456 gduche 1170
					((Button) hmIdentite.get("btnEnregistrerRevenir")).setEnabled(true);
1171
					((Button) hmIdentite.get("btnEnregistrer")).setEnabled(true);
1172
 
386 gduche 1173
				} else {
1174
					Info.display("messages", info.getMessages().toString());
352 gduche 1175
				}
293 gduche 1176
		}
283 gduche 1177
 
1178
		if (nouvellesDonnees == null)
1179
		{
319 gduche 1180
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 1181
 
1182
			//Met à jour le nom Complet du formulaire
283 gduche 1183
			String valeurRetour = "";
1184
 
1185
			// Prefixe
1186
			String prefixe = "";
319 gduche 1187
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 1188
 
1189
			if (valPrefixe != null)	{
1190
				prefixe = valPrefixe.getNom();
293 gduche 1191
			} else 	{
319 gduche 1192
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 1193
			}
283 gduche 1194
 
293 gduche 1195
 
283 gduche 1196
			// Prénom
1197
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
1198
 
1199
			// Nom
1200
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
1201
 
1202
			// Suffixe
1203
			String suffixe = "";
1204
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
1205
 
1206
			if (valSuffixe != null)	{
1207
				suffixe = valSuffixe.getNom();
293 gduche 1208
			} else 	{
1209
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 1210
			}
1211
 
1212
			// Mettre à jour la valeur
1213
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
1214
			valeurRetour = valeurRetour.replaceAll("null", "");
1215
 
1216
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
1217
 
1218
			if (!valeurRetour.trim().equals(""))	{
1219
				((LabelField) hmIdentite.get("nomComplet")).show();
1220
			} else {
1221
				((LabelField) hmIdentite.get("nomComplet")).hide();
1222
			}
1223
		}
338 gduche 1224
 
1225
		mediateur.masquerPopinChargement();
456 gduche 1226
 
1227
		if (mode.equals("AJOUT"))	{
1228
			((Button) hmIdentite.get("btnEnregistrerRevenir")).setEnabled(true);
1229
			((Button) hmIdentite.get("btnEnregistrer")).setEnabled(true);
1230
		}
127 gduche 1231
	}
1232
 
352 gduche 1233
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
293 gduche 1234
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
352 gduche 1235
 
293 gduche 1236
		HashMap hm = null;
1237
		if (hashMapId.equals("hmIdentite"))	{
1238
			hm = hmIdentite;
1239
		} else if (hashMapId.equals("hmAdresse")){
1240
			hm = hmAdresse;
1241
		} else {
1242
			hm = hmInfosNat;
1243
		}
1244
 
1245
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1246
 
293 gduche 1247
		store.removeAll();
1248
		store.add(liste);
1249
		((ComboBox) hm.get(idComboBox)).setStore(store);
376 gduche 1250
 
293 gduche 1251
	}
130 gduche 1252
 
352 gduche 1253
 
376 gduche 1254
	public void ajouterTelephone(String strTelephone, String strValeurTypeTel, String idTel) 	{
352 gduche 1255
 
1256
 
1257
				//Ajout d'un champ à la liste
376 gduche 1258
				String strIdTelephone =  idTel + "##" + strTelephone + ";;";
352 gduche 1259
 
1260
				FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1261
 
356 gduche 1262
				LayoutContainer lcTelephone = new LayoutContainer();
1263
				lcTelephone.setLayout(new ColumnLayout());
1264
 
352 gduche 1265
				Text tTypeTelephone = new Text();
1266
				tTypeTelephone.setText(strValeurTypeTel+":");
1267
 
376 gduche 1268
				hmIdentite.put("type-" + strIdTelephone, tTypeTelephone);
356 gduche 1269
				lcTelephone.add(tTypeTelephone, new ColumnData(0.40));
352 gduche 1270
 
1271
				Text tTelephone = new Text();
1272
				tTelephone.setText(strTelephone);
376 gduche 1273
				hmIdentite.put("tel-" + strIdTelephone, tTelephone);
356 gduche 1274
				lcTelephone.add(tTelephone, new ColumnData(0.40));
352 gduche 1275
 
1276
				IconButton bSupprimer = new IconButton(ComposantClass.ICONE_SUPPRIMER);
376 gduche 1277
				bSupprimer.setId(strIdTelephone);
352 gduche 1278
 
1279
				bSupprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
1280
						public void componentSelected(ComponentEvent ce) {
1281
 
376 gduche 1282
							String strIdTelephone = ce.component.getId();
1283
							LayoutContainer lcContactTel = (LayoutContainer) hmIdentite.get("lc-"+strIdTelephone);
352 gduche 1284
 
376 gduche 1285
							lcContactTel.remove(hmIdentite.get("type-" + strIdTelephone));
1286
							hmIdentite.remove("type-" + strIdTelephone);
352 gduche 1287
 
376 gduche 1288
							lcContactTel.remove(hmIdentite.get("tel-" + strIdTelephone));
1289
							hmIdentite.remove("tel-" + strIdTelephone);
352 gduche 1290
 
356 gduche 1291
							lcContactTel.remove(ce.component);
352 gduche 1292
 
356 gduche 1293
							FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1294
							fsContactTel.remove(lcContactTel);
1295
 
376 gduche 1296
							HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1297
							String strValeurTelephone = hfTelephone.getValue();
1298
							strValeurTelephone = strValeurTelephone.replace(strIdTelephone, "");
1299
							hfTelephone.setValue(strValeurTelephone);
1300
 
352 gduche 1301
							layout();
1302
 
1303
						}
1304
				});
1305
 
356 gduche 1306
				lcTelephone.add(bSupprimer, new ColumnData(0.15));
352 gduche 1307
 
376 gduche 1308
				hmIdentite.put("lc-"+strIdTelephone, lcTelephone);
356 gduche 1309
				fsContactTel.add(lcTelephone);
1310
 
376 gduche 1311
				HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1312
				String strValeurTelephone = hfTelephone.getValue();
1313
				if (strValeurTelephone==null)	{
1314
					strValeurTelephone = "";
1315
				}
1316
				strValeurTelephone += strIdTelephone;
1317
				hfTelephone.setValue(strValeurTelephone);
352 gduche 1318
 
1319
				layout();
1320
 
1321
 
1322
 
1323
 
1324
	}
1325
 
376 gduche 1326
	public void ajouterCourriel(String strEmail)	{
1327
 
1328
			TextField<String> tfCourriel = (TextField<String>) hmIdentite.get("tfCourriel");
1329
			tfCourriel.setValue("");
1330
 
1331
			//Ajouter adresse email
1332
			LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1333
 
1334
			LayoutContainer lcCourriel = new LayoutContainer();
1335
			lcCourriel.setLayout(new ColumnLayout());
1336
 
1337
			LabelField lfCourriel = new LabelField();
1338
			lfCourriel.setText(strEmail);
1339
 
1340
			lcCourriel.add(lfCourriel, new ColumnData(0.8));
1341
			hmIdentite.put("lc-" + strEmail, lcCourriel);
1342
 
1343
			//Bouton supprimer
1344
			IconButton btnSupprimerCourriel = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1345
			btnSupprimerCourriel.setId(strEmail);
1346
			btnSupprimerCourriel.addSelectionListener(new SelectionListener<ComponentEvent>() {
1347
 
1348
				public void componentSelected(ComponentEvent ce) {
1349
					//Suppression de l'adresse email
1350
					String strEmail = ce.component.getId();
1351
					LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1352
					LayoutContainer lcCourriel = (LayoutContainer) hmIdentite.get("lc-" + strEmail);
1353
					lcCourrielContainer.remove(lcCourriel);
1354
 
1355
					hmIdentite.remove("lc-" + strEmail);
1356
					hmIdentite.remove("email-" + strEmail);
1357
 
1358
						HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1359
					String strValeurCourriel = hfHiddenCourriel.getValue();
1360
					strValeurCourriel = strValeurCourriel.replace(strEmail + ";;", "");
1361
					hfHiddenCourriel.setValue(strValeurCourriel);
1362
 
1363
				}
1364
 
1365
			});
1366
 
1367
			lcCourriel.add(btnSupprimerCourriel);
1368
 
1369
 
1370
 
1371
			lcCourrielContainer.add(lcCourriel);
1372
			hmIdentite.put("email-" + strEmail, lfCourriel);
1373
 
1374
			HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1375
			String strHiddenCourrielValue = hfHiddenCourriel.getValue();
1376
			if (strHiddenCourrielValue == null) {
1377
				strHiddenCourrielValue = "";
1378
			}
1379
			hfHiddenCourriel.setRawValue(strHiddenCourrielValue + strEmail + ";;");
1380
 
1381
 
1382
			layout();
1383
 
1384
	}
1385
 
1386
	public void ajouterUrl(String strUrl)	{
1387
 
1388
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1389
 
1390
		LayoutContainer lcUrl = new LayoutContainer();
1391
		lcUrl.setLayout(new ColumnLayout());
1392
		hmIdentite.put("lc-" + strUrl, lcUrl);
1393
 
1394
 
1395
		Text tUrl = new Text(strUrl);
1396
		hmIdentite.put("url-"+strUrl, tUrl);
1397
 
1398
		lcUrl.add(tUrl, new ColumnData(0.8));
1399
 
1400
		IconButton ibSupprimerUrl = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1401
		ibSupprimerUrl.setId(strUrl);
1402
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
130 gduche 1403
 
376 gduche 1404
			public void componentSelected(ComponentEvent ce) {
1405
 
1406
				//Suppression url
1407
				String strUrl = ce.component.getId();
1408
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1409
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1410
 
1411
				lcUrlContainer.remove(lcUrl);
1412
 
386 gduche 1413
 
1414
				HiddenField<String> hfUrl = (HiddenField<String>) hmIdentite.get("hfUrl");
1415
				String strValeurUrl = hfUrl.getValue();
1416
				strValeurUrl = strValeurUrl.replace(strUrl, "");
1417
				hfUrl.setValue(strValeurUrl);
1418
 
376 gduche 1419
			}
1420
		});
1421
 
1422
		lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
1423
		lcUrlContainer.add(lcUrl);
1424
 
386 gduche 1425
		HiddenField<String> hfUrl = (HiddenField<String>) hmIdentite.get("hfUrl");
1426
		String strValeurUrl = hfUrl.getValue();
1427
		if (strValeurUrl == null)	{
1428
			strValeurUrl = "";
1429
		}
1430
 
1431
		strValeurUrl += strUrl + ";;";
1432
		hfUrl.setValue(strValeurUrl);
1433
 
376 gduche 1434
		layout();
1435
 
1436
 
1437
 
1438
	}
1439
 
386 gduche 1440
	public void ajouterUrlLogo(String strUrl)	{
1441
 
1442
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1443
 
1444
		LayoutContainer lcUrl = new LayoutContainer();
1445
		lcUrl.setLayout(new ColumnLayout());
1446
		hmIdentite.put("lc-" + strUrl, lcUrl);
1447
 
1448
 
1449
		Text tUrl = new Text(strUrl);
1450
		hmIdentite.put("url-"+strUrl, tUrl);
1451
 
1452
		lcUrl.add(tUrl, new ColumnData(0.8));
1453
 
1454
		IconButton ibSupprimerUrl = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1455
		ibSupprimerUrl.setId(strUrl);
1456
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
1457
 
1458
			public void componentSelected(ComponentEvent ce) {
1459
 
1460
				//Suppression url
1461
				String strUrl = ce.component.getId();
1462
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1463
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1464
 
1465
				lcUrlContainer.remove(lcUrl);
1466
 
1467
 
1468
				HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1469
				String strValeurUrl = hfUrlLogo.getValue();
1470
				strValeurUrl = strUrl.replace(strUrl, "");
1471
 
1472
				hfUrlLogo.setValue(strValeurUrl);
1473
 
1474
			}
1475
		});
1476
 
1477
		lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
1478
		lcUrlContainer.add(lcUrl);
1479
 
1480
		HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1481
		String strValeurUrl = hfUrlLogo.getValue();
1482
		if (strValeurUrl == null)	{
1483
			strValeurUrl = "";
1484
		}
1485
 
1486
		strValeurUrl += strUrl + ";;";
1487
 
1488
		hfUrlLogo.setValue(strValeurUrl);
1489
 
1490
 
1491
 
1492
		layout();
1493
 
1494
 
1495
 
1496
	}
1497
 
376 gduche 1498
	public void reinitialiser()	{
1499
 
1500
		mediateur.afficherPopinChargement();
1501
 
1502
 
1503
		binderPersonne(personneSauvegarde);
1504
 
1505
 
1506
		layout();
1507
 
1508
		mediateur.masquerPopinChargement();
1509
	}
1510
 
1511
 
1512
 
1513
	public void binderPersonne(Personne personne)	{
1514
 
1515
		binding = new FormBinding(this);
1516
 
1517
		personneSelectionnee = personne;
1518
		binding.autoBind();
1519
		binding.bind(personneSelectionnee);
1520
 
1521
		layout();
1522
	}
130 gduche 1523
 
376 gduche 1524
	/**
1525
	 * Enregistre les information de la personne en cours
1526
	 *
1527
	 */
1528
	public void enregistrer()	{
1529
 
1530
		LinkedList lstMessageErreur = new LinkedList<String>();
1531
 
456 gduche 1532
		ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");
1533
		Projet projet = cbProjets.getValue();
1534
		if (projet == null)	{
1535
			lstMessageErreur.add("Le projet n'a pas été renseigné");
1536
		}
1537
 
1538
 
376 gduche 1539
		//Préparer les données
1540
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1541
		Valeur valeur;
1542
		String strValeur = "";
1543
 
1544
		if (combo.getValue()!=null)	{
1545
			valeur = (Valeur) combo.getValue();
1546
			strValeur = valeur.getId();
1547
		}
1548
 
1549
		if (!strValeur.trim().equals(""))	{
1550
			personneSelectionnee.set("sexe", strValeur);
1551
		} else {
1552
			lstMessageErreur.add("Le champ Sexe n'a pas été renseigné");
1553
		}
1554
 
1555
		strValeur = obtenirValeurCombo("cbPrefixe");
1556
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1557
 
1558
		strValeur = obtenirValeurCombo("cbSuffixe");
1559
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1560
 
1561
		personneSelectionnee.set("truk_courriel", ((HiddenField<String>) hmIdentite.get("hfHiddenCourriel")).getValue());
1562
 
386 gduche 1563
 
1564
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1565
		String strPrefixe = "";
1566
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1567
		valeur = (Valeur) combo.getValue();
1568
		if (valeur != null)	{
1569
			strPrefixe = valeur.getNom();
1570
		} else {
1571
			strPrefixe = combo.getRawValue();
1572
		}
1573
 
1574
		String strSuffixe = "";
1575
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1576
		valeur = (Valeur) combo.getValue();
1577
		if (valeur != null)	{
456 gduche 1578
			strSuffixe = valeur.getNom() + " ";
386 gduche 1579
		} else {
456 gduche 1580
			strSuffixe = combo.getRawValue() +" ";
386 gduche 1581
		}
376 gduche 1582
 
456 gduche 1583
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
376 gduche 1584
 
1585
 
456 gduche 1586
		DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");
1587
		Date naissanceDate = dfDateNaissance.getValue();
1588
		personneSelectionnee.setNaissanceDate(naissanceDate);
376 gduche 1589
 
456 gduche 1590
		Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");
1591
		if (rbEstDecedee.getValue().equals(true))	{
1592
 
1593
			DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");
1594
			Date decesDate = dfDecesDate.getValue();
1595
			if (decesDate == null)	{
1596
				decesDate = new Date();
1597
			}
1598
			personneSelectionnee.setDecesDate(decesDate);
1599
			personneSelectionnee.set("deces_lieu", ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue());
1600
		}
1601
 
1602
		personneSelectionnee.setDecesDate(new Date());
1603
 
376 gduche 1604
		strValeur = obtenirValeurCombo("cbPays");
1605
		personneSelectionnee.set("pays", strValeur);
1606
 
1607
		strValeur = obtenirValeurCombo("cbRegion");
1608
		personneSelectionnee.set("region", strValeur);
1609
 
1610
		personneSelectionnee.set("truk_telephone", ((HiddenField<String>) hmIdentite.get("hfTelephone")).getValue());
1611
 
386 gduche 1612
		String logoUrls = ((HiddenField<String>) hmIdentite.get("hfUrlLogo")).getValue();
1613
		if (logoUrls == null)	{
1614
			logoUrls = "";
1615
		}
1616
		personneSelectionnee.set("truk_logo", logoUrls);
376 gduche 1617
 
386 gduche 1618
		personneSelectionnee.set("truk_url", ((HiddenField) hmIdentite.get("hfUrl")).getValue());
376 gduche 1619
 
456 gduche 1620
		if (lstMessageErreur.size() < 0)	{
386 gduche 1621
			mediateur.enregistrerPersonne(this, personneSelectionnee);
456 gduche 1622
		} else {
1623
			String strMessagesErreur = "<span><br />";
386 gduche 1624
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1625
			while (itMessagesErreur.hasNext())	{
456 gduche 1626
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
386 gduche 1627
			}
456 gduche 1628
			strMessagesErreur += "</span>";
386 gduche 1629
 
1630
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
456 gduche 1631
		}
376 gduche 1632
	}
1633
 
1634
	private String obtenirValeurCombo(String strComboName)	{
1635
 
1636
		String strValeur = "";
1637
		Valeur valeur;
1638
 
1639
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1640
		if (combo == null)	{
1641
			combo = (ComboBox) hmAdresse.get(strComboName);
1642
		}
1643
		if (combo.getValue()!=null)	{
1644
			valeur = (Valeur) combo.getValue();
1645
			strValeur = valeur.getId();
1646
		} else {
1647
			strValeur = combo.getRawValue();
1648
		}
1649
 
1650
		return strValeur;
1651
	}
127 gduche 1652
}