Subversion Repositories eFlore/Applications.coel

Rev

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

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