Subversion Repositories eFlore/Applications.coel

Rev

Rev 695 | Rev 722 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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