Subversion Repositories eFlore/Applications.coel

Rev

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