Subversion Repositories eFlore/Applications.coel

Rev

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