Subversion Repositories eFlore/Applications.coel

Rev

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