Subversion Repositories eFlore/Applications.coel

Rev

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