Subversion Repositories eFlore/Applications.coel

Rev

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