Subversion Repositories eFlore/Applications.coel

Rev

Rev 681 | Rev 692 | 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;
280 gduche 55
import com.extjs.gxt.ui.client.widget.form.ComboBox;
56
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 57
import com.extjs.gxt.ui.client.widget.form.FieldSet;
352 gduche 58
import com.extjs.gxt.ui.client.widget.form.FormPanel;
293 gduche 59
import com.extjs.gxt.ui.client.widget.form.HiddenField;
276 gduche 60
import com.extjs.gxt.ui.client.widget.form.LabelField;
446 gduche 61
import com.extjs.gxt.ui.client.widget.form.Radio;
62
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
286 gduche 63
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 64
import com.extjs.gxt.ui.client.widget.form.TextField;
456 gduche 65
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
276 gduche 66
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
67
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
68
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
319 gduche 69
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 70
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
356 gduche 71
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
276 gduche 72
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
386 gduche 73
import com.google.gwt.core.client.GWT;
339 gduche 74
import com.google.gwt.i18n.client.DateTimeFormat;
689 gduche 75
import com.google.gwt.user.client.ui.Image;
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
689 gduche 653
		LayoutContainer lcLogoUrl = new LayoutContainer();
654
		hmIdentite.put("lcLogoUrl", lcLogoUrl);
676 gduche 655
 
656
		LabelField lfUrlLogo = new LabelField();
657
		lfUrlLogo.setText("<b>Logo:</b>");
689 gduche 658
		lcLogoUrl.add(lfUrlLogo);
676 gduche 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);
689 gduche 683
				} else if(hmIdentite.get("lc-" + strUrl) != null)	{
676 gduche 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));
689 gduche 702
		lcLogoUrl.add(lcUrlLogo);
386 gduche 703
 
689 gduche 704
		fsAutresInfos.add(lcLogoUrl);
705
 
706
		LayoutContainer lcAutreInformations2 = new LayoutContainer(new ColumnLayout());
707
		hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
676 gduche 708
		fsAutresInfos.add(lcAutreInformations2);
386 gduche 709
 
676 gduche 710
		TextArea taLogo = new TextArea();
711
		taLogo.setFieldLabel("Logos");
712
		taLogo.setWidth("100%");
713
		taLogo.setEmptyText("Saisissez les adresses des logos séparées par un saut de ligne");
714
		//fsAutresInfos.add(taLogo, fd100);
293 gduche 715
 
676 gduche 716
		hmIdentite.put("taLogo", taLogo);
293 gduche 717
 
676 gduche 718
		right.add(fsAutresInfos);
293 gduche 719
 
676 gduche 720
		// Ajout des évènements saisi
721
		KeyListener klNoms = new KeyListener()	{
722
			public void componentKeyUp(ComponentEvent ev)	{
723
				rafraichir(null);
724
			}
725
		};
726
 
727
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
728
			public void selectionChanged(SelectionChangedEvent se) {
729
					rafraichir(null);
730
				}
731
		};
283 gduche 732
 
676 gduche 733
		cbPrefixe.addSelectionChangedListener(selectionChange);
734
		cbPrefixe.addKeyListener(klNoms);
735
		tfPrenom.addKeyListener(klNoms);
736
		tfNom.addKeyListener(klNoms);
737
		cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 738
 
739
	}
740
 
293 gduche 741
	public void creerComposantsAdresse()	{
742
 
743
		// Gauche
744
		LayoutContainer left = new LayoutContainer();
745
		left.setLayout(new FormLayout());
746
 
747
		// Droite
748
		LayoutContainer right = new LayoutContainer();
749
		right.setLayout(new FormLayout());
750
 
751
		// Principal
752
		LayoutContainer main = new LayoutContainer();
753
		main.setLayout(new ColumnLayout());
754
 
755
		// Ajout au principal
756
		main.add(left, new ColumnData(.49));
757
		main.add(right, new ColumnData(.49));
758
 
759
		TextField<String> tfAdresse1 = new TextField();
760
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 761
		tfAdresse1.setName("adresse_01");
319 gduche 762
		left.add(tfAdresse1, fd100);
293 gduche 763
		hmAdresse.put("tfAdresse1", tfAdresse1);
764
 
765
		TextField<String> tfAdresse2 = new TextField();
766
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 767
		tfAdresse2.setName("adresse_02");
319 gduche 768
		left.add(tfAdresse2, fd100);
293 gduche 769
		hmAdresse.put("tfAdresse2", tfAdresse2);
770
 
771
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
772
		cbPays.setFieldLabel("Pays");
773
		cbPays.setDisplayField("nom");
774
		cbPays.setEmptyText("Sélectionnez le pays:");
775
 
776
		ListStore<Valeur> storePays = new ListStore<Valeur>();
777
		cbPays.setStore(storePays);
778
 
319 gduche 779
		right.add(cbPays, fd100);
293 gduche 780
		hmAdresse.put("cbPays", cbPays);
781
 
782
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
783
			public void selectionChanged(SelectionChangedEvent se) {
784
					// Rafraichir avec le pays sélectionné
785
					obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
786
 
787
				}
788
		};
789
 
790
		cbPays.addSelectionChangedListener(selectionChange);
791
 
792
 
793
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
794
		cbRegion.setFieldLabel("Region");
795
		cbRegion.setDisplayField("nom");
796
		cbRegion.setEmptyText("Sélectionnez la région:");
797
		cbRegion.setVisible(false);
798
 
799
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
800
		cbRegion.setStore(storeRegion);
801
 
352 gduche 802
 
319 gduche 803
		right.add(cbRegion, fd100);
293 gduche 804
		hmAdresse.put("cbRegion", cbRegion);
805
 
806
		TextField<String> tfBoitePostale = new TextField<String>();
807
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 808
		tfBoitePostale.setName("bp");
809
 
319 gduche 810
		left.add(tfBoitePostale, fd100);
293 gduche 811
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
812
 
813
		TextField<Integer> tfCodePostal = new TextField<Integer>();
814
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 815
		tfCodePostal.setName("code_postal");
816
 
319 gduche 817
		right.add(tfCodePostal, fd100);
293 gduche 818
		hmAdresse.put("tfCodePostal", tfCodePostal);
819
 
820
		TextField tfVille = new TextField();
821
		tfVille.setFieldLabel("Ville");
376 gduche 822
		tfVille.setName("ville");
293 gduche 823
 
319 gduche 824
		right.add(tfVille, fd100);
293 gduche 825
		hmAdresse.put("tfVille", tfVille);
826
 
827
		// MAJ ComboBox
828
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
829
 
304 gduche 830
		FieldSet fsAdresse = new FieldSet();
831
		fsAdresse.setHeading("Adresse personnelle");
832
		fsAdresse.add(main);
293 gduche 833
 
304 gduche 834
		tiAdresses.add(fsAdresse);
352 gduche 835
		((ComboBox) hmIdentite.get("cbPrefixe")).setRawValue("ljkhlkj");
293 gduche 836
	}
338 gduche 837
 
276 gduche 838
	/**
839
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
840
	 *
841
	 * @param barreOutils la barre d'outils à modifier
842
	 * */
376 gduche 843
	public void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
276 gduche 844
 
845
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
488 gduche 846
		Button reinitialiser = new Button("Réinitialiser le formulaire");
519 gduche 847
		reinitialiser.setIcon(Images.ICONES.rafraichir());
488 gduche 848
		reinitialiser.addSelectionListener(new SelectionListener<ButtonEvent>() {
849
			public void componentSelected(ButtonEvent ce) {
376 gduche 850
				//((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
851
				reinitialiser();
276 gduche 852
			}
853
		});
854
		barreOutils.add(reinitialiser);
855
	}
856
 
857
	/**
338 gduche 858
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
859
	 *
860
	 * @param barreOutils la barre d'outils à modifier
861
	 * */
456 gduche 862
	private void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils)	{
338 gduche 863
 
864
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 865
		enregistrerEtRevenir = new Button("Enregistrer et revenir à la liste");
866
		enregistrerEtRevenir.setIcon(Images.ICONES.scriptGo());
867
		enregistrerEtRevenir.setIconAlign(IconAlign.LEFT);
868
		enregistrerEtRevenir.addSelectionListener(new SelectionListener<ButtonEvent>() {
488 gduche 869
			public void componentSelected(ButtonEvent ce) {
676 gduche 870
				if (enregistrer() == true)	{
871
					((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
872
				}
338 gduche 873
			}
874
		});
456 gduche 875
 
668 gduche 876
		hmIdentite.put("btnEnregistrerRevenir", enregistrerEtRevenir);
877
		barreOutils.add(enregistrerEtRevenir);
878
		enregistrerEtRevenir.setEnabled(false);
456 gduche 879
 
338 gduche 880
	}
881
 
882
	/**
276 gduche 883
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
884
	 *
885
	 * @param barreOutils la barre d'outils à modifier
886
	 * */
456 gduche 887
	private void ajouterBoutonEnregistrer(ButtonBar barreOutils)	{
276 gduche 888
 
889
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 890
		enregistrer = new Button("Enregistrer");
519 gduche 891
		enregistrer.setIcon(Images.ICONES.scriptSave());
892
		enregistrer.setIconAlign(IconAlign.LEFT);
352 gduche 893
		enregistrer.setId("main-button");
488 gduche 894
		enregistrer.addSelectionListener(new SelectionListener<ButtonEvent>() {
895
			public void componentSelected(ButtonEvent ce) {
376 gduche 896
				enregistrer();
276 gduche 897
			}
898
		});
456 gduche 899
		enregistrer.setEnabled(false);
900
		hmIdentite.put("btnEnregistrer", enregistrer);
286 gduche 901
		barreOutils.add(enregistrer);
276 gduche 902
	}
903
 
904
	/**
905
	 * Ajouter le bouton annuler à la barre d'outils donnée
906
	 *
907
	 * @param barreOutils la barre d'outils à modifier
908
	 * */
356 gduche 909
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 910
 
911
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 912
		Button annuler = new Button("Revenir à la liste");
488 gduche 913
		annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {
914
			public void componentSelected(ButtonEvent ce) {
276 gduche 915
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
916
			}
917
		});
918
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
919
		barreOutils.add(annuler);
920
	}
921
 
293 gduche 922
	public void obtenirListeRegionParPays(String strPays)	{
923
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
924
	}
276 gduche 925
 
926
 
293 gduche 927
 
276 gduche 928
	/*---------------------------------------------------------------------------------------
929
	 * 		RAFRAICHISSEMENT DU PANNEAU
930
	 * --------------------------------------------------------------------------------------
931
	 */
283 gduche 932
	public void rafraichir(Object nouvellesDonnees) {
386 gduche 933
 
934
 
935
 
456 gduche 936
		if (nouvellesDonnees instanceof ValeurListe) {
283 gduche 937
 
938
 
939
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
940
 
941
			// Créer une liste de valeurs
942
			List<Valeur> liste = new ArrayList<Valeur>();
943
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
944
				liste.add(listeValeurs.get(it.next()));
945
			}
946
 
947
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
948
 
319 gduche 949
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 950
 
951
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
952
 
953
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
954
 
955
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
956
 
957
				remplirCombobox("cbSexe", liste, "hmIdentite");
283 gduche 958
 
293 gduche 959
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
960
 
961
				remplirCombobox("cbTelephone", liste, "hmIdentite");
319 gduche 962
 
963
				//Préselection du tél
964
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
965
				cbTelephone.setValue(liste.get(1));
293 gduche 966
 
967
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
283 gduche 968
 
293 gduche 969
				remplirCombobox("cbPays", liste, "hmAdresse");
283 gduche 970
 
293 gduche 971
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
283 gduche 972
 
293 gduche 973
				remplirCombobox("cbRegion", liste, "hmAdresse");
283 gduche 974
 
293 gduche 975
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 976
			}
293 gduche 977
 
978
 
456 gduche 979
		} else if (nouvellesDonnees instanceof ProjetListe) {
980
 
981
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
982
 
983
			List<Projet> liste = new ArrayList<Projet>();
984
			for (Iterator<String> it = projets.keySet().iterator(); it.hasNext();) {
985
				liste.add(projets.get(it.next()));
986
			}
987
			ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
988
			ListStore<Projet> storeProjets= cbProjets.getStore();
989
			storeProjets.removeAll();
990
			storeProjets.add(liste);
991
			cbProjets.setStore(storeProjets);
992
 
352 gduche 993
		} else if (nouvellesDonnees instanceof Information)	{
286 gduche 994
 
352 gduche 995
			Information info = (Information) nouvellesDonnees;
386 gduche 996
			if (info.getType().equals("ajout_personne"))	{
352 gduche 997
 
386 gduche 998
				GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
461 gduche 999
				Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
376 gduche 1000
 
433 gduche 1001
			} else if (info.getType().equals("modification_personne"))	{
1002
 
1003
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
668 gduche 1004
			}
1005
			else if (info.getType().equals("maj_utilisateur"))	{
1006
				gererEtatActivationBouton();
386 gduche 1007
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
1008
 
1009
 
1010
					Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
1011
					Iterator itPersonneListe = colPersonneListe.iterator();
1012
					Personne personne = (Personne) itPersonneListe.next();
376 gduche 1013
 
386 gduche 1014
					personneSauvegarde = new Personne();
1015
					personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
376 gduche 1016
 
386 gduche 1017
					binderPersonne(personne);
1018
					//Mise à jour de la personne
1019
					//Personne personne = (Personne) nouvellesDonnees;
1020
 
456 gduche 1021
					ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
1022
					cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
386 gduche 1023
 
1024
					//Prefixe
1025
					String prefixe = personne.get("ce_truk_prefix");
1026
					ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
1027
 
1028
 
1029
					String prefixeCourant = personne.get("ce_truk_prefix");
1030
					if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
1031
						cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
1032
					}	else	{
1033
						cbPrefixe.setRawValue(prefixeCourant);
376 gduche 1034
					}
1035
 
1036
 
386 gduche 1037
					((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
1038
					((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
1039
 
1040
					//Suffixe
1041
					String suffixe = personne.get("ce_truk_suffixe");
1042
					ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
1043
 
1044
					String suffixeCourant = personne.get("ce_truk_suffix");
1045
					if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
1046
						cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
1047
					}	else	{
1048
						cbSuffixe.setRawValue(suffixeCourant);
1049
					}
1050
 
1051
					((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
1052
					((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
1053
					((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
1054
 
1055
 
1056
					(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
1057
					((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
1058
 
1059
					(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
1060
					((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
1061
 
473 gduche 1062
 
386 gduche 1063
					// Telephone
1064
					HashMap<String, String> hmTelephone = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
1065
					if (hmTelephone!=null)	{
1066
 
1067
						ListStore storeTelephone = ((ComboBox) hmIdentite.get("cbTelephone")).getStore();
1068
						List lstModelsTelephone = storeTelephone.getModels();
1069
						Iterator<Valeur> itStore = lstModelsTelephone.iterator();
1070
						HashMap<String, String> hmTel = new HashMap();
1071
						while (itStore.hasNext())	{
1072
							Valeur v = itStore.next();
1073
							hmTel.put(v.getAbreviation(), v.getNom());
376 gduche 1074
						}
1075
 
386 gduche 1076
						Collection<String> colTelephone = hmTelephone.keySet();
1077
						Iterator<String> itTelephone = colTelephone.iterator();
1078
 
1079
						while (itTelephone.hasNext())	{
473 gduche 1080
							String strTelephone = itTelephone.next();
1081
							String strTypeTelephone = hmTelephone.get(strTelephone);
386 gduche 1082
							String idTel = hmTel.get(strTypeTelephone);
1083
							if (idTel == null)	{
1084
								idTel = strTypeTelephone;
1085
							}
1086
 
1087
							ajouterTelephone(strTelephone, idTel, strTypeTelephone);
1088
						}
376 gduche 1089
					}
352 gduche 1090
 
386 gduche 1091
					//Courriel
1092
					LinkedList<String> lCourriels = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
440 gduche 1093
					if (lCourriels != null) {
1094
						Iterator<String> itCourriels = lCourriels.iterator();
386 gduche 1095
 
440 gduche 1096
						while (itCourriels.hasNext())	{
1097
							String strEmail = itCourriels.next();
1098
							ajouterCourriel(strEmail);
1099
						}
386 gduche 1100
					}
1101
 
1102
					// Sites
1103
					LinkedList<String> lUrl = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_url");
433 gduche 1104
					if (lUrl!=null) {
1105
						Iterator<String> itUrl = lUrl.iterator();
1106
						while (itUrl.hasNext())	{
1107
							String strUrl = itUrl.next();
1108
							ajouterUrl(strUrl);
1109
						}
386 gduche 1110
					}
1111
 
1112
					// Sexe
1113
					String strSexe = personne.get("ce_sexe");
1114
					ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
681 gduche 1115
 
678 gduche 1116
					if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)	{
1117
						cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
352 gduche 1118
					}	else	{
386 gduche 1119
						cbSexe.setRawValue(strSexe);
352 gduche 1120
					}
386 gduche 1121
 
1122
					((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
1123
 
1124
					// Logos
1125
					TextArea taLogo = (TextArea) hmIdentite.get("taLogo");
1126
					LinkedList<String> lLogo = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
433 gduche 1127
					if (lLogo!=null)	{
1128
						Iterator<String> itLogo = lLogo.iterator();
1129
						String strValeurLogo = "";
1130
						while (itLogo.hasNext())	{
689 gduche 1131
							strValeurLogo = itLogo.next();
473 gduche 1132
							if (!strValeurLogo.trim().equals(""))	{
1133
								ajouterUrlLogo(strValeurLogo);
1134
							}
433 gduche 1135
						}
386 gduche 1136
					}
1137
 
1138
					/*--------------------------------------------------
1139
					                      Adresse
1140
					 ---------------------------------------------------*/
1141
 
1142
					// Adresse
1143
					((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
1144
 
1145
					// Complément
1146
					((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
1147
 
1148
					//Boite postale
1149
					((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
1150
 
1151
					//Pays
1152
					String strPays = personne.get("pays");
1153
					ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
1154
 
1155
 
1156
					if (cbPays.getStore().findModel("nom", strPays) != null)	{
1157
						cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
1158
					}	else	{
1159
						cbPays.setRawValue(strPays);
1160
					}
1161
 
1162
 
1163
					//Région
1164
					String strRegion = personne.get("region");
1165
					if ((strRegion!=null)&&(!strRegion.equals("")))	{
1166
						ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
1167
						cbRegion.setVisible(true);
1168
 
1169
						if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
1170
							cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
1171
						}	else	{
1172
							cbRegion.setRawValue(strRegion);
1173
						}
1174
					}
1175
 
1176
					//Cp
1177
					((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
1178
 
1179
					//Ville
1180
					((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
1181
 
1182
 
668 gduche 1183
					gererEtatActivationBouton();
456 gduche 1184
 
461 gduche 1185
					nouvellesDonnees = null;
386 gduche 1186
				} else {
1187
					Info.display("messages", info.getMessages().toString());
352 gduche 1188
				}
293 gduche 1189
		}
283 gduche 1190
 
1191
		if (nouvellesDonnees == null)
1192
		{
319 gduche 1193
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 1194
 
1195
			//Met à jour le nom Complet du formulaire
283 gduche 1196
			String valeurRetour = "";
1197
 
1198
			// Prefixe
1199
			String prefixe = "";
319 gduche 1200
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 1201
 
1202
			if (valPrefixe != null)	{
1203
				prefixe = valPrefixe.getNom();
293 gduche 1204
			} else 	{
319 gduche 1205
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 1206
			}
283 gduche 1207
 
293 gduche 1208
 
283 gduche 1209
			// Prénom
1210
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
1211
 
1212
			// Nom
1213
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
1214
 
1215
			// Suffixe
1216
			String suffixe = "";
1217
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
1218
 
1219
			if (valSuffixe != null)	{
1220
				suffixe = valSuffixe.getNom();
293 gduche 1221
			} else 	{
1222
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 1223
			}
1224
 
1225
			// Mettre à jour la valeur
1226
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
1227
			valeurRetour = valeurRetour.replaceAll("null", "");
1228
 
1229
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
1230
 
1231
			if (!valeurRetour.trim().equals(""))	{
1232
				((LabelField) hmIdentite.get("nomComplet")).show();
1233
			} else {
1234
				((LabelField) hmIdentite.get("nomComplet")).hide();
1235
			}
1236
		}
338 gduche 1237
 
1238
		mediateur.masquerPopinChargement();
456 gduche 1239
 
461 gduche 1240
		if (this.mode.equals(MODE_AJOUTER))	{
668 gduche 1241
			gererEtatActivationBouton();
456 gduche 1242
		}
127 gduche 1243
	}
1244
 
352 gduche 1245
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
293 gduche 1246
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
352 gduche 1247
 
293 gduche 1248
		HashMap hm = null;
1249
		if (hashMapId.equals("hmIdentite"))	{
1250
			hm = hmIdentite;
1251
		} else if (hashMapId.equals("hmAdresse")){
1252
			hm = hmAdresse;
1253
		} else {
1254
			hm = hmInfosNat;
1255
		}
1256
 
1257
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1258
 
293 gduche 1259
		store.removeAll();
1260
		store.add(liste);
1261
		((ComboBox) hm.get(idComboBox)).setStore(store);
376 gduche 1262
 
293 gduche 1263
	}
130 gduche 1264
 
352 gduche 1265
 
668 gduche 1266
	private void gererEtatActivationBouton()	{
1267
 
1268
		if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
1269
			enregistrer.setEnabled(false);
1270
			enregistrerEtRevenir.setEnabled(false);
1271
		} else	{
1272
			enregistrer.setEnabled(true);
1273
			enregistrerEtRevenir.setEnabled(true);
1274
		}
1275
 
1276
	}
1277
 
376 gduche 1278
	public void ajouterTelephone(String strTelephone, String strValeurTypeTel, String idTel) 	{
352 gduche 1279
 
1280
 
1281
				//Ajout d'un champ à la liste
376 gduche 1282
				String strIdTelephone =  idTel + "##" + strTelephone + ";;";
352 gduche 1283
 
1284
				FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1285
 
356 gduche 1286
				LayoutContainer lcTelephone = new LayoutContainer();
1287
				lcTelephone.setLayout(new ColumnLayout());
1288
 
352 gduche 1289
				Text tTypeTelephone = new Text();
1290
				tTypeTelephone.setText(strValeurTypeTel+":");
1291
 
376 gduche 1292
				hmIdentite.put("type-" + strIdTelephone, tTypeTelephone);
356 gduche 1293
				lcTelephone.add(tTypeTelephone, new ColumnData(0.40));
352 gduche 1294
 
1295
				Text tTelephone = new Text();
1296
				tTelephone.setText(strTelephone);
376 gduche 1297
				hmIdentite.put("tel-" + strIdTelephone, tTelephone);
356 gduche 1298
				lcTelephone.add(tTelephone, new ColumnData(0.40));
352 gduche 1299
 
540 gduche 1300
				Button bSupprimer = new Button();
1301
				bSupprimer.setIcon(Images.ICONES.supprimer());
376 gduche 1302
				bSupprimer.setId(strIdTelephone);
352 gduche 1303
 
540 gduche 1304
				bSupprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
1305
						public void componentSelected(ButtonEvent ce) {
352 gduche 1306
 
488 gduche 1307
							String strIdTelephone = ce.getComponent().getId();
376 gduche 1308
							LayoutContainer lcContactTel = (LayoutContainer) hmIdentite.get("lc-"+strIdTelephone);
352 gduche 1309
 
376 gduche 1310
							lcContactTel.remove(hmIdentite.get("type-" + strIdTelephone));
1311
							hmIdentite.remove("type-" + strIdTelephone);
352 gduche 1312
 
376 gduche 1313
							lcContactTel.remove(hmIdentite.get("tel-" + strIdTelephone));
1314
							hmIdentite.remove("tel-" + strIdTelephone);
352 gduche 1315
 
488 gduche 1316
							lcContactTel.remove(ce.getComponent());
352 gduche 1317
 
356 gduche 1318
							FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1319
							fsContactTel.remove(lcContactTel);
1320
 
376 gduche 1321
							HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1322
							String strValeurTelephone = hfTelephone.getValue();
1323
							strValeurTelephone = strValeurTelephone.replace(strIdTelephone, "");
1324
							hfTelephone.setValue(strValeurTelephone);
1325
 
352 gduche 1326
							layout();
1327
 
1328
						}
1329
				});
1330
 
356 gduche 1331
				lcTelephone.add(bSupprimer, new ColumnData(0.15));
352 gduche 1332
 
376 gduche 1333
				hmIdentite.put("lc-"+strIdTelephone, lcTelephone);
356 gduche 1334
				fsContactTel.add(lcTelephone);
1335
 
376 gduche 1336
				HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1337
				String strValeurTelephone = hfTelephone.getValue();
1338
				if (strValeurTelephone==null)	{
1339
					strValeurTelephone = "";
1340
				}
1341
				strValeurTelephone += strIdTelephone;
1342
				hfTelephone.setValue(strValeurTelephone);
352 gduche 1343
 
1344
				layout();
1345
 
1346
 
1347
 
1348
 
1349
	}
1350
 
376 gduche 1351
	public void ajouterCourriel(String strEmail)	{
1352
 
1353
			TextField<String> tfCourriel = (TextField<String>) hmIdentite.get("tfCourriel");
1354
			tfCourriel.setValue("");
1355
 
1356
			//Ajouter adresse email
1357
			LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1358
 
1359
			LayoutContainer lcCourriel = new LayoutContainer();
1360
			lcCourriel.setLayout(new ColumnLayout());
1361
 
1362
			LabelField lfCourriel = new LabelField();
1363
			lfCourriel.setText(strEmail);
1364
 
1365
			lcCourriel.add(lfCourriel, new ColumnData(0.8));
1366
			hmIdentite.put("lc-" + strEmail, lcCourriel);
1367
 
1368
			//Bouton supprimer
540 gduche 1369
			Button btnSupprimerCourriel = new Button();
1370
			btnSupprimerCourriel.setIcon(Images.ICONES.supprimer());
376 gduche 1371
			btnSupprimerCourriel.setId(strEmail);
540 gduche 1372
			btnSupprimerCourriel.addSelectionListener(new SelectionListener<ButtonEvent>() {
376 gduche 1373
 
540 gduche 1374
				public void componentSelected(ButtonEvent ce) {
376 gduche 1375
					//Suppression de l'adresse email
488 gduche 1376
					String strEmail = ce.getComponent().getId();
376 gduche 1377
					LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1378
					LayoutContainer lcCourriel = (LayoutContainer) hmIdentite.get("lc-" + strEmail);
1379
					lcCourrielContainer.remove(lcCourriel);
1380
 
1381
					hmIdentite.remove("lc-" + strEmail);
1382
					hmIdentite.remove("email-" + strEmail);
1383
 
1384
						HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1385
					String strValeurCourriel = hfHiddenCourriel.getValue();
1386
					strValeurCourriel = strValeurCourriel.replace(strEmail + ";;", "");
1387
					hfHiddenCourriel.setValue(strValeurCourriel);
1388
 
1389
				}
1390
 
1391
			});
1392
 
1393
			lcCourriel.add(btnSupprimerCourriel);
1394
 
1395
 
1396
 
1397
			lcCourrielContainer.add(lcCourriel);
1398
			hmIdentite.put("email-" + strEmail, lfCourriel);
1399
 
1400
			HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1401
			String strHiddenCourrielValue = hfHiddenCourriel.getValue();
1402
			if (strHiddenCourrielValue == null) {
1403
				strHiddenCourrielValue = "";
1404
			}
1405
			hfHiddenCourriel.setRawValue(strHiddenCourrielValue + strEmail + ";;");
1406
 
1407
 
1408
			layout();
1409
 
1410
	}
1411
 
1412
	public void ajouterUrl(String strUrl)	{
1413
 
1414
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1415
 
1416
		LayoutContainer lcUrl = new LayoutContainer();
1417
		lcUrl.setLayout(new ColumnLayout());
1418
		hmIdentite.put("lc-" + strUrl, lcUrl);
1419
 
1420
 
1421
		Text tUrl = new Text(strUrl);
1422
		hmIdentite.put("url-"+strUrl, tUrl);
1423
 
1424
		lcUrl.add(tUrl, new ColumnData(0.8));
1425
 
540 gduche 1426
		Button ibSupprimerUrl = new Button();
1427
		ibSupprimerUrl.setIcon(Images.ICONES.supprimer());
376 gduche 1428
		ibSupprimerUrl.setId(strUrl);
540 gduche 1429
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ButtonEvent>() {
130 gduche 1430
 
540 gduche 1431
			public void componentSelected(ButtonEvent ce) {
376 gduche 1432
 
1433
				//Suppression url
488 gduche 1434
				String strUrl = ce.getComponent().getId();
376 gduche 1435
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1436
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1437
 
1438
				lcUrlContainer.remove(lcUrl);
1439
 
386 gduche 1440
 
1441
				HiddenField<String> hfUrl = (HiddenField<String>) hmIdentite.get("hfUrl");
1442
				String strValeurUrl = hfUrl.getValue();
1443
				strValeurUrl = strValeurUrl.replace(strUrl, "");
1444
				hfUrl.setValue(strValeurUrl);
1445
 
376 gduche 1446
			}
1447
		});
1448
 
1449
		lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
1450
		lcUrlContainer.add(lcUrl);
1451
 
386 gduche 1452
		HiddenField<String> hfUrl = (HiddenField<String>) hmIdentite.get("hfUrl");
1453
		String strValeurUrl = hfUrl.getValue();
1454
		if (strValeurUrl == null)	{
1455
			strValeurUrl = "";
1456
		}
1457
 
1458
		strValeurUrl += strUrl + ";;";
1459
		hfUrl.setValue(strValeurUrl);
1460
 
376 gduche 1461
		layout();
1462
 
1463
 
1464
 
1465
	}
1466
 
386 gduche 1467
	public void ajouterUrlLogo(String strUrl)	{
1468
 
1469
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1470
 
1471
		LayoutContainer lcUrl = new LayoutContainer();
689 gduche 1472
		lcUrl.setLayout(new RowLayout());
386 gduche 1473
		hmIdentite.put("lc-" + strUrl, lcUrl);
1474
 
689 gduche 1475
		Image logo = new Image(strUrl);
1476
		logo.setHeight("150px");
1477
		logo.setTitle(strUrl);
1478
		lcUrl.add(logo);
386 gduche 1479
 
540 gduche 1480
		Button ibSupprimerUrl = new Button();
1481
		ibSupprimerUrl.setIcon(Images.ICONES.supprimer());
689 gduche 1482
		ibSupprimerUrl.setText("Supprimer");
386 gduche 1483
		ibSupprimerUrl.setId(strUrl);
540 gduche 1484
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ButtonEvent>() {
386 gduche 1485
 
540 gduche 1486
			public void componentSelected(ButtonEvent ce) {
386 gduche 1487
 
1488
				//Suppression url
488 gduche 1489
				String strUrl = ce.getComponent().getId();
386 gduche 1490
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1491
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1492
 
1493
				lcUrlContainer.remove(lcUrl);
1494
 
1495
				HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1496
				String strValeurUrl = hfUrlLogo.getValue();
689 gduche 1497
				strValeurUrl = strValeurUrl.replace(strUrl, "");
386 gduche 1498
 
1499
				hfUrlLogo.setValue(strValeurUrl);
1500
			}
1501
		});
1502
 
689 gduche 1503
		lcUrl.add(ibSupprimerUrl);
386 gduche 1504
		lcUrlContainer.add(lcUrl);
1505
 
689 gduche 1506
 
1507
 
386 gduche 1508
		HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1509
		String strValeurUrl = hfUrlLogo.getValue();
1510
		if (strValeurUrl == null)	{
1511
			strValeurUrl = "";
1512
		}
1513
 
1514
		strValeurUrl += strUrl + ";;";
1515
 
1516
		hfUrlLogo.setValue(strValeurUrl);
1517
 
1518
		layout();
1519
	}
1520
 
376 gduche 1521
	public void reinitialiser()	{
1522
 
461 gduche 1523
		mediateur.afficherPopinChargement();
376 gduche 1524
 
1525
		binderPersonne(personneSauvegarde);
1526
		layout();
1527
 
1528
		mediateur.masquerPopinChargement();
1529
	}
1530
 
1531
 
1532
 
1533
	public void binderPersonne(Personne personne)	{
1534
 
1535
		binding = new FormBinding(this);
1536
 
1537
		personneSelectionnee = personne;
1538
		binding.autoBind();
1539
		binding.bind(personneSelectionnee);
1540
 
1541
		layout();
1542
	}
130 gduche 1543
 
376 gduche 1544
	/**
1545
	 * Enregistre les information de la personne en cours
1546
	 *
1547
	 */
676 gduche 1548
	public boolean enregistrer()	{
376 gduche 1549
 
676 gduche 1550
		boolean success = false;
376 gduche 1551
		LinkedList lstMessageErreur = new LinkedList<String>();
1552
 
456 gduche 1553
		ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");
1554
		Projet projet = cbProjets.getValue();
1555
		if (projet == null)	{
1556
			lstMessageErreur.add("Le projet n'a pas été renseigné");
681 gduche 1557
		} else {
1558
			personneSelectionnee.set("ce_projet", projet.getId());
456 gduche 1559
		}
461 gduche 1560
 
1561
		String strTfNom = ((TextField<String>) hmIdentite.get("tfNom")).getValue();
1562
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1563
			lstMessageErreur.add("Le nom n'a pas été saisi");
622 gduche 1564
		} else {
1565
			strTfNom = UtilString.ucFirst(strTfNom);
1566
			personneSelectionnee.set("nom", strTfNom);
461 gduche 1567
		}
456 gduche 1568
 
622 gduche 1569
		String strTfPrenom = ((TextField<String>) hmIdentite.get("tfPrenom")).getValue();
1570
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1571
 
376 gduche 1572
		//Préparer les données
1573
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1574
		Valeur valeur;
1575
		String strValeur = "";
1576
 
678 gduche 1577
		valeur = (Valeur) combo.getValue();
1578
		if (valeur!=null)	{
1579
			personneSelectionnee.set("ce_sexe", valeur.getId());
1580
		}
376 gduche 1581
 
1582
		strValeur = obtenirValeurCombo("cbPrefixe");
1583
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1584
 
1585
		strValeur = obtenirValeurCombo("cbSuffixe");
1586
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1587
 
1588
		personneSelectionnee.set("truk_courriel", ((HiddenField<String>) hmIdentite.get("hfHiddenCourriel")).getValue());
1589
 
386 gduche 1590
 
1591
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1592
		String strPrefixe = "";
1593
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1594
		valeur = (Valeur) combo.getValue();
1595
		if (valeur != null)	{
1596
			strPrefixe = valeur.getNom();
1597
		} else {
1598
			strPrefixe = combo.getRawValue();
1599
		}
1600
 
1601
		String strSuffixe = "";
1602
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1603
		valeur = (Valeur) combo.getValue();
1604
		if (valeur != null)	{
456 gduche 1605
			strSuffixe = valeur.getNom() + " ";
386 gduche 1606
		} else {
456 gduche 1607
			strSuffixe = combo.getRawValue() +" ";
386 gduche 1608
		}
376 gduche 1609
 
456 gduche 1610
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
376 gduche 1611
 
1612
 
456 gduche 1613
		DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");
1614
		Date naissanceDate = dfDateNaissance.getValue();
1615
		personneSelectionnee.setNaissanceDate(naissanceDate);
376 gduche 1616
 
456 gduche 1617
		Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");
1618
		if (rbEstDecedee.getValue().equals(true))	{
1619
 
1620
			DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");
1621
			Date decesDate = dfDecesDate.getValue();
1622
			if (decesDate == null)	{
1623
				decesDate = new Date();
1624
			}
1625
			personneSelectionnee.setDecesDate(decesDate);
1626
			personneSelectionnee.set("deces_lieu", ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue());
1627
		}
1628
 
1629
		personneSelectionnee.setDecesDate(new Date());
1630
 
376 gduche 1631
		strValeur = obtenirValeurCombo("cbPays");
676 gduche 1632
		personneSelectionnee.set("ce_truk_pays", strValeur);
376 gduche 1633
 
1634
		strValeur = obtenirValeurCombo("cbRegion");
676 gduche 1635
		personneSelectionnee.set("ce_truk_region", strValeur);
376 gduche 1636
 
1637
		personneSelectionnee.set("truk_telephone", ((HiddenField<String>) hmIdentite.get("hfTelephone")).getValue());
1638
 
386 gduche 1639
		String logoUrls = ((HiddenField<String>) hmIdentite.get("hfUrlLogo")).getValue();
1640
		if (logoUrls == null)	{
1641
			logoUrls = "";
1642
		}
1643
		personneSelectionnee.set("truk_logo", logoUrls);
376 gduche 1644
 
386 gduche 1645
		personneSelectionnee.set("truk_url", ((HiddenField) hmIdentite.get("hfUrl")).getValue());
376 gduche 1646
 
461 gduche 1647
		if (lstMessageErreur.size() == 0)	{
386 gduche 1648
			mediateur.enregistrerPersonne(this, personneSelectionnee);
676 gduche 1649
			success = true;
456 gduche 1650
		} else {
1651
			String strMessagesErreur = "<span><br />";
386 gduche 1652
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1653
			while (itMessagesErreur.hasNext())	{
456 gduche 1654
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
386 gduche 1655
			}
456 gduche 1656
			strMessagesErreur += "</span>";
386 gduche 1657
 
1658
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
676 gduche 1659
 			success = false;
456 gduche 1660
		}
676 gduche 1661
 
1662
		return success;
376 gduche 1663
	}
1664
 
1665
	private String obtenirValeurCombo(String strComboName)	{
1666
 
1667
		String strValeur = "";
1668
		Valeur valeur;
1669
 
1670
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1671
		if (combo == null)	{
1672
			combo = (ComboBox) hmAdresse.get(strComboName);
1673
		}
1674
		if (combo.getValue()!=null)	{
1675
			valeur = (Valeur) combo.getValue();
1676
			strValeur = valeur.getId();
1677
		} else {
1678
			strValeur = combo.getRawValue();
1679
		}
1680
 
1681
		return strValeur;
1682
	}
127 gduche 1683
}