Subversion Repositories eFlore/Applications.coel

Rev

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