Subversion Repositories eFlore/Applications.coel

Rev

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