Subversion Repositories eFlore/Applications.coel

Rev

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