Subversion Repositories eFlore/Applications.coel

Rev

Rev 376 | Rev 433 | 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
 
386 gduche 917
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été enregistrées");
918
				//Passer en mode modifier
376 gduche 919
 
386 gduche 920
			} else if (info.getType().equals("suppression_personne"))	{
921
				GWT.log(info.toString(), null);
922
				Info.display("lk", info.getMessages().toString());
923
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
924
 
925
 
926
					Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
927
					Iterator itPersonneListe = colPersonneListe.iterator();
928
					Personne personne = (Personne) itPersonneListe.next();
376 gduche 929
 
386 gduche 930
					personneSauvegarde = new Personne();
931
					personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
376 gduche 932
 
386 gduche 933
					binderPersonne(personne);
934
					//Mise à jour de la personne
935
					//Personne personne = (Personne) nouvellesDonnees;
936
 
937
 
938
 
939
					//Prefixe
940
					String prefixe = personne.get("ce_truk_prefix");
941
					ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
942
 
943
 
944
					String prefixeCourant = personne.get("ce_truk_prefix");
945
					if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
946
						cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
947
					}	else	{
948
						cbPrefixe.setRawValue(prefixeCourant);
376 gduche 949
					}
950
 
951
 
386 gduche 952
					((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
953
					((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
954
 
955
					//Suffixe
956
					String suffixe = personne.get("ce_truk_suffixe");
957
					ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
958
 
959
					String suffixeCourant = personne.get("ce_truk_suffix");
960
					if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
961
						cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
962
					}	else	{
963
						cbSuffixe.setRawValue(suffixeCourant);
964
					}
965
 
966
					((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
967
					((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
968
					((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
969
 
970
 
971
					(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
972
					((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
973
 
974
					(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
975
					((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
976
 
977
					// Telephone
978
					HashMap<String, String> hmTelephone = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
979
					if (hmTelephone!=null)	{
980
 
981
 
982
						ListStore storeTelephone = ((ComboBox) hmIdentite.get("cbTelephone")).getStore();
983
						List lstModelsTelephone = storeTelephone.getModels();
984
						Iterator<Valeur> itStore = lstModelsTelephone.iterator();
985
						HashMap<String, String> hmTel = new HashMap();
986
						while (itStore.hasNext())	{
987
							Valeur v = itStore.next();
988
							hmTel.put(v.getAbreviation(), v.getNom());
376 gduche 989
						}
990
 
386 gduche 991
 
992
						Collection<String> colTelephone = hmTelephone.keySet();
993
						Iterator<String> itTelephone = colTelephone.iterator();
994
 
995
						while (itTelephone.hasNext())	{
996
							String strTypeTelephone = itTelephone.next();
997
							String strTelephone = hmTelephone.get(strTypeTelephone);
998
							String idTel = hmTel.get(strTypeTelephone);
999
							if (idTel == null)	{
1000
								idTel = strTypeTelephone;
1001
							}
1002
 
1003
							ajouterTelephone(strTelephone, idTel, strTypeTelephone);
1004
						}
376 gduche 1005
					}
352 gduche 1006
 
386 gduche 1007
					//Courriel
1008
					LinkedList<String> lCourriels = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
1009
					Iterator<String> itCourriels = lCourriels.iterator();
1010
 
1011
					while (itCourriels.hasNext())	{
1012
						String strEmail = itCourriels.next();
1013
						ajouterCourriel(strEmail);
1014
					}
1015
 
1016
					// Sites
1017
					LinkedList<String> lUrl = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_url");
1018
					Iterator<String> itUrl = lUrl.iterator();
1019
 
1020
 
1021
					while (itUrl.hasNext())	{
1022
						String strUrl = itUrl.next();
1023
						ajouterUrl(strUrl);
1024
					}
1025
 
1026
					// Sexe
1027
					String strSexe = personne.get("ce_sexe");
1028
					ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
1029
 
1030
 
1031
					//FIXME : le lien avec la bdd ne peut pas se faire
1032
					if (cbSexe.getStore().findModel("abreviation", strSexe) != null)	{
1033
						cbSexe.setValue(cbSexe.getStore().findModel("abreviation", strSexe));
352 gduche 1034
					}	else	{
386 gduche 1035
						cbSexe.setRawValue(strSexe);
352 gduche 1036
					}
386 gduche 1037
 
1038
					((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
1039
 
1040
					// Logos
1041
					TextArea taLogo = (TextArea) hmIdentite.get("taLogo");
1042
					LinkedList<String> lLogo = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");
1043
					Iterator<String> itLogo = lLogo.iterator();
1044
 
1045
					String strValeurLogo = "";
1046
					while (itLogo.hasNext())	{
1047
						strValeurLogo += itLogo.next() + "\n";
1048
					}
1049
 
1050
					if (!strValeurLogo.trim().equals(""))	{
1051
						taLogo.setRawValue(strValeurLogo);
1052
					}
1053
 
1054
 
1055
					/*--------------------------------------------------
1056
					                      Adresse
1057
					 ---------------------------------------------------*/
1058
 
1059
					// Adresse
1060
					((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
1061
 
1062
					// Complément
1063
					((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
1064
 
1065
					//Boite postale
1066
					((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
1067
 
1068
					//Pays
1069
					String strPays = personne.get("pays");
1070
					ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
1071
 
1072
 
1073
					if (cbPays.getStore().findModel("nom", strPays) != null)	{
1074
						cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
1075
					}	else	{
1076
						cbPays.setRawValue(strPays);
1077
					}
1078
 
1079
 
1080
					//Région
1081
					String strRegion = personne.get("region");
1082
					if ((strRegion!=null)&&(!strRegion.equals("")))	{
1083
						ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
1084
						cbRegion.setVisible(true);
1085
 
1086
						if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
1087
							cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
1088
						}	else	{
1089
							cbRegion.setRawValue(strRegion);
1090
						}
1091
					}
1092
 
1093
					//Cp
1094
					((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
1095
 
1096
					//Ville
1097
					((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
1098
 
1099
 
1100
				} else {
1101
					Info.display("messages", info.getMessages().toString());
352 gduche 1102
				}
293 gduche 1103
		}
283 gduche 1104
 
1105
		if (nouvellesDonnees == null)
1106
		{
319 gduche 1107
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 1108
 
1109
			//Met à jour le nom Complet du formulaire
283 gduche 1110
			String valeurRetour = "";
1111
 
1112
			// Prefixe
1113
			String prefixe = "";
319 gduche 1114
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 1115
 
1116
			if (valPrefixe != null)	{
1117
				prefixe = valPrefixe.getNom();
293 gduche 1118
			} else 	{
319 gduche 1119
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 1120
			}
283 gduche 1121
 
293 gduche 1122
 
283 gduche 1123
			// Prénom
1124
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
1125
 
1126
			// Nom
1127
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
1128
 
1129
			// Suffixe
1130
			String suffixe = "";
1131
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
1132
 
1133
			if (valSuffixe != null)	{
1134
				suffixe = valSuffixe.getNom();
293 gduche 1135
			} else 	{
1136
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 1137
			}
1138
 
1139
			// Mettre à jour la valeur
1140
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
1141
			valeurRetour = valeurRetour.replaceAll("null", "");
1142
 
1143
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
1144
 
1145
			if (!valeurRetour.trim().equals(""))	{
1146
				((LabelField) hmIdentite.get("nomComplet")).show();
1147
			} else {
1148
				((LabelField) hmIdentite.get("nomComplet")).hide();
1149
			}
1150
		}
338 gduche 1151
 
1152
		mediateur.masquerPopinChargement();
127 gduche 1153
	}
1154
 
352 gduche 1155
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
293 gduche 1156
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
352 gduche 1157
 
293 gduche 1158
		HashMap hm = null;
1159
		if (hashMapId.equals("hmIdentite"))	{
1160
			hm = hmIdentite;
1161
		} else if (hashMapId.equals("hmAdresse")){
1162
			hm = hmAdresse;
1163
		} else {
1164
			hm = hmInfosNat;
1165
		}
1166
 
1167
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1168
 
293 gduche 1169
		store.removeAll();
1170
		store.add(liste);
1171
		((ComboBox) hm.get(idComboBox)).setStore(store);
376 gduche 1172
 
293 gduche 1173
	}
130 gduche 1174
 
352 gduche 1175
 
376 gduche 1176
	public void ajouterTelephone(String strTelephone, String strValeurTypeTel, String idTel) 	{
352 gduche 1177
 
1178
 
1179
				//Ajout d'un champ à la liste
376 gduche 1180
				String strIdTelephone =  idTel + "##" + strTelephone + ";;";
352 gduche 1181
 
1182
				FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1183
 
356 gduche 1184
				LayoutContainer lcTelephone = new LayoutContainer();
1185
				lcTelephone.setLayout(new ColumnLayout());
1186
 
352 gduche 1187
				Text tTypeTelephone = new Text();
1188
				tTypeTelephone.setText(strValeurTypeTel+":");
1189
 
376 gduche 1190
				hmIdentite.put("type-" + strIdTelephone, tTypeTelephone);
356 gduche 1191
				lcTelephone.add(tTypeTelephone, new ColumnData(0.40));
352 gduche 1192
 
1193
				Text tTelephone = new Text();
1194
				tTelephone.setText(strTelephone);
376 gduche 1195
				hmIdentite.put("tel-" + strIdTelephone, tTelephone);
356 gduche 1196
				lcTelephone.add(tTelephone, new ColumnData(0.40));
352 gduche 1197
 
1198
				IconButton bSupprimer = new IconButton(ComposantClass.ICONE_SUPPRIMER);
376 gduche 1199
				bSupprimer.setId(strIdTelephone);
352 gduche 1200
 
1201
				bSupprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
1202
						public void componentSelected(ComponentEvent ce) {
1203
 
376 gduche 1204
							String strIdTelephone = ce.component.getId();
1205
							LayoutContainer lcContactTel = (LayoutContainer) hmIdentite.get("lc-"+strIdTelephone);
352 gduche 1206
 
376 gduche 1207
							lcContactTel.remove(hmIdentite.get("type-" + strIdTelephone));
1208
							hmIdentite.remove("type-" + strIdTelephone);
352 gduche 1209
 
376 gduche 1210
							lcContactTel.remove(hmIdentite.get("tel-" + strIdTelephone));
1211
							hmIdentite.remove("tel-" + strIdTelephone);
352 gduche 1212
 
356 gduche 1213
							lcContactTel.remove(ce.component);
352 gduche 1214
 
356 gduche 1215
							FieldSet fsContactTel = (FieldSet) hmIdentite.get("fsContactTel");
1216
							fsContactTel.remove(lcContactTel);
1217
 
376 gduche 1218
							HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1219
							String strValeurTelephone = hfTelephone.getValue();
1220
							strValeurTelephone = strValeurTelephone.replace(strIdTelephone, "");
1221
							hfTelephone.setValue(strValeurTelephone);
1222
 
352 gduche 1223
							layout();
1224
 
1225
						}
1226
				});
1227
 
356 gduche 1228
				lcTelephone.add(bSupprimer, new ColumnData(0.15));
352 gduche 1229
 
376 gduche 1230
				hmIdentite.put("lc-"+strIdTelephone, lcTelephone);
356 gduche 1231
				fsContactTel.add(lcTelephone);
1232
 
376 gduche 1233
				HiddenField<String> hfTelephone = (HiddenField) hmIdentite.get("hfTelephone");
1234
				String strValeurTelephone = hfTelephone.getValue();
1235
				if (strValeurTelephone==null)	{
1236
					strValeurTelephone = "";
1237
				}
1238
				strValeurTelephone += strIdTelephone;
1239
				hfTelephone.setValue(strValeurTelephone);
352 gduche 1240
 
1241
				layout();
1242
 
1243
 
1244
 
1245
 
1246
	}
1247
 
376 gduche 1248
	public void ajouterCourriel(String strEmail)	{
1249
 
1250
			TextField<String> tfCourriel = (TextField<String>) hmIdentite.get("tfCourriel");
1251
			tfCourriel.setValue("");
1252
 
1253
			//Ajouter adresse email
1254
			LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1255
 
1256
			LayoutContainer lcCourriel = new LayoutContainer();
1257
			lcCourriel.setLayout(new ColumnLayout());
1258
 
1259
			LabelField lfCourriel = new LabelField();
1260
			lfCourriel.setText(strEmail);
1261
 
1262
			lcCourriel.add(lfCourriel, new ColumnData(0.8));
1263
			hmIdentite.put("lc-" + strEmail, lcCourriel);
1264
 
1265
			//Bouton supprimer
1266
			IconButton btnSupprimerCourriel = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1267
			btnSupprimerCourriel.setId(strEmail);
1268
			btnSupprimerCourriel.addSelectionListener(new SelectionListener<ComponentEvent>() {
1269
 
1270
				public void componentSelected(ComponentEvent ce) {
1271
					//Suppression de l'adresse email
1272
					String strEmail = ce.component.getId();
1273
					LayoutContainer lcCourrielContainer = (LayoutContainer) hmIdentite.get("lcCourrielContainer");
1274
					LayoutContainer lcCourriel = (LayoutContainer) hmIdentite.get("lc-" + strEmail);
1275
					lcCourrielContainer.remove(lcCourriel);
1276
 
1277
					hmIdentite.remove("lc-" + strEmail);
1278
					hmIdentite.remove("email-" + strEmail);
1279
 
1280
						HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1281
					String strValeurCourriel = hfHiddenCourriel.getValue();
1282
					strValeurCourriel = strValeurCourriel.replace(strEmail + ";;", "");
1283
					hfHiddenCourriel.setValue(strValeurCourriel);
1284
 
1285
				}
1286
 
1287
			});
1288
 
1289
			lcCourriel.add(btnSupprimerCourriel);
1290
 
1291
 
1292
 
1293
			lcCourrielContainer.add(lcCourriel);
1294
			hmIdentite.put("email-" + strEmail, lfCourriel);
1295
 
1296
			HiddenField<String> hfHiddenCourriel = (HiddenField) hmIdentite.get("hfHiddenCourriel");
1297
			String strHiddenCourrielValue = hfHiddenCourriel.getValue();
1298
			if (strHiddenCourrielValue == null) {
1299
				strHiddenCourrielValue = "";
1300
			}
1301
			hfHiddenCourriel.setRawValue(strHiddenCourrielValue + strEmail + ";;");
1302
 
1303
 
1304
			layout();
1305
 
1306
	}
1307
 
1308
	public void ajouterUrl(String strUrl)	{
1309
 
1310
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1311
 
1312
		LayoutContainer lcUrl = new LayoutContainer();
1313
		lcUrl.setLayout(new ColumnLayout());
1314
		hmIdentite.put("lc-" + strUrl, lcUrl);
1315
 
1316
 
1317
		Text tUrl = new Text(strUrl);
1318
		hmIdentite.put("url-"+strUrl, tUrl);
1319
 
1320
		lcUrl.add(tUrl, new ColumnData(0.8));
1321
 
1322
		IconButton ibSupprimerUrl = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1323
		ibSupprimerUrl.setId(strUrl);
1324
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
130 gduche 1325
 
376 gduche 1326
			public void componentSelected(ComponentEvent ce) {
1327
 
1328
				//Suppression url
1329
				String strUrl = ce.component.getId();
1330
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1331
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcUrlContainer");
1332
 
1333
				lcUrlContainer.remove(lcUrl);
1334
 
386 gduche 1335
 
1336
				HiddenField<String> hfUrl = (HiddenField<String>) hmIdentite.get("hfUrl");
1337
				String strValeurUrl = hfUrl.getValue();
1338
				strValeurUrl = strValeurUrl.replace(strUrl, "");
1339
				hfUrl.setValue(strValeurUrl);
1340
 
376 gduche 1341
			}
1342
		});
1343
 
1344
		lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
1345
		lcUrlContainer.add(lcUrl);
1346
 
386 gduche 1347
		HiddenField<String> hfUrl = (HiddenField<String>) hmIdentite.get("hfUrl");
1348
		String strValeurUrl = hfUrl.getValue();
1349
		if (strValeurUrl == null)	{
1350
			strValeurUrl = "";
1351
		}
1352
 
1353
		strValeurUrl += strUrl + ";;";
1354
		hfUrl.setValue(strValeurUrl);
1355
 
376 gduche 1356
		layout();
1357
 
1358
 
1359
 
1360
	}
1361
 
386 gduche 1362
	public void ajouterUrlLogo(String strUrl)	{
1363
 
1364
		LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1365
 
1366
		LayoutContainer lcUrl = new LayoutContainer();
1367
		lcUrl.setLayout(new ColumnLayout());
1368
		hmIdentite.put("lc-" + strUrl, lcUrl);
1369
 
1370
 
1371
		Text tUrl = new Text(strUrl);
1372
		hmIdentite.put("url-"+strUrl, tUrl);
1373
 
1374
		lcUrl.add(tUrl, new ColumnData(0.8));
1375
 
1376
		IconButton ibSupprimerUrl = new IconButton(ComposantClass.ICONE_SUPPRIMER);
1377
		ibSupprimerUrl.setId(strUrl);
1378
		ibSupprimerUrl.addSelectionListener(new SelectionListener<ComponentEvent>() {
1379
 
1380
			public void componentSelected(ComponentEvent ce) {
1381
 
1382
				//Suppression url
1383
				String strUrl = ce.component.getId();
1384
				LayoutContainer lcUrl = (LayoutContainer) hmIdentite.get("lc-" + strUrl);
1385
				LayoutContainer lcUrlContainer  = (LayoutContainer) hmIdentite.get("lcAutreInformations2");
1386
 
1387
				lcUrlContainer.remove(lcUrl);
1388
 
1389
 
1390
				HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1391
				String strValeurUrl = hfUrlLogo.getValue();
1392
				strValeurUrl = strUrl.replace(strUrl, "");
1393
 
1394
				hfUrlLogo.setValue(strValeurUrl);
1395
 
1396
			}
1397
		});
1398
 
1399
		lcUrl.add(ibSupprimerUrl, new ColumnData(0.15));
1400
		lcUrlContainer.add(lcUrl);
1401
 
1402
		HiddenField<String> hfUrlLogo = (HiddenField<String>) hmIdentite.get("hfUrlLogo");
1403
		String strValeurUrl = hfUrlLogo.getValue();
1404
		if (strValeurUrl == null)	{
1405
			strValeurUrl = "";
1406
		}
1407
 
1408
		strValeurUrl += strUrl + ";;";
1409
 
1410
		hfUrlLogo.setValue(strValeurUrl);
1411
 
1412
 
1413
 
1414
		layout();
1415
 
1416
 
1417
 
1418
	}
1419
 
376 gduche 1420
	public void reinitialiser()	{
1421
 
1422
		mediateur.afficherPopinChargement();
1423
 
1424
 
1425
		binderPersonne(personneSauvegarde);
1426
 
1427
 
1428
		layout();
1429
 
1430
		mediateur.masquerPopinChargement();
1431
	}
1432
 
1433
 
1434
 
1435
	public void binderPersonne(Personne personne)	{
1436
 
1437
		binding = new FormBinding(this);
1438
 
1439
		personneSelectionnee = personne;
1440
		binding.autoBind();
1441
		binding.bind(personneSelectionnee);
1442
 
1443
		layout();
1444
	}
130 gduche 1445
 
376 gduche 1446
	/**
1447
	 * Enregistre les information de la personne en cours
1448
	 *
1449
	 */
1450
	public void enregistrer()	{
1451
 
1452
		LinkedList lstMessageErreur = new LinkedList<String>();
1453
 
1454
		//Préparer les données
1455
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1456
		Valeur valeur;
1457
		String strValeur = "";
1458
 
1459
		if (combo.getValue()!=null)	{
1460
			valeur = (Valeur) combo.getValue();
1461
			strValeur = valeur.getId();
1462
		}
1463
 
1464
		if (!strValeur.trim().equals(""))	{
1465
			personneSelectionnee.set("sexe", strValeur);
1466
		} else {
1467
			lstMessageErreur.add("Le champ Sexe n'a pas été renseigné");
1468
		}
1469
 
1470
		strValeur = obtenirValeurCombo("cbPrefixe");
1471
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1472
 
1473
		strValeur = obtenirValeurCombo("cbSuffixe");
1474
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1475
 
1476
		personneSelectionnee.set("truk_courriel", ((HiddenField<String>) hmIdentite.get("hfHiddenCourriel")).getValue());
1477
 
386 gduche 1478
 
1479
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1480
		String strPrefixe = "";
1481
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1482
		valeur = (Valeur) combo.getValue();
1483
		if (valeur != null)	{
1484
			strPrefixe = valeur.getNom();
1485
		} else {
1486
			strPrefixe = combo.getRawValue();
1487
		}
1488
 
1489
		String strSuffixe = "";
1490
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1491
		valeur = (Valeur) combo.getValue();
1492
		if (valeur != null)	{
1493
			strSuffixe = valeur.getNom();
1494
		} else {
1495
			strSuffixe = combo.getRawValue();
1496
		}
1497
		strValeur = strPrefixe
376 gduche 1498
					+ " " + personneSelectionnee.get("prenom")
1499
					+ " " + personneSelectionnee.get("nom")
386 gduche 1500
					+ " " + strSuffixe;
376 gduche 1501
 
1502
		personneSelectionnee.set("fmt_nom_complet", strValeur);
1503
 
1504
		personneSelectionnee.set("naissance_date", (Date) ((DateField) hmIdentite.get("dfDateNaissance")).getValue());
1505
 
1506
 
1507
		strValeur = obtenirValeurCombo("cbPays");
1508
		personneSelectionnee.set("pays", strValeur);
1509
 
1510
		strValeur = obtenirValeurCombo("cbRegion");
1511
		personneSelectionnee.set("region", strValeur);
1512
 
1513
		personneSelectionnee.set("truk_telephone", ((HiddenField<String>) hmIdentite.get("hfTelephone")).getValue());
1514
 
386 gduche 1515
		String logoUrls = ((HiddenField<String>) hmIdentite.get("hfUrlLogo")).getValue();
1516
		if (logoUrls == null)	{
1517
			logoUrls = "";
1518
		}
1519
		personneSelectionnee.set("truk_logo", logoUrls);
376 gduche 1520
 
386 gduche 1521
		personneSelectionnee.set("truk_url", ((HiddenField) hmIdentite.get("hfUrl")).getValue());
376 gduche 1522
 
386 gduche 1523
		//if (lstMessageErreur.size() < 0)	{
1524
			mediateur.enregistrerPersonne(this, personneSelectionnee);
1525
		/*} else {
1526
			String strMessagesErreur = "";
1527
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1528
			while (itMessagesErreur.hasNext())	{
1529
				strMessagesErreur += " - " + itMessagesErreur.next() +" \n";
1530
			}
1531
 
1532
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
1533
		}*/
376 gduche 1534
	}
1535
 
1536
	private String obtenirValeurCombo(String strComboName)	{
1537
 
1538
		String strValeur = "";
1539
		Valeur valeur;
1540
 
1541
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1542
		if (combo == null)	{
1543
			combo = (ComboBox) hmAdresse.get(strComboName);
1544
		}
1545
		if (combo.getValue()!=null)	{
1546
			valeur = (Valeur) combo.getValue();
1547
			strValeur = valeur.getId();
1548
		} else {
1549
			strValeur = combo.getRawValue();
1550
		}
1551
 
1552
		return strValeur;
1553
	}
127 gduche 1554
}