Subversion Repositories eFlore/Applications.coel

Rev

Rev 437 | Rev 440 | 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
 
437 gduche 70
public class PersonneForm 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
	 * */
437 gduche 97
	public PersonneForm() {
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("");
439 gduche 534
										//if (!strUrl.matches("[a-z]{3,}://[a-z0-9-]+.[.a-z0-9-]+(?::[0-9]*)?"))	{
535
										if (!strUrl.startsWith("http://"))	{
376 gduche 536
											MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: http://www.domain.com)", null);
537
										} else if (strUrl.length()>255){
538
											MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
539
										} else {
540
											ajouterUrl(strUrl);
541
										}
542
 
293 gduche 543
								}
544
 
545
							}
376 gduche 546
						});
286 gduche 547
 
376 gduche 548
						lcUrl.add(ibAjouterUrl, new ColumnData(0.15));
549
					fsContact.add(lcUrl);
286 gduche 550
 
376 gduche 551
					LayoutContainer lcUrlContainer = new LayoutContainer(new RowLayout());
552
 
553
					fsContact.add(lcUrlContainer);
554
					hmIdentite.put("lcUrlContainer", lcUrlContainer);
555
 
556
					FieldSet fsAutresInfos = new FieldSet();
557
					fsAutresInfos.setHeading("Autres informations");
286 gduche 558
 
376 gduche 559
					formLayout = new FormLayout();
560
					formLayout.setLabelAlign(LabelAlign.LEFT);
561
					fsAutresInfos.setLayout(formLayout);
286 gduche 562
 
376 gduche 563
 
386 gduche 564
			formLayout = new FormLayout();
565
			formLayout.setLabelAlign(LabelAlign.TOP);
566
			LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout);
567
 
568
			//Civilité
569
			ListStore<Valeur> storeSexe = new ListStore<Valeur>();
570
			ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
571
			cbSexe.setStore(storeSexe);
572
			cbSexe.setFieldLabel("Sexe");
573
			cbSexe.setDisplayField("nom");
574
			cbSexe.setEmptyText("Choisissez le sexe:");
575
 
576
			lcAutreInformations1.add(cbSexe, fd100);
577
			hmIdentite.put("cbSexe", cbSexe);
578
 
579
			mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
356 gduche 580
 
293 gduche 581
			//Description
582
			TextArea taDescription = new TextArea();
583
			taDescription.setEmptyText("Saisissez une description");
584
			taDescription.setFieldLabel("Description");
319 gduche 585
			taDescription.setWidth("100%");
376 gduche 586
			taDescription.setName("description");
293 gduche 587
 
386 gduche 588
			lcAutreInformations1.add(taDescription, fd100);
293 gduche 589
			hmIdentite.put("taDescription", taDescription);
590
 
386 gduche 591
			fsAutresInfos.add(lcAutreInformations1);
376 gduche 592
 
293 gduche 593
			// Logo
386 gduche 594
			LayoutContainer lcAutreInformations2 = new LayoutContainer();
595
			hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
596
 
597
			LabelField lfUrlLogo = new LabelField();
598
			lfUrlLogo.setText("<b>Logo:</b>");
599
			lcAutreInformations2.add(lfUrlLogo);
600
 
601
			LayoutContainer lcUrlLogo = new LayoutContainer(new ColumnLayout());
602
			hmIdentite.put("lcUrlLogo", lcUrlLogo);
603
 
604
				TextField tfUrlLogo = new TextField();
605
				tfUrlLogo.setValue("http://");
606
 
607
				HiddenField<String> hfUrlLogo = new HiddenField<String>();
608
				hmIdentite.put("hfUrlLogo", hfUrlLogo);
609
 
610
				lcUrlLogo.add(tfUrlLogo, new ColumnData(0.8));
611
				hmIdentite.put("tfUrlLogo", tfUrlLogo);
612
 
613
				IconButton ibAjouterUrlLogo = new IconButton(ComposantClass.ICONE_AJOUTER);
614
				ibAjouterUrlLogo.addSelectionListener(new SelectionListener<ComponentEvent>() {
615
 
616
					public void componentSelected(ComponentEvent ce) {
617
 
618
						TextField<String> tfUrlLogo = (TextField) hmIdentite.get("tfUrlLogo");
619
						String strUrl = tfUrlLogo.getValue();
620
 
621
						if ((strUrl == null)||(strUrl.trim().equals("http://"))||(strUrl.trim().equals("")))	{
622
							MessageBox.alert("Erreur de saisie", "Vous devez saisir un URL", null);
623
						} else if(hmIdentite.get("url-" + strUrl) != null)	{
624
							MessageBox.alert("Erreur de saisie", "L'url est déjà présente dans la liste.", null);
625
						}	else	{
626
							tfUrlLogo.setValue("");
439 gduche 627
							//if (!strUrl.matches("[a-z]{3,}://[a-z0-9-]+.[.a-z0-9-]+(?::[0-9]*)?"))	{
628
							if (!strUrl.startsWith("http://"))	{
386 gduche 629
									MessageBox.alert("Erreur de saisie", "L'adresse n'est pas au bon format (ex: http://www.domain.com)", null);
630
								} else if (strUrl.length()>255){
631
									MessageBox.alert("Erreur de saisie", "L'adresse ne peut dépasser 255 caractères", null);
632
								} else {
633
									ajouterUrlLogo(strUrl);
634
								}
635
 
636
						}
637
 
638
					}
639
				});
640
 
641
				lcUrlLogo.add(ibAjouterUrlLogo, new ColumnData(0.15));
642
				lcAutreInformations2.add(lcUrlLogo);
643
 
644
			fsAutresInfos.add(lcAutreInformations2);
645
 
293 gduche 646
			TextArea taLogo = new TextArea();
647
			taLogo.setFieldLabel("Logos");
319 gduche 648
			taLogo.setWidth("100%");
293 gduche 649
			taLogo.setEmptyText("Saisissez les adresses des logos séparées par un saut de ligne");
386 gduche 650
			//fsAutresInfos.add(taLogo, fd100);
293 gduche 651
 
652
			hmIdentite.put("taLogo", taLogo);
653
 
376 gduche 654
			right.add(fsAutresInfos);
293 gduche 655
 
276 gduche 656
			// Ajout des évènements saisi
657
			KeyListener klNoms = new KeyListener()	{
658
				public void componentKeyUp(ComponentEvent ev)	{
283 gduche 659
					rafraichir(null);
280 gduche 660
				}
276 gduche 661
			};
662
 
283 gduche 663
			SelectionChangedListener<InterneValeur> selectionChange = new SelectionChangedListener<InterneValeur>() {
664
				public void selectionChanged(SelectionChangedEvent se) {
665
						rafraichir(null);
666
					}
667
			};
668
 
319 gduche 669
			cbPrefixe.addSelectionChangedListener(selectionChange);
670
			cbPrefixe.addKeyListener(klNoms);
276 gduche 671
			tfPrenom.addKeyListener(klNoms);
672
			tfNom.addKeyListener(klNoms);
283 gduche 673
			cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 674
 
675
	}
676
 
293 gduche 677
	public void creerComposantsAdresse()	{
678
 
679
		// Gauche
680
		LayoutContainer left = new LayoutContainer();
681
		left.setLayout(new FormLayout());
682
 
683
		// Droite
684
		LayoutContainer right = new LayoutContainer();
685
		right.setLayout(new FormLayout());
686
 
687
		// Principal
688
		LayoutContainer main = new LayoutContainer();
689
		main.setLayout(new ColumnLayout());
690
 
691
		// Ajout au principal
692
		main.add(left, new ColumnData(.49));
693
		main.add(right, new ColumnData(.49));
694
 
695
		TextField<String> tfAdresse1 = new TextField();
696
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 697
		tfAdresse1.setName("adresse_01");
319 gduche 698
		left.add(tfAdresse1, fd100);
293 gduche 699
		hmAdresse.put("tfAdresse1", tfAdresse1);
700
 
701
		TextField<String> tfAdresse2 = new TextField();
702
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 703
		tfAdresse2.setName("adresse_02");
319 gduche 704
		left.add(tfAdresse2, fd100);
293 gduche 705
		hmAdresse.put("tfAdresse2", tfAdresse2);
706
 
707
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
708
		cbPays.setFieldLabel("Pays");
709
		cbPays.setDisplayField("nom");
710
		cbPays.setEmptyText("Sélectionnez le pays:");
711
 
712
		ListStore<Valeur> storePays = new ListStore<Valeur>();
713
		cbPays.setStore(storePays);
714
 
319 gduche 715
		right.add(cbPays, fd100);
293 gduche 716
		hmAdresse.put("cbPays", cbPays);
717
 
718
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
719
			public void selectionChanged(SelectionChangedEvent se) {
720
					// Rafraichir avec le pays sélectionné
721
					obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
722
 
723
				}
724
		};
725
 
726
		cbPays.addSelectionChangedListener(selectionChange);
727
 
728
 
729
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
730
		cbRegion.setFieldLabel("Region");
731
		cbRegion.setDisplayField("nom");
732
		cbRegion.setEmptyText("Sélectionnez la région:");
733
		cbRegion.setVisible(false);
734
 
735
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
736
		cbRegion.setStore(storeRegion);
737
 
352 gduche 738
 
319 gduche 739
		right.add(cbRegion, fd100);
293 gduche 740
		hmAdresse.put("cbRegion", cbRegion);
741
 
742
		TextField<String> tfBoitePostale = new TextField<String>();
743
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 744
		tfBoitePostale.setName("bp");
745
 
319 gduche 746
		left.add(tfBoitePostale, fd100);
293 gduche 747
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
748
 
749
		TextField<Integer> tfCodePostal = new TextField<Integer>();
750
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 751
		tfCodePostal.setName("code_postal");
752
 
319 gduche 753
		right.add(tfCodePostal, fd100);
293 gduche 754
		hmAdresse.put("tfCodePostal", tfCodePostal);
755
 
756
		TextField tfVille = new TextField();
757
		tfVille.setFieldLabel("Ville");
376 gduche 758
		tfVille.setName("ville");
293 gduche 759
 
319 gduche 760
		right.add(tfVille, fd100);
293 gduche 761
		hmAdresse.put("tfVille", tfVille);
762
 
763
		// MAJ ComboBox
764
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
765
 
304 gduche 766
		FieldSet fsAdresse = new FieldSet();
767
		fsAdresse.setHeading("Adresse personnelle");
768
		fsAdresse.add(main);
293 gduche 769
 
304 gduche 770
		tiAdresses.add(fsAdresse);
771
 
352 gduche 772
		((ComboBox) hmIdentite.get("cbPrefixe")).setRawValue("ljkhlkj");
773
 
774
 
293 gduche 775
	}
338 gduche 776
 
276 gduche 777
	/**
778
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
779
	 *
780
	 * @param barreOutils la barre d'outils à modifier
781
	 * */
376 gduche 782
	public void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
276 gduche 783
 
784
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
352 gduche 785
		TextToolItem reinitialiser = new TextToolItem("Réinitialiser le formulaire");
276 gduche 786
		reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
787
		reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
788
			public void componentSelected(ComponentEvent ce) {
376 gduche 789
				//((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
790
				reinitialiser();
791
				//System.out.println(personneSelectionnee);
276 gduche 792
			}
793
		});
794
		barreOutils.add(reinitialiser);
795
	}
796
 
797
	/**
338 gduche 798
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
799
	 *
800
	 * @param barreOutils la barre d'outils à modifier
801
	 * */
356 gduche 802
	public static void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils)	{
338 gduche 803
 
804
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
356 gduche 805
		Button enregistrer = new Button("Enregistrer et revenir à la liste");
338 gduche 806
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
807
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
808
			public void componentSelected(ComponentEvent ce) {
809
				// TODO : Enregistrer le formulaire
810
			}
811
		});
812
		barreOutils.add(enregistrer);
813
	}
814
 
815
	/**
276 gduche 816
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
817
	 *
818
	 * @param barreOutils la barre d'outils à modifier
819
	 * */
376 gduche 820
	public void ajouterBoutonEnregistrer(ButtonBar barreOutils)	{
276 gduche 821
 
822
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
356 gduche 823
		Button enregistrer = new Button("Enregistrer");
286 gduche 824
		enregistrer.setIconStyle(ComposantClass.ICONE_PREFERENCE);
352 gduche 825
		enregistrer.setId("main-button");
286 gduche 826
		enregistrer.addSelectionListener(new SelectionListener<ComponentEvent>() {
276 gduche 827
			public void componentSelected(ComponentEvent ce) {
376 gduche 828
				enregistrer();
829
 
830
 
276 gduche 831
			}
832
		});
286 gduche 833
		barreOutils.add(enregistrer);
276 gduche 834
	}
835
 
836
	/**
837
	 * Ajouter le bouton annuler à la barre d'outils donnée
838
	 *
839
	 * @param barreOutils la barre d'outils à modifier
840
	 * */
356 gduche 841
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 842
 
843
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 844
		Button annuler = new Button("Revenir à la liste");
276 gduche 845
		annuler.addSelectionListener(new SelectionListener<ComponentEvent>() {
846
			public void componentSelected(ComponentEvent ce) {
847
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
848
			}
849
		});
850
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
851
		barreOutils.add(annuler);
852
	}
853
 
293 gduche 854
	public void obtenirListeRegionParPays(String strPays)	{
855
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
856
	}
276 gduche 857
 
858
 
293 gduche 859
 
276 gduche 860
	/*---------------------------------------------------------------------------------------
861
	 * 		RAFRAICHISSEMENT DU PANNEAU
862
	 * --------------------------------------------------------------------------------------
863
	 */
283 gduche 864
	public void rafraichir(Object nouvellesDonnees) {
386 gduche 865
 
866
 
867
 
283 gduche 868
		if (nouvellesDonnees instanceof ValeurListe){
869
 
870
 
871
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
872
 
873
			// Créer une liste de valeurs
874
			List<Valeur> liste = new ArrayList<Valeur>();
875
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
876
				liste.add(listeValeurs.get(it.next()));
877
			}
878
 
879
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
880
 
319 gduche 881
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 882
 
883
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
884
 
885
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
886
 
887
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
888
 
889
				remplirCombobox("cbSexe", liste, "hmIdentite");
283 gduche 890
 
293 gduche 891
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
892
 
893
				remplirCombobox("cbTelephone", liste, "hmIdentite");
319 gduche 894
 
895
				//Préselection du tél
896
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
897
				cbTelephone.setValue(liste.get(1));
293 gduche 898
 
899
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
283 gduche 900
 
293 gduche 901
				remplirCombobox("cbPays", liste, "hmAdresse");
283 gduche 902
 
293 gduche 903
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
283 gduche 904
 
293 gduche 905
				remplirCombobox("cbRegion", liste, "hmAdresse");
283 gduche 906
 
293 gduche 907
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 908
			}
293 gduche 909
 
910
 
352 gduche 911
		} else if (nouvellesDonnees instanceof Information)	{
286 gduche 912
 
352 gduche 913
			Information info = (Information) nouvellesDonnees;
386 gduche 914
			if (info.getType().equals("ajout_personne"))	{
352 gduche 915
 
386 gduche 916
				personneSelectionnee.set("id_personne", info.toString());
917
				GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
376 gduche 918
 
433 gduche 919
				Info.display("Enregistrement", "La personne a été ajoutée (PID:" + personneSelectionnee.getId() + ")");
386 gduche 920
				//Passer en mode modifier
376 gduche 921
 
433 gduche 922
			} else if (info.getType().equals("modification_personne"))	{
923
 
924
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
925
 
386 gduche 926
			} else if (info.getType().equals("suppression_personne"))	{
433 gduche 927
 
386 gduche 928
				GWT.log(info.toString(), null);
929
				Info.display("lk", info.getMessages().toString());
930
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
931
 
932
 
933
					Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
934
					Iterator itPersonneListe = colPersonneListe.iterator();
935
					Personne personne = (Personne) itPersonneListe.next();
376 gduche 936
 
386 gduche 937
					personneSauvegarde = new Personne();
938
					personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
376 gduche 939
 
386 gduche 940
					binderPersonne(personne);
941
					//Mise à jour de la personne
942
					//Personne personne = (Personne) nouvellesDonnees;
943
 
944
 
945
 
946
					//Prefixe
947
					String prefixe = personne.get("ce_truk_prefix");
948
					ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
949
 
950
 
951
					String prefixeCourant = personne.get("ce_truk_prefix");
952
					if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
953
						cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
954
					}	else	{
955
						cbPrefixe.setRawValue(prefixeCourant);
376 gduche 956
					}
957
 
958
 
386 gduche 959
					((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
960
					((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
961
 
962
					//Suffixe
963
					String suffixe = personne.get("ce_truk_suffixe");
964
					ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
965
 
966
					String suffixeCourant = personne.get("ce_truk_suffix");
967
					if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
968
						cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
969
					}	else	{
970
						cbSuffixe.setRawValue(suffixeCourant);
971
					}
972
 
973
					((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
974
					((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
975
					((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
976
 
977
 
978
					(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
979
					((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
980
 
981
					(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
982
					((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
983
 
984
					// Telephone
985
					HashMap<String, String> hmTelephone = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
986
					if (hmTelephone!=null)	{
987
 
988
 
989
						ListStore storeTelephone = ((ComboBox) hmIdentite.get("cbTelephone")).getStore();
990
						List lstModelsTelephone = storeTelephone.getModels();
991
						Iterator<Valeur> itStore = lstModelsTelephone.iterator();
992
						HashMap<String, String> hmTel = new HashMap();
993
						while (itStore.hasNext())	{
994
							Valeur v = itStore.next();
995
							hmTel.put(v.getAbreviation(), v.getNom());
376 gduche 996
						}
997
 
386 gduche 998
 
999
						Collection<String> colTelephone = hmTelephone.keySet();
1000
						Iterator<String> itTelephone = colTelephone.iterator();
1001
 
1002
						while (itTelephone.hasNext())	{
1003
							String strTypeTelephone = itTelephone.next();
1004
							String strTelephone = hmTelephone.get(strTypeTelephone);
1005
							String idTel = hmTel.get(strTypeTelephone);
1006
							if (idTel == null)	{
1007
								idTel = strTypeTelephone;
1008
							}
1009
 
1010
							ajouterTelephone(strTelephone, idTel, strTypeTelephone);
1011
						}
376 gduche 1012
					}
352 gduche 1013
 
386 gduche 1014
					//Courriel
1015
					LinkedList<String> lCourriels = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
1016
					Iterator<String> itCourriels = lCourriels.iterator();
1017
 
1018
					while (itCourriels.hasNext())	{
1019
						String strEmail = itCourriels.next();
1020
						ajouterCourriel(strEmail);
1021
					}
1022
 
1023
					// Sites
1024
					LinkedList<String> lUrl = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_url");
433 gduche 1025
					if (lUrl!=null) {
1026
						Iterator<String> itUrl = lUrl.iterator();
1027
						while (itUrl.hasNext())	{
1028
							String strUrl = itUrl.next();
1029
							ajouterUrl(strUrl);
1030
						}
386 gduche 1031
					}
1032
 
1033
					// Sexe
1034
					String strSexe = personne.get("ce_sexe");
1035
					ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
1036
 
1037
 
1038
					//FIXME : le lien avec la bdd ne peut pas se faire
1039
					if (cbSexe.getStore().findModel("abreviation", strSexe) != null)	{
1040
						cbSexe.setValue(cbSexe.getStore().findModel("abreviation", strSexe));
352 gduche 1041
					}	else	{
386 gduche 1042
						cbSexe.setRawValue(strSexe);
352 gduche 1043
					}
386 gduche 1044
 
1045
					((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
1046
 
1047
					// Logos
1048
					TextArea taLogo = (TextArea) hmIdentite.get("taLogo");
1049
					LinkedList<String> lLogo = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
433 gduche 1050
					if (lLogo!=null)	{
1051
						Iterator<String> itLogo = lLogo.iterator();
1052
						String strValeurLogo = "";
1053
						while (itLogo.hasNext())	{
1054
							strValeurLogo += itLogo.next() + "\n";
1055
						}
386 gduche 1056
 
433 gduche 1057
						if (!strValeurLogo.trim().equals(""))	{
439 gduche 1058
							ajouterUrlLogo(strValeurLogo);
433 gduche 1059
						}
386 gduche 1060
					}
1061
 
1062
					/*--------------------------------------------------
1063
					                      Adresse
1064
					 ---------------------------------------------------*/
1065
 
1066
					// Adresse
1067
					((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
1068
 
1069
					// Complément
1070
					((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
1071
 
1072
					//Boite postale
1073
					((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
1074
 
1075
					//Pays
1076
					String strPays = personne.get("pays");
1077
					ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
1078
 
1079
 
1080
					if (cbPays.getStore().findModel("nom", strPays) != null)	{
1081
						cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
1082
					}	else	{
1083
						cbPays.setRawValue(strPays);
1084
					}
1085
 
1086
 
1087
					//Région
1088
					String strRegion = personne.get("region");
1089
					if ((strRegion!=null)&&(!strRegion.equals("")))	{
1090
						ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
1091
						cbRegion.setVisible(true);
1092
 
1093
						if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
1094
							cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
1095
						}	else	{
1096
							cbRegion.setRawValue(strRegion);
1097
						}
1098
					}
1099
 
1100
					//Cp
1101
					((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
1102
 
1103
					//Ville
1104
					((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
1105
 
1106
 
1107
				} else {
1108
					Info.display("messages", info.getMessages().toString());
352 gduche 1109
				}
293 gduche 1110
		}
283 gduche 1111
 
1112
		if (nouvellesDonnees == null)
1113
		{
319 gduche 1114
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 1115
 
1116
			//Met à jour le nom Complet du formulaire
283 gduche 1117
			String valeurRetour = "";
1118
 
1119
			// Prefixe
1120
			String prefixe = "";
319 gduche 1121
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 1122
 
1123
			if (valPrefixe != null)	{
1124
				prefixe = valPrefixe.getNom();
293 gduche 1125
			} else 	{
319 gduche 1126
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 1127
			}
283 gduche 1128
 
293 gduche 1129
 
283 gduche 1130
			// Prénom
1131
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
1132
 
1133
			// Nom
1134
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
1135
 
1136
			// Suffixe
1137
			String suffixe = "";
1138
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
1139
 
1140
			if (valSuffixe != null)	{
1141
				suffixe = valSuffixe.getNom();
293 gduche 1142
			} else 	{
1143
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 1144
			}
1145
 
1146
			// Mettre à jour la valeur
1147
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
1148
			valeurRetour = valeurRetour.replaceAll("null", "");
1149
 
1150
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
1151
 
1152
			if (!valeurRetour.trim().equals(""))	{
1153
				((LabelField) hmIdentite.get("nomComplet")).show();
1154
			} else {
1155
				((LabelField) hmIdentite.get("nomComplet")).hide();
1156
			}
1157
		}
338 gduche 1158
 
1159
		mediateur.masquerPopinChargement();
127 gduche 1160
	}
1161
 
352 gduche 1162
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
293 gduche 1163
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
352 gduche 1164
 
293 gduche 1165
		HashMap hm = null;
1166
		if (hashMapId.equals("hmIdentite"))	{
1167
			hm = hmIdentite;
1168
		} else if (hashMapId.equals("hmAdresse")){
1169
			hm = hmAdresse;
1170
		} else {
1171
			hm = hmInfosNat;
1172
		}
1173
 
1174
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1175
 
293 gduche 1176
		store.removeAll();
1177
		store.add(liste);
1178
		((ComboBox) hm.get(idComboBox)).setStore(store);
376 gduche 1179
 
293 gduche 1180
	}
130 gduche 1181
 
352 gduche 1182
 
376 gduche 1183
	public void ajouterTelephone(String strTelephone, String strValeurTypeTel, String idTel) 	{
352 gduche 1184
 
1185
 
1186
				//Ajout d'un champ à la liste
376 gduche 1187
				String strIdTelephone =  idTel + "##" + strTelephone + ";;";
352 gduche 1188
 
1189
				FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1190
 
356 gduche 1191
				LayoutContainer lcTelephone = new LayoutContainer();
1192
				lcTelephone.setLayout(new ColumnLayout());
1193
 
352 gduche 1194
				Text tTypeTelephone = new Text();
1195
				tTypeTelephone.setText(strValeurTypeTel+":");
1196
 
376 gduche 1197
				hmIdentite.put("type-" + strIdTelephone, tTypeTelephone);
356 gduche 1198
				lcTelephone.add(tTypeTelephone, new ColumnData(0.40));
352 gduche 1199
 
1200
				Text tTelephone = new Text();
1201
				tTelephone.setText(strTelephone);
376 gduche 1202
				hmIdentite.put("tel-" + strIdTelephone, tTelephone);
356 gduche 1203
				lcTelephone.add(tTelephone, new ColumnData(0.40));
352 gduche 1204
 
1205
				IconButton bSupprimer = new IconButton(ComposantClass.ICONE_SUPPRIMER);
376 gduche 1206
				bSupprimer.setId(strIdTelephone);
352 gduche 1207
 
1208
				bSupprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
1209
						public void componentSelected(ComponentEvent ce) {
1210
 
376 gduche 1211
							String strIdTelephone = ce.component.getId();
1212
							LayoutContainer lcContactTel = (LayoutContainer) hmIdentite.get("lc-"+strIdTelephone);
352 gduche 1213
 
376 gduche 1214
							lcContactTel.remove(hmIdentite.get("type-" + strIdTelephone));
1215
							hmIdentite.remove("type-" + strIdTelephone);
352 gduche 1216
 
376 gduche 1217
							lcContactTel.remove(hmIdentite.get("tel-" + strIdTelephone));
1218
							hmIdentite.remove("tel-" + strIdTelephone);
352 gduche 1219
 
356 gduche 1220
							lcContactTel.remove(ce.component);
352 gduche 1221
 
356 gduche 1222
							FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1223
							fsContactTel.remove(lcContactTel);
1224
 
376 gduche 1225
							HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1226
							String strValeurTelephone = hfTelephone.getValue();
1227
							strValeurTelephone = strValeurTelephone.replace(strIdTelephone, "");
1228
							hfTelephone.setValue(strValeurTelephone);
1229
 
352 gduche 1230
							layout();
1231
 
1232
						}
1233
				});
1234
 
356 gduche 1235
				lcTelephone.add(bSupprimer, new ColumnData(0.15));
352 gduche 1236
 
376 gduche 1237
				hmIdentite.put("lc-"+strIdTelephone, lcTelephone);
356 gduche 1238
				fsContactTel.add(lcTelephone);
1239
 
376 gduche 1240
				HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1241
				String strValeurTelephone = hfTelephone.getValue();
1242
				if (strValeurTelephone==null)	{
1243
					strValeurTelephone = "";
1244
				}
1245
				strValeurTelephone += strIdTelephone;
1246
				hfTelephone.setValue(strValeurTelephone);
352 gduche 1247
 
1248
				layout();
1249
 
1250
 
1251
 
1252
 
1253
	}
1254
 
376 gduche 1255
	public void ajouterCourriel(String strEmail)	{
1256
 
1257
			TextField<String> tfCourriel = (TextField<String>) hmIdentite.get("tfCourriel");
1258
			tfCourriel.setValue("");
1259
 
1260
			//Ajouter adresse email
1261
			LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1262
 
1263
			LayoutContainer lcCourriel = new LayoutContainer();
1264
			lcCourriel.setLayout(new ColumnLayout());
1265
 
1266
			LabelField lfCourriel = new LabelField();
1267
			lfCourriel.setText(strEmail);
1268
 
1269
			lcCourriel.add(lfCourriel, new ColumnData(0.8));
1270
			hmIdentite.put("lc-" + strEmail, lcCourriel);
1271
 
1272
			//Bouton supprimer
1273
			IconButton btnSupprimerCourriel = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1274
			btnSupprimerCourriel.setId(strEmail);
1275
			btnSupprimerCourriel.addSelectionListener(new SelectionListener<ComponentEvent>() {
1276
 
1277
				public void componentSelected(ComponentEvent ce) {
1278
					//Suppression de l'adresse email
1279
					String strEmail = ce.component.getId();
1280
					LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1281
					LayoutContainer lcCourriel = (LayoutContainer) hmIdentite.get("lc-" + strEmail);
1282
					lcCourrielContainer.remove(lcCourriel);
1283
 
1284
					hmIdentite.remove("lc-" + strEmail);
1285
					hmIdentite.remove("email-" + strEmail);
1286
 
1287
						HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1288
					String strValeurCourriel = hfHiddenCourriel.getValue();
1289
					strValeurCourriel = strValeurCourriel.replace(strEmail + ";;", "");
1290
					hfHiddenCourriel.setValue(strValeurCourriel);
1291
 
1292
				}
1293
 
1294
			});
1295
 
1296
			lcCourriel.add(btnSupprimerCourriel);
1297
 
1298
 
1299
 
1300
			lcCourrielContainer.add(lcCourriel);
1301
			hmIdentite.put("email-" + strEmail, lfCourriel);
1302
 
1303
			HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1304
			String strHiddenCourrielValue = hfHiddenCourriel.getValue();
1305
			if (strHiddenCourrielValue == null) {
1306
				strHiddenCourrielValue = "";
1307
			}
1308
			hfHiddenCourriel.setRawValue(strHiddenCourrielValue + strEmail + ";;");
1309
 
1310
 
1311
			layout();
1312
 
1313
	}
1314
 
1315
	public void ajouterUrl(String strUrl)	{
1316
 
1317
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1318
 
1319
		LayoutContainer lcUrl = new LayoutContainer();
1320
		lcUrl.setLayout(new ColumnLayout());
1321
		hmIdentite.put("lc-" + strUrl, lcUrl);
1322
 
1323
 
1324
		Text tUrl = new Text(strUrl);
1325
		hmIdentite.put("url-"+strUrl, tUrl);
1326
 
1327
		lcUrl.add(tUrl, new ColumnData(0.8));
1328
 
1329
		IconButton ibSupprimerUrl = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1330
		ibSupprimerUrl.setId(strUrl);
1331
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
130 gduche 1332
 
376 gduche 1333
			public void componentSelected(ComponentEvent ce) {
1334
 
1335
				//Suppression url
1336
				String strUrl = ce.component.getId();
1337
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1338
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1339
 
1340
				lcUrlContainer.remove(lcUrl);
1341
 
386 gduche 1342
 
1343
				HiddenField<String> hfUrl = (HiddenField<String>) hmIdentite.get("hfUrl");
1344
				String strValeurUrl = hfUrl.getValue();
1345
				strValeurUrl = strValeurUrl.replace(strUrl, "");
1346
				hfUrl.setValue(strValeurUrl);
1347
 
376 gduche 1348
			}
1349
		});
1350
 
1351
		lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
1352
		lcUrlContainer.add(lcUrl);
1353
 
386 gduche 1354
		HiddenField<String> hfUrl = (HiddenField<String>) hmIdentite.get("hfUrl");
1355
		String strValeurUrl = hfUrl.getValue();
1356
		if (strValeurUrl == null)	{
1357
			strValeurUrl = "";
1358
		}
1359
 
1360
		strValeurUrl += strUrl + ";;";
1361
		hfUrl.setValue(strValeurUrl);
1362
 
376 gduche 1363
		layout();
1364
 
1365
 
1366
 
1367
	}
1368
 
386 gduche 1369
	public void ajouterUrlLogo(String strUrl)	{
1370
 
1371
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1372
 
1373
		LayoutContainer lcUrl = new LayoutContainer();
1374
		lcUrl.setLayout(new ColumnLayout());
1375
		hmIdentite.put("lc-" + strUrl, lcUrl);
1376
 
1377
 
1378
		Text tUrl = new Text(strUrl);
1379
		hmIdentite.put("url-"+strUrl, tUrl);
1380
 
1381
		lcUrl.add(tUrl, new ColumnData(0.8));
1382
 
1383
		IconButton ibSupprimerUrl = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1384
		ibSupprimerUrl.setId(strUrl);
1385
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
1386
 
1387
			public void componentSelected(ComponentEvent ce) {
1388
 
1389
				//Suppression url
1390
				String strUrl = ce.component.getId();
1391
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1392
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1393
 
1394
				lcUrlContainer.remove(lcUrl);
1395
 
1396
 
1397
				HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1398
				String strValeurUrl = hfUrlLogo.getValue();
1399
				strValeurUrl = strUrl.replace(strUrl, "");
1400
 
1401
				hfUrlLogo.setValue(strValeurUrl);
1402
 
1403
			}
1404
		});
1405
 
1406
		lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
1407
		lcUrlContainer.add(lcUrl);
1408
 
1409
		HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1410
		String strValeurUrl = hfUrlLogo.getValue();
1411
		if (strValeurUrl == null)	{
1412
			strValeurUrl = "";
1413
		}
1414
 
1415
		strValeurUrl += strUrl + ";;";
1416
 
1417
		hfUrlLogo.setValue(strValeurUrl);
1418
 
1419
 
1420
 
1421
		layout();
1422
 
1423
 
1424
 
1425
	}
1426
 
376 gduche 1427
	public void reinitialiser()	{
1428
 
1429
		mediateur.afficherPopinChargement();
1430
 
1431
 
1432
		binderPersonne(personneSauvegarde);
1433
 
1434
 
1435
		layout();
1436
 
1437
		mediateur.masquerPopinChargement();
1438
	}
1439
 
1440
 
1441
 
1442
	public void binderPersonne(Personne personne)	{
1443
 
1444
		binding = new FormBinding(this);
1445
 
1446
		personneSelectionnee = personne;
1447
		binding.autoBind();
1448
		binding.bind(personneSelectionnee);
1449
 
1450
		layout();
1451
	}
130 gduche 1452
 
376 gduche 1453
	/**
1454
	 * Enregistre les information de la personne en cours
1455
	 *
1456
	 */
1457
	public void enregistrer()	{
1458
 
1459
		LinkedList lstMessageErreur = new LinkedList<String>();
1460
 
1461
		//Préparer les données
1462
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1463
		Valeur valeur;
1464
		String strValeur = "";
1465
 
1466
		if (combo.getValue()!=null)	{
1467
			valeur = (Valeur) combo.getValue();
1468
			strValeur = valeur.getId();
1469
		}
1470
 
1471
		if (!strValeur.trim().equals(""))	{
1472
			personneSelectionnee.set("sexe", strValeur);
1473
		} else {
1474
			lstMessageErreur.add("Le champ Sexe n'a pas été renseigné");
1475
		}
1476
 
1477
		strValeur = obtenirValeurCombo("cbPrefixe");
1478
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1479
 
1480
		strValeur = obtenirValeurCombo("cbSuffixe");
1481
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1482
 
1483
		personneSelectionnee.set("truk_courriel", ((HiddenField<String>) hmIdentite.get("hfHiddenCourriel")).getValue());
1484
 
386 gduche 1485
 
1486
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1487
		String strPrefixe = "";
1488
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1489
		valeur = (Valeur) combo.getValue();
1490
		if (valeur != null)	{
1491
			strPrefixe = valeur.getNom();
1492
		} else {
1493
			strPrefixe = combo.getRawValue();
1494
		}
1495
 
1496
		String strSuffixe = "";
1497
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1498
		valeur = (Valeur) combo.getValue();
1499
		if (valeur != null)	{
1500
			strSuffixe = valeur.getNom();
1501
		} else {
1502
			strSuffixe = combo.getRawValue();
1503
		}
1504
		strValeur = strPrefixe
376 gduche 1505
					+ " " + personneSelectionnee.get("prenom")
1506
					+ " " + personneSelectionnee.get("nom")
386 gduche 1507
					+ " " + strSuffixe;
376 gduche 1508
 
1509
		personneSelectionnee.set("fmt_nom_complet", strValeur);
1510
 
1511
		personneSelectionnee.set("naissance_date", (Date) ((DateField) hmIdentite.get("dfDateNaissance")).getValue());
1512
 
1513
 
1514
		strValeur = obtenirValeurCombo("cbPays");
1515
		personneSelectionnee.set("pays", strValeur);
1516
 
1517
		strValeur = obtenirValeurCombo("cbRegion");
1518
		personneSelectionnee.set("region", strValeur);
1519
 
1520
		personneSelectionnee.set("truk_telephone", ((HiddenField<String>) hmIdentite.get("hfTelephone")).getValue());
1521
 
386 gduche 1522
		String logoUrls = ((HiddenField<String>) hmIdentite.get("hfUrlLogo")).getValue();
1523
		if (logoUrls == null)	{
1524
			logoUrls = "";
1525
		}
1526
		personneSelectionnee.set("truk_logo", logoUrls);
376 gduche 1527
 
386 gduche 1528
		personneSelectionnee.set("truk_url", ((HiddenField) hmIdentite.get("hfUrl")).getValue());
376 gduche 1529
 
386 gduche 1530
		//if (lstMessageErreur.size() < 0)	{
1531
			mediateur.enregistrerPersonne(this, personneSelectionnee);
1532
		/*} else {
1533
			String strMessagesErreur = "";
1534
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1535
			while (itMessagesErreur.hasNext())	{
1536
				strMessagesErreur += " - " + itMessagesErreur.next() +" \n";
1537
			}
1538
 
1539
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
1540
		}*/
376 gduche 1541
	}
1542
 
1543
	private String obtenirValeurCombo(String strComboName)	{
1544
 
1545
		String strValeur = "";
1546
		Valeur valeur;
1547
 
1548
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1549
		if (combo == null)	{
1550
			combo = (ComboBox) hmAdresse.get(strComboName);
1551
		}
1552
		if (combo.getValue()!=null)	{
1553
			valeur = (Valeur) combo.getValue();
1554
			strValeur = valeur.getId();
1555
		} else {
1556
			strValeur = combo.getRawValue();
1557
		}
1558
 
1559
		return strValeur;
1560
	}
127 gduche 1561
}