Subversion Repositories eFlore/Applications.coel

Rev

Rev 692 | Rev 701 | 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");
695 gduche 517
		sites.setValeurParDefaut("http://");
518
		sites.setValidation("^http:\\/\\/[^$]+$", "http://www.monsite.com");
692 gduche 519
		fsContact.add(sites);
520
		hmIdentite.put("sites", sites);
286 gduche 521
 
676 gduche 522
		FieldSet fsAutresInfos = new FieldSet();
523
		fsAutresInfos.setHeading("Autres informations");
524
 
525
		formLayout = new FormLayout();
526
		formLayout.setLabelAlign(LabelAlign.LEFT);
527
		fsAutresInfos.setLayout(formLayout);
356 gduche 528
 
386 gduche 529
 
676 gduche 530
		formLayout = new FormLayout();
531
		formLayout.setLabelAlign(LabelAlign.TOP);
532
		LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout);
533
 
534
		//Civilité
535
		ListStore<Valeur> storeSexe = new ListStore<Valeur>();
536
		ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
537
		cbSexe.setStore(storeSexe);
538
		cbSexe.setFieldLabel("Sexe");
539
		cbSexe.setDisplayField("nom");
540
		cbSexe.setEmptyText("Choisissez le sexe:");
386 gduche 541
 
676 gduche 542
		lcAutreInformations1.add(cbSexe, fd100);
543
		hmIdentite.put("cbSexe", cbSexe);
386 gduche 544
 
676 gduche 545
		mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
546
 
547
		//Description
548
		TextArea taDescription = new TextArea();
549
		taDescription.setEmptyText("Saisissez une description");
550
		taDescription.setFieldLabel("Description");
551
		taDescription.setWidth("100%");
552
		taDescription.setName("description");
553
 
554
		lcAutreInformations1.add(taDescription, fd100);
555
		hmIdentite.put("taDescription", taDescription);
556
 
557
		fsAutresInfos.add(lcAutreInformations1);
558
 
559
		// Logo
689 gduche 560
		LayoutContainer lcLogoUrl = new LayoutContainer();
561
		hmIdentite.put("lcLogoUrl", lcLogoUrl);
676 gduche 562
 
563
		LabelField lfUrlLogo = new LabelField();
564
		lfUrlLogo.setText("<b>Logo:</b>");
689 gduche 565
		lcLogoUrl.add(lfUrlLogo);
676 gduche 566
 
567
		LayoutContainer lcUrlLogo = new LayoutContainer(new ColumnLayout());
568
		hmIdentite.put("lcUrlLogo", lcUrlLogo);
569
 
570
		TextField tfUrlLogo = new TextField();
571
		tfUrlLogo.setValue("http://");
572
 
573
		HiddenField<String> hfUrlLogo = new HiddenField<String>();
574
		hmIdentite.put("hfUrlLogo", hfUrlLogo);
386 gduche 575
 
676 gduche 576
		lcUrlLogo.add(tfUrlLogo, new ColumnData(0.8));
577
		hmIdentite.put("tfUrlLogo", tfUrlLogo);
578
 
579
		Button ibAjouterUrlLogo = new Button();
580
		ibAjouterUrlLogo.setIcon(Images.ICONES.ajouter());
581
		ibAjouterUrlLogo.addSelectionListener(new SelectionListener<ButtonEvent>() {
582
 
583
			public void componentSelected(ButtonEvent ce) {
584
 
585
				TextField<String> tfUrlLogo = (TextField) hmIdentite.get("tfUrlLogo");
586
				String strUrl = tfUrlLogo.getValue();
587
 
588
				if ((strUrl == null)||(strUrl.trim().equals("http://"))||(strUrl.trim().equals("")))	{
589
					MessageBox.alert("Erreur de saisie", "Vous devez saisir un URL", null);
689 gduche 590
				} else if(hmIdentite.get("lc-" + strUrl) != null)	{
676 gduche 591
					MessageBox.alert("Erreur de saisie", "L'url est déjà présente dans la liste.", null);
592
				}	else	{
593
					tfUrlLogo.setValue("http://");
594
					//if (!strUrl.matches("[a-z]{3,}://[a-z0-9-]+.[.a-z0-9-]+(?::[0-9]*)?"))	{
595
					if (!strUrl.startsWith("http://"))	{
596
							MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: http://www.domain.com)", null);
597
						} else if (strUrl.length()>255){
598
							MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
599
						} else {
600
							ajouterUrlLogo(strUrl);
386 gduche 601
						}
676 gduche 602
 
603
				}
604
 
605
			}
606
		});
386 gduche 607
 
676 gduche 608
		lcUrlLogo.add(ibAjouterUrlLogo, new ColumnData(0.15));
689 gduche 609
		lcLogoUrl.add(lcUrlLogo);
386 gduche 610
 
689 gduche 611
		fsAutresInfos.add(lcLogoUrl);
612
 
613
		LayoutContainer lcAutreInformations2 = new LayoutContainer(new ColumnLayout());
614
		hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
676 gduche 615
		fsAutresInfos.add(lcAutreInformations2);
386 gduche 616
 
676 gduche 617
		TextArea taLogo = new TextArea();
618
		taLogo.setFieldLabel("Logos");
619
		taLogo.setWidth("100%");
620
		taLogo.setEmptyText("Saisissez les adresses des logos séparées par un saut de ligne");
621
		//fsAutresInfos.add(taLogo, fd100);
293 gduche 622
 
676 gduche 623
		hmIdentite.put("taLogo", taLogo);
293 gduche 624
 
676 gduche 625
		right.add(fsAutresInfos);
293 gduche 626
 
676 gduche 627
		// Ajout des évènements saisi
628
		KeyListener klNoms = new KeyListener()	{
629
			public void componentKeyUp(ComponentEvent ev)	{
630
				rafraichir(null);
631
			}
632
		};
633
 
634
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
635
			public void selectionChanged(SelectionChangedEvent se) {
636
					rafraichir(null);
637
				}
638
		};
283 gduche 639
 
676 gduche 640
		cbPrefixe.addSelectionChangedListener(selectionChange);
641
		cbPrefixe.addKeyListener(klNoms);
642
		tfPrenom.addKeyListener(klNoms);
643
		tfNom.addKeyListener(klNoms);
644
		cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 645
 
646
	}
647
 
293 gduche 648
	public void creerComposantsAdresse()	{
649
 
650
		// Gauche
651
		LayoutContainer left = new LayoutContainer();
652
		left.setLayout(new FormLayout());
653
 
654
		// Droite
655
		LayoutContainer right = new LayoutContainer();
656
		right.setLayout(new FormLayout());
657
 
658
		// Principal
659
		LayoutContainer main = new LayoutContainer();
660
		main.setLayout(new ColumnLayout());
661
 
662
		// Ajout au principal
663
		main.add(left, new ColumnData(.49));
664
		main.add(right, new ColumnData(.49));
665
 
666
		TextField<String> tfAdresse1 = new TextField();
667
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 668
		tfAdresse1.setName("adresse_01");
319 gduche 669
		left.add(tfAdresse1, fd100);
293 gduche 670
		hmAdresse.put("tfAdresse1", tfAdresse1);
671
 
672
		TextField<String> tfAdresse2 = new TextField();
673
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 674
		tfAdresse2.setName("adresse_02");
319 gduche 675
		left.add(tfAdresse2, fd100);
293 gduche 676
		hmAdresse.put("tfAdresse2", tfAdresse2);
677
 
678
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
679
		cbPays.setFieldLabel("Pays");
680
		cbPays.setDisplayField("nom");
681
		cbPays.setEmptyText("Sélectionnez le pays:");
682
 
683
		ListStore<Valeur> storePays = new ListStore<Valeur>();
684
		cbPays.setStore(storePays);
685
 
319 gduche 686
		right.add(cbPays, fd100);
293 gduche 687
		hmAdresse.put("cbPays", cbPays);
688
 
689
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
690
			public void selectionChanged(SelectionChangedEvent se) {
691
					// Rafraichir avec le pays sélectionné
692
					obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
693
 
694
				}
695
		};
696
 
697
		cbPays.addSelectionChangedListener(selectionChange);
698
 
699
 
700
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
701
		cbRegion.setFieldLabel("Region");
702
		cbRegion.setDisplayField("nom");
703
		cbRegion.setEmptyText("Sélectionnez la région:");
704
		cbRegion.setVisible(false);
705
 
706
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
707
		cbRegion.setStore(storeRegion);
708
 
352 gduche 709
 
319 gduche 710
		right.add(cbRegion, fd100);
293 gduche 711
		hmAdresse.put("cbRegion", cbRegion);
712
 
713
		TextField<String> tfBoitePostale = new TextField<String>();
714
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 715
		tfBoitePostale.setName("bp");
716
 
319 gduche 717
		left.add(tfBoitePostale, fd100);
293 gduche 718
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
719
 
720
		TextField<Integer> tfCodePostal = new TextField<Integer>();
721
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 722
		tfCodePostal.setName("code_postal");
723
 
319 gduche 724
		right.add(tfCodePostal, fd100);
293 gduche 725
		hmAdresse.put("tfCodePostal", tfCodePostal);
726
 
727
		TextField tfVille = new TextField();
728
		tfVille.setFieldLabel("Ville");
376 gduche 729
		tfVille.setName("ville");
293 gduche 730
 
319 gduche 731
		right.add(tfVille, fd100);
293 gduche 732
		hmAdresse.put("tfVille", tfVille);
733
 
734
		// MAJ ComboBox
735
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
736
 
304 gduche 737
		FieldSet fsAdresse = new FieldSet();
738
		fsAdresse.setHeading("Adresse personnelle");
739
		fsAdresse.add(main);
293 gduche 740
 
304 gduche 741
		tiAdresses.add(fsAdresse);
352 gduche 742
		((ComboBox) hmIdentite.get("cbPrefixe")).setRawValue("ljkhlkj");
293 gduche 743
	}
338 gduche 744
 
276 gduche 745
	/**
746
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
747
	 *
748
	 * @param barreOutils la barre d'outils à modifier
749
	 * */
376 gduche 750
	public void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
276 gduche 751
 
752
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
488 gduche 753
		Button reinitialiser = new Button("Réinitialiser le formulaire");
519 gduche 754
		reinitialiser.setIcon(Images.ICONES.rafraichir());
488 gduche 755
		reinitialiser.addSelectionListener(new SelectionListener<ButtonEvent>() {
756
			public void componentSelected(ButtonEvent ce) {
376 gduche 757
				//((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
758
				reinitialiser();
276 gduche 759
			}
760
		});
761
		barreOutils.add(reinitialiser);
762
	}
763
 
764
	/**
338 gduche 765
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
766
	 *
767
	 * @param barreOutils la barre d'outils à modifier
768
	 * */
456 gduche 769
	private void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils)	{
338 gduche 770
 
771
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 772
		enregistrerEtRevenir = new Button("Enregistrer et revenir à la liste");
773
		enregistrerEtRevenir.setIcon(Images.ICONES.scriptGo());
774
		enregistrerEtRevenir.setIconAlign(IconAlign.LEFT);
775
		enregistrerEtRevenir.addSelectionListener(new SelectionListener<ButtonEvent>() {
488 gduche 776
			public void componentSelected(ButtonEvent ce) {
676 gduche 777
				if (enregistrer() == true)	{
778
					((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
779
				}
338 gduche 780
			}
781
		});
456 gduche 782
 
668 gduche 783
		hmIdentite.put("btnEnregistrerRevenir", enregistrerEtRevenir);
784
		barreOutils.add(enregistrerEtRevenir);
785
		enregistrerEtRevenir.setEnabled(false);
456 gduche 786
 
338 gduche 787
	}
788
 
789
	/**
276 gduche 790
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
791
	 *
792
	 * @param barreOutils la barre d'outils à modifier
793
	 * */
456 gduche 794
	private void ajouterBoutonEnregistrer(ButtonBar barreOutils)	{
276 gduche 795
 
796
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 797
		enregistrer = new Button("Enregistrer");
519 gduche 798
		enregistrer.setIcon(Images.ICONES.scriptSave());
799
		enregistrer.setIconAlign(IconAlign.LEFT);
352 gduche 800
		enregistrer.setId("main-button");
488 gduche 801
		enregistrer.addSelectionListener(new SelectionListener<ButtonEvent>() {
802
			public void componentSelected(ButtonEvent ce) {
376 gduche 803
				enregistrer();
276 gduche 804
			}
805
		});
456 gduche 806
		enregistrer.setEnabled(false);
807
		hmIdentite.put("btnEnregistrer", enregistrer);
286 gduche 808
		barreOutils.add(enregistrer);
276 gduche 809
	}
810
 
811
	/**
812
	 * Ajouter le bouton annuler à la barre d'outils donnée
813
	 *
814
	 * @param barreOutils la barre d'outils à modifier
815
	 * */
356 gduche 816
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 817
 
818
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 819
		Button annuler = new Button("Revenir à la liste");
488 gduche 820
		annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {
821
			public void componentSelected(ButtonEvent ce) {
276 gduche 822
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
823
			}
824
		});
825
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
826
		barreOutils.add(annuler);
827
	}
828
 
293 gduche 829
	public void obtenirListeRegionParPays(String strPays)	{
830
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
831
	}
276 gduche 832
 
833
 
293 gduche 834
 
276 gduche 835
	/*---------------------------------------------------------------------------------------
836
	 * 		RAFRAICHISSEMENT DU PANNEAU
837
	 * --------------------------------------------------------------------------------------
838
	 */
283 gduche 839
	public void rafraichir(Object nouvellesDonnees) {
386 gduche 840
 
841
 
842
 
456 gduche 843
		if (nouvellesDonnees instanceof ValeurListe) {
283 gduche 844
 
845
 
846
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
847
 
848
			// Créer une liste de valeurs
849
			List<Valeur> liste = new ArrayList<Valeur>();
850
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
851
				liste.add(listeValeurs.get(it.next()));
852
			}
853
 
854
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
855
 
319 gduche 856
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 857
 
858
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
859
 
860
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
861
 
862
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
863
 
864
				remplirCombobox("cbSexe", liste, "hmIdentite");
283 gduche 865
 
293 gduche 866
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
867
 
868
				remplirCombobox("cbTelephone", liste, "hmIdentite");
319 gduche 869
 
870
				//Préselection du tél
871
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
872
				cbTelephone.setValue(liste.get(1));
293 gduche 873
 
874
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
283 gduche 875
 
293 gduche 876
				remplirCombobox("cbPays", liste, "hmAdresse");
283 gduche 877
 
293 gduche 878
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
283 gduche 879
 
293 gduche 880
				remplirCombobox("cbRegion", liste, "hmAdresse");
283 gduche 881
 
293 gduche 882
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 883
			}
293 gduche 884
 
885
 
456 gduche 886
		} else if (nouvellesDonnees instanceof ProjetListe) {
887
 
888
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
889
 
890
			List<Projet> liste = new ArrayList<Projet>();
891
			for (Iterator<String> it = projets.keySet().iterator(); it.hasNext();) {
892
				liste.add(projets.get(it.next()));
893
			}
894
			ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
895
			ListStore<Projet> storeProjets= cbProjets.getStore();
896
			storeProjets.removeAll();
897
			storeProjets.add(liste);
898
			cbProjets.setStore(storeProjets);
899
 
352 gduche 900
		} else if (nouvellesDonnees instanceof Information)	{
286 gduche 901
 
352 gduche 902
			Information info = (Information) nouvellesDonnees;
386 gduche 903
			if (info.getType().equals("ajout_personne"))	{
352 gduche 904
 
386 gduche 905
				GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
461 gduche 906
				Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
376 gduche 907
 
433 gduche 908
			} else if (info.getType().equals("modification_personne"))	{
909
 
910
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
668 gduche 911
			}
912
			else if (info.getType().equals("maj_utilisateur"))	{
913
				gererEtatActivationBouton();
386 gduche 914
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
915
 
916
					Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
917
					Iterator itPersonneListe = colPersonneListe.iterator();
918
					Personne personne = (Personne) itPersonneListe.next();
376 gduche 919
 
386 gduche 920
					personneSauvegarde = new Personne();
921
					personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
376 gduche 922
 
386 gduche 923
					binderPersonne(personne);
924
					//Mise à jour de la personne
925
					//Personne personne = (Personne) nouvellesDonnees;
926
 
456 gduche 927
					ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
928
					cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
386 gduche 929
 
930
					//Prefixe
931
					String prefixe = personne.get("ce_truk_prefix");
932
					ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
933
 
934
 
935
					String prefixeCourant = personne.get("ce_truk_prefix");
936
					if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
937
						cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
938
					}	else	{
939
						cbPrefixe.setRawValue(prefixeCourant);
376 gduche 940
					}
941
 
942
 
386 gduche 943
					((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
944
					((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
945
 
946
					//Suffixe
947
					String suffixe = personne.get("ce_truk_suffixe");
948
					ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
949
 
950
					String suffixeCourant = personne.get("ce_truk_suffix");
951
					if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
952
						cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
953
					}	else	{
954
						cbSuffixe.setRawValue(suffixeCourant);
955
					}
956
 
957
					((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
958
					((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
959
					((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
960
 
961
 
962
					(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
963
					((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
964
 
965
					(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
966
					((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
967
 
473 gduche 968
 
386 gduche 969
					// Telephone
970
					HashMap<String, String> hmTelephone = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
971
					if (hmTelephone!=null)	{
972
 
973
						ListStore storeTelephone = ((ComboBox) hmIdentite.get("cbTelephone")).getStore();
974
						List lstModelsTelephone = storeTelephone.getModels();
975
						Iterator<Valeur> itStore = lstModelsTelephone.iterator();
976
						HashMap<String, String> hmTel = new HashMap();
977
						while (itStore.hasNext())	{
978
							Valeur v = itStore.next();
979
							hmTel.put(v.getAbreviation(), v.getNom());
376 gduche 980
						}
981
 
386 gduche 982
						Collection<String> colTelephone = hmTelephone.keySet();
983
						Iterator<String> itTelephone = colTelephone.iterator();
984
 
985
						while (itTelephone.hasNext())	{
473 gduche 986
							String strTelephone = itTelephone.next();
987
							String strTypeTelephone = hmTelephone.get(strTelephone);
386 gduche 988
							String idTel = hmTel.get(strTypeTelephone);
989
							if (idTel == null)	{
990
								idTel = strTypeTelephone;
991
							}
992
 
993
							ajouterTelephone(strTelephone, idTel, strTypeTelephone);
994
						}
376 gduche 995
					}
352 gduche 996
 
386 gduche 997
					//Courriel
692 gduche 998
					((ChampMultiValeurs) hmIdentite.get("courriels")).peupler(personne.getCourriel());
386 gduche 999
 
692 gduche 1000
					//Sites web
1001
					((ChampMultiValeurs) hmIdentite.get("sites")).peupler(personne.getString("truk_url"));
386 gduche 1002
 
1003
 
1004
					// Sexe
1005
					String strSexe = personne.get("ce_sexe");
1006
					ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
681 gduche 1007
 
678 gduche 1008
					if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)	{
1009
						cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
352 gduche 1010
					}	else	{
386 gduche 1011
						cbSexe.setRawValue(strSexe);
352 gduche 1012
					}
386 gduche 1013
 
1014
					((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
1015
 
1016
					// Logos
1017
					TextArea taLogo = (TextArea) hmIdentite.get("taLogo");
1018
					LinkedList<String> lLogo = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
433 gduche 1019
					if (lLogo!=null)	{
1020
						Iterator<String> itLogo = lLogo.iterator();
1021
						String strValeurLogo = "";
1022
						while (itLogo.hasNext())	{
689 gduche 1023
							strValeurLogo = itLogo.next();
473 gduche 1024
							if (!strValeurLogo.trim().equals(""))	{
1025
								ajouterUrlLogo(strValeurLogo);
1026
							}
433 gduche 1027
						}
386 gduche 1028
					}
1029
 
1030
					/*--------------------------------------------------
1031
					                      Adresse
1032
					 ---------------------------------------------------*/
1033
 
1034
					// Adresse
1035
					((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
1036
 
1037
					// Complément
1038
					((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
1039
 
1040
					//Boite postale
1041
					((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
1042
 
1043
					//Pays
1044
					String strPays = personne.get("pays");
1045
					ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
1046
 
1047
 
1048
					if (cbPays.getStore().findModel("nom", strPays) != null)	{
1049
						cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
1050
					}	else	{
1051
						cbPays.setRawValue(strPays);
1052
					}
1053
 
1054
 
1055
					//Région
1056
					String strRegion = personne.get("region");
1057
					if ((strRegion!=null)&&(!strRegion.equals("")))	{
1058
						ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
1059
						cbRegion.setVisible(true);
1060
 
1061
						if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
1062
							cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
1063
						}	else	{
1064
							cbRegion.setRawValue(strRegion);
1065
						}
1066
					}
1067
 
1068
					//Cp
1069
					((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
1070
 
1071
					//Ville
1072
					((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
1073
 
1074
 
668 gduche 1075
					gererEtatActivationBouton();
456 gduche 1076
 
461 gduche 1077
					nouvellesDonnees = null;
386 gduche 1078
				} else {
1079
					Info.display("messages", info.getMessages().toString());
352 gduche 1080
				}
293 gduche 1081
		}
283 gduche 1082
 
1083
		if (nouvellesDonnees == null)
1084
		{
319 gduche 1085
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 1086
 
1087
			//Met à jour le nom Complet du formulaire
283 gduche 1088
			String valeurRetour = "";
1089
 
1090
			// Prefixe
1091
			String prefixe = "";
319 gduche 1092
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 1093
 
1094
			if (valPrefixe != null)	{
1095
				prefixe = valPrefixe.getNom();
293 gduche 1096
			} else 	{
319 gduche 1097
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 1098
			}
283 gduche 1099
 
293 gduche 1100
 
283 gduche 1101
			// Prénom
1102
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
1103
 
1104
			// Nom
1105
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
1106
 
1107
			// Suffixe
1108
			String suffixe = "";
1109
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
1110
 
1111
			if (valSuffixe != null)	{
1112
				suffixe = valSuffixe.getNom();
293 gduche 1113
			} else 	{
1114
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 1115
			}
1116
 
1117
			// Mettre à jour la valeur
1118
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
1119
			valeurRetour = valeurRetour.replaceAll("null", "");
1120
 
1121
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
1122
 
1123
			if (!valeurRetour.trim().equals(""))	{
1124
				((LabelField) hmIdentite.get("nomComplet")).show();
1125
			} else {
1126
				((LabelField) hmIdentite.get("nomComplet")).hide();
1127
			}
1128
		}
338 gduche 1129
 
1130
		mediateur.masquerPopinChargement();
456 gduche 1131
 
461 gduche 1132
		if (this.mode.equals(MODE_AJOUTER))	{
668 gduche 1133
			gererEtatActivationBouton();
456 gduche 1134
		}
127 gduche 1135
	}
1136
 
352 gduche 1137
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
293 gduche 1138
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
352 gduche 1139
 
293 gduche 1140
		HashMap hm = null;
1141
		if (hashMapId.equals("hmIdentite"))	{
1142
			hm = hmIdentite;
1143
		} else if (hashMapId.equals("hmAdresse")){
1144
			hm = hmAdresse;
1145
		} else {
1146
			hm = hmInfosNat;
1147
		}
1148
 
1149
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1150
 
293 gduche 1151
		store.removeAll();
1152
		store.add(liste);
1153
		((ComboBox) hm.get(idComboBox)).setStore(store);
376 gduche 1154
 
293 gduche 1155
	}
130 gduche 1156
 
352 gduche 1157
 
668 gduche 1158
	private void gererEtatActivationBouton()	{
1159
 
1160
		if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
1161
			enregistrer.setEnabled(false);
1162
			enregistrerEtRevenir.setEnabled(false);
1163
		} else	{
1164
			enregistrer.setEnabled(true);
1165
			enregistrerEtRevenir.setEnabled(true);
1166
		}
1167
 
1168
	}
1169
 
376 gduche 1170
	public void ajouterTelephone(String strTelephone, String strValeurTypeTel, String idTel) 	{
352 gduche 1171
 
1172
 
1173
				//Ajout d'un champ à la liste
376 gduche 1174
				String strIdTelephone =  idTel + "##" + strTelephone + ";;";
352 gduche 1175
 
1176
				FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1177
 
356 gduche 1178
				LayoutContainer lcTelephone = new LayoutContainer();
1179
				lcTelephone.setLayout(new ColumnLayout());
1180
 
352 gduche 1181
				Text tTypeTelephone = new Text();
1182
				tTypeTelephone.setText(strValeurTypeTel+":");
1183
 
376 gduche 1184
				hmIdentite.put("type-" + strIdTelephone, tTypeTelephone);
356 gduche 1185
				lcTelephone.add(tTypeTelephone, new ColumnData(0.40));
352 gduche 1186
 
1187
				Text tTelephone = new Text();
1188
				tTelephone.setText(strTelephone);
376 gduche 1189
				hmIdentite.put("tel-" + strIdTelephone, tTelephone);
356 gduche 1190
				lcTelephone.add(tTelephone, new ColumnData(0.40));
352 gduche 1191
 
540 gduche 1192
				Button bSupprimer = new Button();
1193
				bSupprimer.setIcon(Images.ICONES.supprimer());
376 gduche 1194
				bSupprimer.setId(strIdTelephone);
352 gduche 1195
 
540 gduche 1196
				bSupprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
1197
						public void componentSelected(ButtonEvent ce) {
352 gduche 1198
 
488 gduche 1199
							String strIdTelephone = ce.getComponent().getId();
376 gduche 1200
							LayoutContainer lcContactTel = (LayoutContainer) hmIdentite.get("lc-"+strIdTelephone);
352 gduche 1201
 
376 gduche 1202
							lcContactTel.remove(hmIdentite.get("type-" + strIdTelephone));
1203
							hmIdentite.remove("type-" + strIdTelephone);
352 gduche 1204
 
376 gduche 1205
							lcContactTel.remove(hmIdentite.get("tel-" + strIdTelephone));
1206
							hmIdentite.remove("tel-" + strIdTelephone);
352 gduche 1207
 
488 gduche 1208
							lcContactTel.remove(ce.getComponent());
352 gduche 1209
 
356 gduche 1210
							FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1211
							fsContactTel.remove(lcContactTel);
1212
 
376 gduche 1213
							HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1214
							String strValeurTelephone = hfTelephone.getValue();
1215
							strValeurTelephone = strValeurTelephone.replace(strIdTelephone, "");
1216
							hfTelephone.setValue(strValeurTelephone);
1217
 
352 gduche 1218
							layout();
1219
 
1220
						}
1221
				});
1222
 
356 gduche 1223
				lcTelephone.add(bSupprimer, new ColumnData(0.15));
352 gduche 1224
 
376 gduche 1225
				hmIdentite.put("lc-"+strIdTelephone, lcTelephone);
356 gduche 1226
				fsContactTel.add(lcTelephone);
1227
 
376 gduche 1228
				HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1229
				String strValeurTelephone = hfTelephone.getValue();
1230
				if (strValeurTelephone==null)	{
1231
					strValeurTelephone = "";
1232
				}
1233
				strValeurTelephone += strIdTelephone;
1234
				hfTelephone.setValue(strValeurTelephone);
352 gduche 1235
 
1236
				layout();
1237
 
1238
 
1239
 
1240
 
1241
	}
1242
 
386 gduche 1243
	public void ajouterUrlLogo(String strUrl)	{
1244
 
1245
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1246
 
1247
		LayoutContainer lcUrl = new LayoutContainer();
689 gduche 1248
		lcUrl.setLayout(new RowLayout());
386 gduche 1249
		hmIdentite.put("lc-" + strUrl, lcUrl);
1250
 
689 gduche 1251
		Image logo = new Image(strUrl);
1252
		logo.setHeight("150px");
1253
		logo.setTitle(strUrl);
1254
		lcUrl.add(logo);
386 gduche 1255
 
540 gduche 1256
		Button ibSupprimerUrl = new Button();
1257
		ibSupprimerUrl.setIcon(Images.ICONES.supprimer());
689 gduche 1258
		ibSupprimerUrl.setText("Supprimer");
386 gduche 1259
		ibSupprimerUrl.setId(strUrl);
540 gduche 1260
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ButtonEvent>() {
386 gduche 1261
 
540 gduche 1262
			public void componentSelected(ButtonEvent ce) {
386 gduche 1263
 
1264
				//Suppression url
488 gduche 1265
				String strUrl = ce.getComponent().getId();
386 gduche 1266
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1267
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1268
 
1269
				lcUrlContainer.remove(lcUrl);
1270
 
1271
				HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1272
				String strValeurUrl = hfUrlLogo.getValue();
689 gduche 1273
				strValeurUrl = strValeurUrl.replace(strUrl, "");
386 gduche 1274
 
1275
				hfUrlLogo.setValue(strValeurUrl);
1276
			}
1277
		});
1278
 
689 gduche 1279
		lcUrl.add(ibSupprimerUrl);
386 gduche 1280
		lcUrlContainer.add(lcUrl);
1281
 
689 gduche 1282
 
1283
 
386 gduche 1284
		HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1285
		String strValeurUrl = hfUrlLogo.getValue();
1286
		if (strValeurUrl == null)	{
1287
			strValeurUrl = "";
1288
		}
1289
 
1290
		strValeurUrl += strUrl + ";;";
1291
 
1292
		hfUrlLogo.setValue(strValeurUrl);
1293
 
1294
		layout();
1295
	}
1296
 
376 gduche 1297
	public void reinitialiser()	{
1298
 
461 gduche 1299
		mediateur.afficherPopinChargement();
376 gduche 1300
 
1301
		binderPersonne(personneSauvegarde);
1302
		layout();
1303
 
1304
		mediateur.masquerPopinChargement();
1305
	}
1306
 
1307
 
1308
 
1309
	public void binderPersonne(Personne personne)	{
1310
 
1311
		binding = new FormBinding(this);
1312
 
1313
		personneSelectionnee = personne;
1314
		binding.autoBind();
1315
		binding.bind(personneSelectionnee);
1316
 
1317
		layout();
1318
	}
130 gduche 1319
 
376 gduche 1320
	/**
1321
	 * Enregistre les information de la personne en cours
1322
	 *
1323
	 */
676 gduche 1324
	public boolean enregistrer()	{
376 gduche 1325
 
676 gduche 1326
		boolean success = false;
376 gduche 1327
		LinkedList lstMessageErreur = new LinkedList<String>();
1328
 
456 gduche 1329
		ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");
1330
		Projet projet = cbProjets.getValue();
1331
		if (projet == null)	{
1332
			lstMessageErreur.add("Le projet n'a pas été renseigné");
681 gduche 1333
		} else {
1334
			personneSelectionnee.set("ce_projet", projet.getId());
456 gduche 1335
		}
461 gduche 1336
 
1337
		String strTfNom = ((TextField<String>) hmIdentite.get("tfNom")).getValue();
1338
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1339
			lstMessageErreur.add("Le nom n'a pas été saisi");
622 gduche 1340
		} else {
1341
			strTfNom = UtilString.ucFirst(strTfNom);
1342
			personneSelectionnee.set("nom", strTfNom);
461 gduche 1343
		}
456 gduche 1344
 
622 gduche 1345
		String strTfPrenom = ((TextField<String>) hmIdentite.get("tfPrenom")).getValue();
1346
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1347
 
376 gduche 1348
		//Préparer les données
1349
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1350
		Valeur valeur;
1351
		String strValeur = "";
1352
 
678 gduche 1353
		valeur = (Valeur) combo.getValue();
1354
		if (valeur!=null)	{
1355
			personneSelectionnee.set("ce_sexe", valeur.getId());
1356
		}
376 gduche 1357
 
1358
		strValeur = obtenirValeurCombo("cbPrefixe");
1359
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1360
 
1361
		strValeur = obtenirValeurCombo("cbSuffixe");
1362
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1363
 
692 gduche 1364
		personneSelectionnee.set("truk_courriel", ((ChampMultiValeurs) hmIdentite.get("courriels")).getValeurs());
376 gduche 1365
 
386 gduche 1366
 
1367
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1368
		String strPrefixe = "";
1369
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1370
		valeur = (Valeur) combo.getValue();
1371
		if (valeur != null)	{
1372
			strPrefixe = valeur.getNom();
1373
		} else {
1374
			strPrefixe = combo.getRawValue();
1375
		}
1376
 
1377
		String strSuffixe = "";
1378
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1379
		valeur = (Valeur) combo.getValue();
1380
		if (valeur != null)	{
456 gduche 1381
			strSuffixe = valeur.getNom() + " ";
386 gduche 1382
		} else {
456 gduche 1383
			strSuffixe = combo.getRawValue() +" ";
386 gduche 1384
		}
376 gduche 1385
 
456 gduche 1386
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
376 gduche 1387
 
1388
 
456 gduche 1389
		DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");
1390
		Date naissanceDate = dfDateNaissance.getValue();
1391
		personneSelectionnee.setNaissanceDate(naissanceDate);
376 gduche 1392
 
456 gduche 1393
		Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");
1394
		if (rbEstDecedee.getValue().equals(true))	{
1395
 
1396
			DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");
1397
			Date decesDate = dfDecesDate.getValue();
1398
			if (decesDate == null)	{
1399
				decesDate = new Date();
1400
			}
1401
			personneSelectionnee.setDecesDate(decesDate);
1402
			personneSelectionnee.set("deces_lieu", ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue());
1403
		}
1404
 
1405
		personneSelectionnee.setDecesDate(new Date());
1406
 
376 gduche 1407
		strValeur = obtenirValeurCombo("cbPays");
676 gduche 1408
		personneSelectionnee.set("ce_truk_pays", strValeur);
376 gduche 1409
 
1410
		strValeur = obtenirValeurCombo("cbRegion");
676 gduche 1411
		personneSelectionnee.set("ce_truk_region", strValeur);
376 gduche 1412
 
1413
		personneSelectionnee.set("truk_telephone", ((HiddenField<String>) hmIdentite.get("hfTelephone")).getValue());
1414
 
386 gduche 1415
		String logoUrls = ((HiddenField<String>) hmIdentite.get("hfUrlLogo")).getValue();
1416
		if (logoUrls == null)	{
1417
			logoUrls = "";
1418
		}
1419
		personneSelectionnee.set("truk_logo", logoUrls);
376 gduche 1420
 
692 gduche 1421
		personneSelectionnee.set("truk_url", ((ChampMultiValeurs) hmIdentite.get("sites")).getValeurs());
376 gduche 1422
 
461 gduche 1423
		if (lstMessageErreur.size() == 0)	{
386 gduche 1424
			mediateur.enregistrerPersonne(this, personneSelectionnee);
676 gduche 1425
			success = true;
456 gduche 1426
		} else {
1427
			String strMessagesErreur = "<span><br />";
386 gduche 1428
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1429
			while (itMessagesErreur.hasNext())	{
456 gduche 1430
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
386 gduche 1431
			}
456 gduche 1432
			strMessagesErreur += "</span>";
386 gduche 1433
 
1434
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
676 gduche 1435
 			success = false;
456 gduche 1436
		}
676 gduche 1437
 
1438
		return success;
376 gduche 1439
	}
1440
 
1441
	private String obtenirValeurCombo(String strComboName)	{
1442
 
1443
		String strValeur = "";
1444
		Valeur valeur;
1445
 
1446
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1447
		if (combo == null)	{
1448
			combo = (ComboBox) hmAdresse.get(strComboName);
1449
		}
1450
		if (combo.getValue()!=null)	{
1451
			valeur = (Valeur) combo.getValue();
1452
			strValeur = valeur.getId();
1453
		} else {
1454
			strValeur = combo.getRawValue();
1455
		}
1456
 
1457
		return strValeur;
1458
	}
127 gduche 1459
}