Subversion Repositories eFlore/Applications.coel

Rev

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