Subversion Repositories eFlore/Applications.coel

Rev

Rev 731 | Rev 821 | 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;
692 gduche 14
import org.tela_botanica.client.composants.ChampMultiValeurs;
701 gduche 15
import org.tela_botanica.client.composants.ChampMultiValeursImage;
722 gduche 16
import org.tela_botanica.client.composants.ChampMultiValeursMultiTypes;
519 gduche 17
import org.tela_botanica.client.images.Images;
127 gduche 18
import org.tela_botanica.client.interfaces.Rafraichissable;
283 gduche 19
import org.tela_botanica.client.modeles.Configuration;
293 gduche 20
 
352 gduche 21
import org.tela_botanica.client.modeles.Information;
286 gduche 22
import org.tela_botanica.client.modeles.Personne;
352 gduche 23
import org.tela_botanica.client.modeles.PersonneListe;
456 gduche 24
import org.tela_botanica.client.modeles.Projet;
25
import org.tela_botanica.client.modeles.ProjetListe;
668 gduche 26
import org.tela_botanica.client.modeles.Utilisateur;
280 gduche 27
import org.tela_botanica.client.modeles.Valeur;
283 gduche 28
import org.tela_botanica.client.modeles.ValeurListe;
729 jp_milcent 29
import org.tela_botanica.client.util.Pattern;
622 gduche 30
import org.tela_botanica.client.util.UtilString;
127 gduche 31
 
488 gduche 32
import com.extjs.gxt.ui.client.event.Events;
276 gduche 33
import com.extjs.gxt.ui.client.Registry;
34
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
519 gduche 35
import com.extjs.gxt.ui.client.Style.IconAlign;
283 gduche 36
import com.extjs.gxt.ui.client.Style.Scroll;
386 gduche 37
 
376 gduche 38
import com.extjs.gxt.ui.client.binding.FormBinding;
386 gduche 39
 
488 gduche 40
import com.extjs.gxt.ui.client.event.ButtonEvent;
276 gduche 41
import com.extjs.gxt.ui.client.event.ComponentEvent;
42
import com.extjs.gxt.ui.client.event.KeyListener;
446 gduche 43
import com.extjs.gxt.ui.client.event.Listener;
280 gduche 44
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
45
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 46
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 47
import com.extjs.gxt.ui.client.store.ListStore;
127 gduche 48
import com.extjs.gxt.ui.client.widget.LayoutContainer;
319 gduche 49
import com.extjs.gxt.ui.client.widget.MessageBox;
338 gduche 50
 
386 gduche 51
import com.extjs.gxt.ui.client.widget.Info;
276 gduche 52
import com.extjs.gxt.ui.client.widget.TabItem;
53
import com.extjs.gxt.ui.client.widget.TabPanel;
283 gduche 54
 
356 gduche 55
import com.extjs.gxt.ui.client.widget.button.Button;
56
import com.extjs.gxt.ui.client.widget.button.ButtonBar;
280 gduche 57
import com.extjs.gxt.ui.client.widget.form.ComboBox;
58
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 59
import com.extjs.gxt.ui.client.widget.form.FieldSet;
352 gduche 60
import com.extjs.gxt.ui.client.widget.form.FormPanel;
276 gduche 61
import com.extjs.gxt.ui.client.widget.form.LabelField;
446 gduche 62
import com.extjs.gxt.ui.client.widget.form.Radio;
63
import com.extjs.gxt.ui.client.widget.form.RadioGroup;
286 gduche 64
import com.extjs.gxt.ui.client.widget.form.TextArea;
276 gduche 65
import com.extjs.gxt.ui.client.widget.form.TextField;
456 gduche 66
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
276 gduche 67
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
68
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
69
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
319 gduche 70
import com.extjs.gxt.ui.client.widget.layout.FormData;
276 gduche 71
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
356 gduche 72
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
276 gduche 73
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
386 gduche 74
import com.google.gwt.core.client.GWT;
339 gduche 75
import com.google.gwt.i18n.client.DateTimeFormat;
276 gduche 76
import com.google.gwt.user.client.ui.Widget;
127 gduche 77
 
446 gduche 78
public class PersonneForm extends FormPanel implements Rafraichissable {
127 gduche 79
 
730 jp_milcent 80
	// VARIABLES
276 gduche 81
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
283 gduche 82
	private Mediateur mediateur = Registry.get(RegistreId.MEDIATEUR);
83
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
376 gduche 84
	private Personne personneSelectionnee, personneSauvegarde = null;
456 gduche 85
	private String mode = "";
276 gduche 86
 
657 gduche 87
	//hmIdentite[...] référence par une chaine de caractère tous les composants de l'onglet Identite
88
	private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();
89
	private HashMap<String, Widget>hmAdresse = new HashMap<String, Widget>();
90
	private HashMap<String, Widget>hmInfosNat = new HashMap<String, Widget>();
730 jp_milcent 91
	private HashMap<String, Valeur> hmCbSelectionnee = new HashMap();
657 gduche 92
	private FormData fd100 = new FormData("1");
93
 
668 gduche 94
	private Button enregistrer, enregistrerEtRevenir;
95
 
456 gduche 96
	public static final String MODE_AJOUTER = "AJOUT";
97
	public static final String MODE_MODIFIER = "MODIF";
730 jp_milcent 98
 
376 gduche 99
	private FormBinding binding = null;
100
 
730 jp_milcent 101
	// CONSTRUCTEUR
446 gduche 102
 
456 gduche 103
	public PersonneForm(String mode) {
104
		this.mode = mode;
386 gduche 105
		initialiserComposants();
352 gduche 106
	}
107
 
386 gduche 108
	public void initialiserComposants()	{
376 gduche 109
		personneSelectionnee = new Personne();
110
		personneSauvegarde = new Personne();
111
 
283 gduche 112
		initialiserPanneau();
276 gduche 113
 
356 gduche 114
		ButtonBar barreOutilsBas = new ButtonBar();
488 gduche 115
		//barreOutilsBas.setButtonAlign(HorizontalAlignment.CENTER);
116
		barreOutilsBas.setAlignment(HorizontalAlignment.CENTER);
276 gduche 117
 
352 gduche 118
		ajouterBoutonEnregistrer(barreOutilsBas);
119
		ajouterBoutonEnregistrerEtRevenir(barreOutilsBas);
120
		ajouterBoutonAnnuler(barreOutilsBas);
668 gduche 121
		gererEtatActivationBouton();
276 gduche 122
 
352 gduche 123
		setBottomComponent(barreOutilsBas);
276 gduche 124
 
352 gduche 125
		ToolBar barreOutilsHaut = new ToolBar();
126
		ajouterBoutonReinitialiser(barreOutilsHaut);
127
		setTopComponent(barreOutilsHaut);
338 gduche 128
 
276 gduche 129
		initialiserOnglets();
130
 
131
		creerComposantsIdentite();
293 gduche 132
		creerComposantsAdresse();
280 gduche 133
 
352 gduche 134
		layout();
338 gduche 135
 
376 gduche 136
		binderPersonne(personneSelectionnee);
276 gduche 137
	}
138
 
730 jp_milcent 139
	// SOUS-METHODES
140
 
283 gduche 141
	public void initialiserPanneau()	{
142
		setCollapsible(false);
461 gduche 143
		if (this.mode.equals(MODE_AJOUTER))	{
144
			setHeading(mediateur.i18nC.personneModeAjout());
519 gduche 145
			setIcon(Images.ICONES.ajouter());
461 gduche 146
		} else 	{
147
			setHeading(mediateur.i18nC.personneModeModifier());
519 gduche 148
			setIcon(Images.ICONES.formModifier());
461 gduche 149
		}
283 gduche 150
		setButtonAlign(HorizontalAlignment.CENTER);
386 gduche 151
		setLayout(new FitLayout());
376 gduche 152
		setBodyBorder(false);
153
		setBorders(false);
154
		setPadding(0);
155
		setWidth("100%");
446 gduche 156
 
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
 
167
		//Tab 1 : identite
461 gduche 168
		tiIdentite = new TabItem(mediateur.i18nC.personneIdentite());
276 gduche 169
		tiIdentite.setLayout(new FormLayout());
283 gduche 170
		tiIdentite.setScrollMode(Scroll.AUTO);
446 gduche 171
 
276 gduche 172
		formulaireOnglets.add(tiIdentite);
293 gduche 173
		hmIdentite.put("tiIdentite", tiIdentite);
276 gduche 174
 
175
		//Tab 2 : Adresse
461 gduche 176
		tiAdresses = new TabItem(mediateur.i18nC.adresse());
304 gduche 177
		tiAdresses.setLayout(new FormLayout());
283 gduche 178
		tiAdresses.setScrollMode(Scroll.AUTO);
446 gduche 179
 
276 gduche 180
		formulaireOnglets.add(tiAdresses);
181
 
182
		//Tab 3 : Infos Naturalistes
461 gduche 183
		tiInfosNat = new TabItem(mediateur.i18nC.personneInfoNat());
276 gduche 184
		tiInfosNat.setLayout(new FormLayout());
283 gduche 185
		tiInfosNat.setScrollMode(Scroll.AUTO);
446 gduche 186
 
276 gduche 187
		formulaireOnglets.add(tiInfosNat);
188
		add(formulaireOnglets);
189
	}
190
 
191
	/**
192
	 * Crée les widgets pour l'onglet identité
193
	 *
194
	 * */
195
 
196
 
197
	public void creerComposantsIdentite()	{
676 gduche 198
		// Gestion de l'affichage en colonnes : 3 Layout container : principal, gauche & droite
199
		LayoutContainer left = new LayoutContainer();
200
		left.setLayout(new FormLayout());
201
		LayoutContainer right = new LayoutContainer();
202
		right.setLayout(new FormLayout());
456 gduche 203
 
676 gduche 204
		LayoutContainer main = new LayoutContainer();
205
 
206
		main.add(left, new ColumnData(.45));
207
		main.add(right, new ColumnData(.45));
208
 
209
		main.setLayout(new ColumnLayout());
210
		main.setHeight("100%");
211
		main.setScrollMode(Scroll.AUTO);
212
 
213
		// Création des champs
214
		FormLayout formLayout = new FormLayout();
215
		formLayout.setLabelAlign(LabelAlign.LEFT);
216
 
217
		FieldSet fsProjet = new FieldSet();
218
		fsProjet.setHeading(mediateur.i18nC.menuProjet());
219
		fsProjet.setLayout(new FormLayout());
220
 
221
		ListStore<Projet> storeProjets = new ListStore<Projet>();
222
		ComboBox cbProjets = new ComboBox<Projet>();
223
		cbProjets.setFieldLabel(mediateur.i18nC.personneProjet()+ " :");
224
		cbProjets.setEmptyText(mediateur.i18nC.txtListeProjetDefaut());
225
		cbProjets.setLabelSeparator("");
226
		cbProjets.setDisplayField("nom");
227
		cbProjets.setEditable(false);
228
		cbProjets.setTriggerAction(TriggerAction.ALL);
229
		cbProjets.setStore(storeProjets);
230
		cbProjets.setAllowBlank(false);
231
		fsProjet.add(cbProjets);
232
 
233
		hmIdentite.put("cbProjets", cbProjets);
234
 
235
		mediateur.selectionnerProjets(this);
456 gduche 236
 
676 gduche 237
		left.add(fsProjet);
456 gduche 238
 
676 gduche 239
		FieldSet fsNoms = new FieldSet();
240
		fsNoms.setHeading("Noms");
241
		fsNoms.setLayout(formLayout);
456 gduche 242
 
676 gduche 243
		// Nom complet : Affiché que si valeurs saisies
244
		LabelField nomComplet = new LabelField();
245
		nomComplet.setFieldLabel(mediateur.i18nC.personneNomComplet() +" :");
246
		nomComplet.hide();
456 gduche 247
 
676 gduche 248
		fsNoms.add(nomComplet);
249
		hmIdentite.put("nomComplet", nomComplet);
276 gduche 250
 
676 gduche 251
		//Préfixe
252
		ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
253
		ComboBox<Valeur> cbPrefixe = new ComboBox<Valeur>();
254
		cbPrefixe.setStore(storePrefixe);
255
		cbPrefixe.setDisplayField("nom");
256
		cbPrefixe.setEmptyText("Choisissez le préfixe:");
257
		cbPrefixe.setFieldLabel("Prefix");
258
 
259
		fsNoms.add(cbPrefixe);
260
		hmIdentite.put("cbPrefixe", cbPrefixe);
261
 
262
		mediateur.obtenirListeValeurEtRafraichir(this, "prefixe");
263
 
264
		//Prénom
265
		TextField<String> tfPrenom = new TextField<String>();
266
		tfPrenom.setFieldLabel("Prénom");
267
		tfPrenom.setName("prenom");
268
 
269
		fsNoms.add(tfPrenom);
270
		hmIdentite.put("tfPrenom", tfPrenom);
271
 
272
		//Nom
273
		TextField<String> tfNom = new TextField<String>();
274
		tfNom.setFieldLabel("Nom");
275
		tfNom.setAllowBlank(false);
276
		tfNom.setName("nom");
277
 
278
		fsNoms.add(tfNom);
279
		hmIdentite.put("tfNom", tfNom);
280
 
281
		//Suffixe
282
		ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
283
		ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
284
		cbSuffixe.setStore(storeSuffixe);
285
		cbSuffixe.setFieldLabel("Suffixe");
286
		cbSuffixe.setDisplayField("nom");
287
		cbSuffixe.setEmptyText("Choisissez un suffixe:");
288
 
289
		fsNoms.add(cbSuffixe);
290
		hmIdentite.put("cbSuffixe", cbSuffixe);
291
 
292
		mediateur.obtenirListeValeurEtRafraichir(this, "suffixes");
293
 
730 jp_milcent 294
		TextField<String> tfNomAutre = new TextField<String>();
676 gduche 295
		tfNomAutre.setFieldLabel("Autres noms");
296
		tfNomAutre.setName("truk_nom_autre");
297
 
298
		fsNoms.add(tfNomAutre);
299
		hmIdentite.put("tfNomAutre", tfNomAutre);
300
 
301
		TextField<String> tfAbreviation = new TextField<String>();
302
		tfAbreviation.setFieldLabel("Abréviation");
303
		tfAbreviation.setName("abreviation");
304
 
305
		fsNoms.add(tfAbreviation);
306
		hmIdentite.put("tfAbreviation", tfAbreviation);
307
 
308
		//Abréviation autres
309
		TextField<String> tfAbreviationAutre = new TextField<String>();
310
		tfAbreviationAutre.setFieldLabel("Autres Abrév.");
311
		tfAbreviationAutre.setName("truk_abreviation_autre");
312
 
313
		fsNoms.add(tfAbreviationAutre);
314
		hmIdentite.put("tfAbreviationAutre", tfAbreviationAutre);
376 gduche 315
 
676 gduche 316
		left.add(fsNoms);
317
 
318
		formLayout = new FormLayout();
319
		formLayout.setLabelAlign(LabelAlign.LEFT);
320
 
321
		FieldSet fsNaissance = new FieldSet();
322
		fsNaissance.setHeading("Naissance");
323
		fsNaissance.setLayout(formLayout);
324
 
325
		DateField dfDateNaissance = new DateField();
326
		dfDateNaissance.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
327
		dfDateNaissance.setFieldLabel("Date");
328
		dfDateNaissance.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
329
 
330
		fsNaissance.add(dfDateNaissance);
331
		hmIdentite.put("dfDateNaissance", dfDateNaissance);
332
 
333
		// Lieu naissance
730 jp_milcent 334
		TextField<String> tfLieuNaissance = new TextField<String>();
676 gduche 335
		tfLieuNaissance.setFieldLabel("Lieu");
336
		tfLieuNaissance.setName("naissance_lieu");
337
 
338
		fsNaissance.add(tfLieuNaissance);
339
		hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
276 gduche 340
 
676 gduche 341
		left.add(fsNaissance);
342
 
343
		formLayout = new FormLayout();
344
		formLayout.setLabelAlign(LabelAlign.LEFT);
345
 
346
		FieldSet fsDeces = new FieldSet();
347
		fsDeces.setHeading("Décès");
348
		fsDeces.setLayout(formLayout);
276 gduche 349
 
676 gduche 350
		Radio rbEstDecedee = new Radio();
351
		rbEstDecedee.setBoxLabel("oui");
352
 
353
		rbEstDecedee.addListener(Events.Change, new Listener<ComponentEvent>() {
446 gduche 354
 
676 gduche 355
			public void handleEvent(ComponentEvent be) {
356
				if(((Radio) be.getComponent()).getValue().equals(true))	{
357
					((DateField) hmIdentite.get("dfDateDeces")).setVisible(true);
358
					((TextField) hmIdentite.get("tfLieuDeces")).setVisible(true);
359
				} else	{
360
					((DateField) hmIdentite.get("dfDateDeces")).setVisible(false);
361
					((TextField) hmIdentite.get("tfLieuDeces")).setVisible(false);
362
				}
363
			}
364
		});
446 gduche 365
 
676 gduche 366
		hmIdentite.put("rbEstDecedee", rbEstDecedee);
367
 
368
		Radio rbNestPasDecedee = new Radio();
369
		rbNestPasDecedee.setBoxLabel("non");
370
		rbNestPasDecedee.setValue(true);
371
 
372
		RadioGroup rbgDeces = new RadioGroup();
373
		rbgDeces.setFieldLabel("Est décédée");
374
		rbgDeces.add(rbEstDecedee);
375
		rbgDeces.add(rbNestPasDecedee);
376
 
377
		fsDeces.add(rbgDeces);
378
 
379
		DateField dfDateDeces = new DateField();
380
		dfDateDeces.getPropertyEditor().setFormat(DateTimeFormat.getFormat("dd/MM/yyyy"));
381
		dfDateDeces.setFormatValue(true);
382
		dfDateDeces.getMessages().setInvalidText("La valeur saisie n'est pas une date valide. La date doit être au format «jj/mm/aaaa».");
383
		dfDateDeces.setFieldLabel("Date");
384
		dfDateDeces.setVisible(false);
385
 
386
		fsDeces.add(dfDateDeces);
387
		hmIdentite.put("dfDateDeces", dfDateDeces);
388
 
730 jp_milcent 389
		TextField<String> tfLieuDeces = new TextField<String>();
676 gduche 390
		tfLieuDeces.setFieldLabel("Lieu");
391
		tfLieuDeces.setName("deces_lieu");
392
		tfLieuDeces.setVisible(false);
393
 
394
		fsDeces.add(tfLieuDeces);
395
		hmIdentite.put("tfLieuDeces", tfLieuDeces);
376 gduche 396
 
676 gduche 397
		left.add(fsDeces);
276 gduche 398
 
676 gduche 399
		tiIdentite.add(main);
283 gduche 400
 
676 gduche 401
		FieldSet fsContactTel = new FieldSet();
402
		fsContactTel.setHeading("Contact - Téléphones");
403
		fsContactTel.setLayout(new RowLayout());
404
 
722 gduche 405
 
406
		ChampMultiValeursMultiTypes telephones = new ChampMultiValeursMultiTypes("Téléphones");
407
		hmIdentite.put("telephones", telephones);
408
		telephones.initialiserType("tel", mediateur);
409
		fsContactTel.add(telephones);
676 gduche 410
		right.add(fsContactTel);
411
		hmIdentite.put("fsContactTel", fsContactTel);
376 gduche 412
 
676 gduche 413
 
414
		FieldSet fsContact = new FieldSet();
415
		fsContact.setHeading("Contact - Autres");
416
		fsContact.setId("fsContact");
417
		fsContact.setLayout(new RowLayout());
418
 
419
		right.add(fsContact);
420
		hmIdentite.put("fsContact", fsContact);
421
 
692 gduche 422
		ChampMultiValeurs courriels = new ChampMultiValeurs("Courriels");
729 jp_milcent 423
		courriels.setValidation(Pattern.email, "moi@domaine.fr");
692 gduche 424
		fsContact.add(courriels);
425
		hmIdentite.put("courriels", courriels);
676 gduche 426
 
427
		LayoutContainer lcCourrielContainer = new LayoutContainer(new RowLayout());
428
 
429
		fsContact.add(lcCourrielContainer);
430
		hmIdentite.put("lcCourrielContainer", lcCourrielContainer);
431
 
692 gduche 432
		ChampMultiValeurs sites = new ChampMultiValeurs("Sites web");
695 gduche 433
		sites.setValeurParDefaut("http://");
729 jp_milcent 434
		sites.setValidation(Pattern.url, "http://www.monsite.com");
692 gduche 435
		fsContact.add(sites);
436
		hmIdentite.put("sites", sites);
286 gduche 437
 
676 gduche 438
		FieldSet fsAutresInfos = new FieldSet();
439
		fsAutresInfos.setHeading("Autres informations");
440
 
441
		formLayout = new FormLayout();
442
		formLayout.setLabelAlign(LabelAlign.LEFT);
443
		fsAutresInfos.setLayout(formLayout);
356 gduche 444
 
386 gduche 445
 
676 gduche 446
		formLayout = new FormLayout();
447
		formLayout.setLabelAlign(LabelAlign.TOP);
448
		LayoutContainer lcAutreInformations1 = new LayoutContainer(formLayout);
449
 
450
		//Civilité
451
		ListStore<Valeur> storeSexe = new ListStore<Valeur>();
452
		ComboBox<Valeur> cbSexe = new ComboBox<Valeur>();
453
		cbSexe.setStore(storeSexe);
454
		cbSexe.setFieldLabel("Sexe");
455
		cbSexe.setDisplayField("nom");
456
		cbSexe.setEmptyText("Choisissez le sexe:");
386 gduche 457
 
676 gduche 458
		lcAutreInformations1.add(cbSexe, fd100);
459
		hmIdentite.put("cbSexe", cbSexe);
386 gduche 460
 
676 gduche 461
		mediateur.obtenirListeValeurEtRafraichir(this, "sexe");
462
 
463
		//Description
464
		TextArea taDescription = new TextArea();
465
		taDescription.setEmptyText("Saisissez une description");
466
		taDescription.setFieldLabel("Description");
467
		taDescription.setWidth("100%");
468
		taDescription.setName("description");
469
 
470
		lcAutreInformations1.add(taDescription, fd100);
471
		hmIdentite.put("taDescription", taDescription);
472
 
473
		fsAutresInfos.add(lcAutreInformations1);
474
 
475
		// Logo
689 gduche 476
		LayoutContainer lcLogoUrl = new LayoutContainer();
477
		hmIdentite.put("lcLogoUrl", lcLogoUrl);
676 gduche 478
 
701 gduche 479
		ChampMultiValeursImage logo = new ChampMultiValeursImage("Logos");
480
		logo.setImageHeight("150px");
481
		logo.setValeurParDefaut("http://");
729 jp_milcent 482
		logo.setValidation(Pattern.url, "http://www.monsite.com/mon_image.jpg");
701 gduche 483
		logo.setValeurBoutonSupprimer("Supprimer");
484
		hmIdentite.put("logos", logo);
676 gduche 485
 
701 gduche 486
		lcLogoUrl.add(logo);
676 gduche 487
 
701 gduche 488
		fsAutresInfos.add(logo);
689 gduche 489
 
490
		LayoutContainer lcAutreInformations2 = new LayoutContainer(new ColumnLayout());
491
		hmIdentite.put("lcAutreInformations2", lcAutreInformations2);
676 gduche 492
		fsAutresInfos.add(lcAutreInformations2);
386 gduche 493
 
676 gduche 494
		right.add(fsAutresInfos);
293 gduche 495
 
676 gduche 496
		// Ajout des évènements saisi
497
		KeyListener klNoms = new KeyListener()	{
498
			public void componentKeyUp(ComponentEvent ev)	{
499
				rafraichir(null);
500
			}
501
		};
502
 
503
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
504
			public void selectionChanged(SelectionChangedEvent se) {
730 jp_milcent 505
				rafraichir(null);
506
			}
676 gduche 507
		};
283 gduche 508
 
676 gduche 509
		cbPrefixe.addSelectionChangedListener(selectionChange);
510
		cbPrefixe.addKeyListener(klNoms);
511
		tfPrenom.addKeyListener(klNoms);
512
		tfNom.addKeyListener(klNoms);
513
		cbSuffixe.addSelectionChangedListener(selectionChange);
276 gduche 514
 
515
	}
516
 
293 gduche 517
	public void creerComposantsAdresse()	{
518
		// Gauche
519
		LayoutContainer left = new LayoutContainer();
520
		left.setLayout(new FormLayout());
521
 
522
		// Droite
523
		LayoutContainer right = new LayoutContainer();
524
		right.setLayout(new FormLayout());
525
 
526
		// Principal
527
		LayoutContainer main = new LayoutContainer();
528
		main.setLayout(new ColumnLayout());
529
 
530
		// Ajout au principal
531
		main.add(left, new ColumnData(.49));
532
		main.add(right, new ColumnData(.49));
533
 
534
		TextField<String> tfAdresse1 = new TextField();
535
		tfAdresse1.setFieldLabel("Adresse");
376 gduche 536
		tfAdresse1.setName("adresse_01");
319 gduche 537
		left.add(tfAdresse1, fd100);
293 gduche 538
		hmAdresse.put("tfAdresse1", tfAdresse1);
539
 
540
		TextField<String> tfAdresse2 = new TextField();
541
		tfAdresse2.setFieldLabel("Complément d'adresse");
376 gduche 542
		tfAdresse2.setName("adresse_02");
319 gduche 543
		left.add(tfAdresse2, fd100);
293 gduche 544
		hmAdresse.put("tfAdresse2", tfAdresse2);
545
 
546
		ComboBox<Valeur> cbPays = new ComboBox<Valeur>();
547
		cbPays.setFieldLabel("Pays");
548
		cbPays.setDisplayField("nom");
549
		cbPays.setEmptyText("Sélectionnez le pays:");
550
 
551
		ListStore<Valeur> storePays = new ListStore<Valeur>();
552
		cbPays.setStore(storePays);
553
 
319 gduche 554
		right.add(cbPays, fd100);
293 gduche 555
		hmAdresse.put("cbPays", cbPays);
556
 
557
		SelectionChangedListener<Valeur> selectionChange = new SelectionChangedListener<Valeur>() {
558
			public void selectionChanged(SelectionChangedEvent se) {
730 jp_milcent 559
				// Rafraichir avec le pays sélectionné
560
				obtenirListeRegionParPays(((Valeur) se.getSelectedItem()).getAbreviation().toString());
561
			}
293 gduche 562
		};
563
 
564
		cbPays.addSelectionChangedListener(selectionChange);
565
 
566
 
567
		ComboBox<Valeur> cbRegion = new ComboBox<Valeur>();
568
		cbRegion.setFieldLabel("Region");
569
		cbRegion.setDisplayField("nom");
570
		cbRegion.setEmptyText("Sélectionnez la région:");
571
		cbRegion.setVisible(false);
572
 
573
		ListStore<Valeur> storeRegion = new ListStore<Valeur>();
574
		cbRegion.setStore(storeRegion);
575
 
352 gduche 576
 
319 gduche 577
		right.add(cbRegion, fd100);
293 gduche 578
		hmAdresse.put("cbRegion", cbRegion);
579
 
580
		TextField<String> tfBoitePostale = new TextField<String>();
581
		tfBoitePostale.setFieldLabel("Boite postale");
376 gduche 582
		tfBoitePostale.setName("bp");
583
 
319 gduche 584
		left.add(tfBoitePostale, fd100);
293 gduche 585
		hmAdresse.put("tfBoitePostale", tfBoitePostale);
586
 
587
		TextField<Integer> tfCodePostal = new TextField<Integer>();
588
		tfCodePostal.setFieldLabel("Code postal");
376 gduche 589
		tfCodePostal.setName("code_postal");
590
 
319 gduche 591
		right.add(tfCodePostal, fd100);
293 gduche 592
		hmAdresse.put("tfCodePostal", tfCodePostal);
593
 
594
		TextField tfVille = new TextField();
595
		tfVille.setFieldLabel("Ville");
376 gduche 596
		tfVille.setName("ville");
293 gduche 597
 
319 gduche 598
		right.add(tfVille, fd100);
293 gduche 599
		hmAdresse.put("tfVille", tfVille);
600
 
601
		// MAJ ComboBox
602
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
603
 
304 gduche 604
		FieldSet fsAdresse = new FieldSet();
605
		fsAdresse.setHeading("Adresse personnelle");
606
		fsAdresse.add(main);
293 gduche 607
 
304 gduche 608
		tiAdresses.add(fsAdresse);
352 gduche 609
		((ComboBox) hmIdentite.get("cbPrefixe")).setRawValue("ljkhlkj");
293 gduche 610
	}
338 gduche 611
 
276 gduche 612
	/**
613
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
614
	 *
615
	 * @param barreOutils la barre d'outils à modifier
616
	 * */
376 gduche 617
	public void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
276 gduche 618
 
619
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
488 gduche 620
		Button reinitialiser = new Button("Réinitialiser le formulaire");
519 gduche 621
		reinitialiser.setIcon(Images.ICONES.rafraichir());
488 gduche 622
		reinitialiser.addSelectionListener(new SelectionListener<ButtonEvent>() {
623
			public void componentSelected(ButtonEvent ce) {
376 gduche 624
				//((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
625
				reinitialiser();
276 gduche 626
			}
627
		});
628
		barreOutils.add(reinitialiser);
629
	}
630
 
631
	/**
338 gduche 632
	 * Ajouter le bouton Sauvegarder et revenir à la liste à la barre d'outils donnée
633
	 *
634
	 * @param barreOutils la barre d'outils à modifier
635
	 * */
456 gduche 636
	private void ajouterBoutonEnregistrerEtRevenir(ButtonBar barreOutils)	{
338 gduche 637
 
638
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 639
		enregistrerEtRevenir = new Button("Enregistrer et revenir à la liste");
640
		enregistrerEtRevenir.setIcon(Images.ICONES.scriptGo());
641
		enregistrerEtRevenir.setIconAlign(IconAlign.LEFT);
642
		enregistrerEtRevenir.addSelectionListener(new SelectionListener<ButtonEvent>() {
488 gduche 643
			public void componentSelected(ButtonEvent ce) {
676 gduche 644
				if (enregistrer() == true)	{
645
					((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
646
				}
338 gduche 647
			}
648
		});
456 gduche 649
 
668 gduche 650
		hmIdentite.put("btnEnregistrerRevenir", enregistrerEtRevenir);
651
		barreOutils.add(enregistrerEtRevenir);
652
		enregistrerEtRevenir.setEnabled(false);
456 gduche 653
 
338 gduche 654
	}
655
 
656
	/**
276 gduche 657
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
658
	 *
659
	 * @param barreOutils la barre d'outils à modifier
660
	 * */
456 gduche 661
	private void ajouterBoutonEnregistrer(ButtonBar barreOutils)	{
276 gduche 662
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
668 gduche 663
		enregistrer = new Button("Enregistrer");
519 gduche 664
		enregistrer.setIcon(Images.ICONES.scriptSave());
665
		enregistrer.setIconAlign(IconAlign.LEFT);
352 gduche 666
		enregistrer.setId("main-button");
488 gduche 667
		enregistrer.addSelectionListener(new SelectionListener<ButtonEvent>() {
668
			public void componentSelected(ButtonEvent ce) {
376 gduche 669
				enregistrer();
276 gduche 670
			}
671
		});
456 gduche 672
		enregistrer.setEnabled(false);
673
		hmIdentite.put("btnEnregistrer", enregistrer);
286 gduche 674
		barreOutils.add(enregistrer);
276 gduche 675
	}
676
 
677
	/**
678
	 * Ajouter le bouton annuler à la barre d'outils donnée
679
	 *
680
	 * @param barreOutils la barre d'outils à modifier
681
	 * */
356 gduche 682
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 683
 
684
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 685
		Button annuler = new Button("Revenir à la liste");
488 gduche 686
		annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {
687
			public void componentSelected(ButtonEvent ce) {
276 gduche 688
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
689
			}
690
		});
691
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
692
		barreOutils.add(annuler);
693
	}
694
 
293 gduche 695
	public void obtenirListeRegionParPays(String strPays)	{
696
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
697
	}
276 gduche 698
 
730 jp_milcent 699
	// RAFRAICHISSEMENT DU PANNEAU
700
 
283 gduche 701
	public void rafraichir(Object nouvellesDonnees) {
456 gduche 702
		if (nouvellesDonnees instanceof ValeurListe) {
283 gduche 703
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
704
 
705
			// Créer une liste de valeurs
706
			List<Valeur> liste = new ArrayList<Valeur>();
707
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
708
				liste.add(listeValeurs.get(it.next()));
709
			}
710
 
711
			if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
319 gduche 712
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 713
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
714
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
715
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
716
				remplirCombobox("cbSexe", liste, "hmIdentite");
717
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
718
				remplirCombobox("cbTelephone", liste, "hmIdentite");
730 jp_milcent 719
 
319 gduche 720
				//Préselection du tél
721
				ComboBox<Valeur> cbTelephone = (ComboBox<Valeur>) hmIdentite.get("cbTelephone");
722
				cbTelephone.setValue(liste.get(1));
293 gduche 723
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
724
				remplirCombobox("cbPays", liste, "hmAdresse");
725
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
726
				remplirCombobox("cbRegion", liste, "hmAdresse");
731 jp_milcent 727
				((ComboBox) hmAdresse.get("cbRegion")).setVisible(true);
283 gduche 728
			}
456 gduche 729
		} else if (nouvellesDonnees instanceof ProjetListe) {
730
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
730 jp_milcent 731
			List<Projet> liste = projets.toList();
456 gduche 732
 
731 jp_milcent 733
			ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
456 gduche 734
			ListStore<Projet> storeProjets= cbProjets.getStore();
735
			storeProjets.removeAll();
736
			storeProjets.add(liste);
737
			cbProjets.setStore(storeProjets);
352 gduche 738
		} else if (nouvellesDonnees instanceof Information)	{
739
			Information info = (Information) nouvellesDonnees;
386 gduche 740
			if (info.getType().equals("ajout_personne"))	{
741
				GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
461 gduche 742
				Info.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
433 gduche 743
			} else if (info.getType().equals("modification_personne"))	{
744
				Info.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
668 gduche 745
			}
746
			else if (info.getType().equals("maj_utilisateur"))	{
747
				gererEtatActivationBouton();
386 gduche 748
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
776 gduche 749
 
730 jp_milcent 750
				Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
751
				Iterator itPersonneListe = colPersonneListe.iterator();
752
				Personne personne = (Personne) itPersonneListe.next();
753
 
754
				personneSauvegarde = new Personne();
755
				personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
756
 
757
				binderPersonne(personne);
758
 
776 gduche 759
				mettreAJourPersonne(personne);
730 jp_milcent 760
 
761
				nouvellesDonnees = null;
762
			} else {
763
				Info.display("messages", info.getMessages().toString());
764
			}
776 gduche 765
		}
283 gduche 766
 
730 jp_milcent 767
		if (nouvellesDonnees == null) {
319 gduche 768
			ComboBox cb= (ComboBox) hmIdentite.get("cbPrefixe");
293 gduche 769
 
770
			//Met à jour le nom Complet du formulaire
283 gduche 771
			String valeurRetour = "";
772
 
773
			// Prefixe
774
			String prefixe = "";
319 gduche 775
			Valeur valPrefixe = (Valeur) ((ComboBox) hmIdentite.get("cbPrefixe")).getValue();
283 gduche 776
 
777
			if (valPrefixe != null)	{
778
				prefixe = valPrefixe.getNom();
293 gduche 779
			} else 	{
319 gduche 780
				prefixe =  (String) ((ComboBox) hmIdentite.get("cbPrefixe")).getRawValue();
293 gduche 781
			}
283 gduche 782
 
783
			// Prénom
784
			String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
785
 
786
			// Nom
787
			String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
788
 
789
			// Suffixe
790
			String suffixe = "";
791
			Valeur valSuffixe = (Valeur) ((ComboBox) hmIdentite.get("cbSuffixe")).getValue();
792
 
793
			if (valSuffixe != null)	{
794
				suffixe = valSuffixe.getNom();
293 gduche 795
			} else 	{
796
				suffixe =  (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getRawValue();
283 gduche 797
			}
798
 
799
			// Mettre à jour la valeur
800
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
801
			valeurRetour = valeurRetour.replaceAll("null", "");
802
 
803
			((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
804
 
805
			if (!valeurRetour.trim().equals(""))	{
806
				((LabelField) hmIdentite.get("nomComplet")).show();
807
			} else {
808
				((LabelField) hmIdentite.get("nomComplet")).hide();
809
			}
810
		}
338 gduche 811
 
812
		mediateur.masquerPopinChargement();
456 gduche 813
 
461 gduche 814
		if (this.mode.equals(MODE_AJOUTER))	{
668 gduche 815
			gererEtatActivationBouton();
456 gduche 816
		}
127 gduche 817
	}
818
 
776 gduche 819
	private void mettreAJourPersonne(Personne personne)	{
820
 
821
 
822
		//Mise à jour de la personne
823
		//Personne personne = (Personne) nouvellesDonnees;
824
 
825
		ComboBox cbProjets = (ComboBox) hmIdentite.get("cbProjets");
826
		cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
827
 
828
		//Prefixe
829
		String prefixe = personne.get("ce_truk_prefix");
830
		ComboBox<Valeur> cbPrefixe = (ComboBox<Valeur>) hmIdentite.get("cbPrefixe");
831
 
832
 
833
		String prefixeCourant = personne.get("ce_truk_prefix");
834
		if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
835
			cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
836
		}	else	{
837
			cbPrefixe.setRawValue(prefixeCourant);
838
		}
839
 
840
 
841
		((TextField) hmIdentite.get("tfPrenom")).setValue(personne.get("prenom"));
842
		((TextField) hmIdentite.get("tfNom")).setValue(personne.get("nom"));
843
 
844
		//Suffixe
845
		String suffixe = personne.get("ce_truk_suffixe");
846
		ComboBox<Valeur> cbSuffixe = (ComboBox<Valeur>) hmIdentite.get("cbSuffixe");
847
 
848
		String suffixeCourant = personne.get("ce_truk_suffix");
849
		if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
850
			cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
851
		}	else	{
852
			cbSuffixe.setRawValue(suffixeCourant);
853
		}
854
 
855
		((TextField) hmIdentite.get("tfNomAutre")).setValue(personne.get("truk_nom_autre"));
856
		((TextField) hmIdentite.get("tfAbreviation")).setValue(personne.get("abreviation"));
857
		((TextField) hmIdentite.get("tfAbreviationAutre")).setValue(personne.get("truk_abreviation_autre"));
858
 
859
 
860
		(((DateField) hmIdentite.get("dfDateNaissance"))).setValue(personne.getDate("naissance_date"));
861
		((TextField) hmIdentite.get("tfLieuNaissance")).setValue(personne.get("naissance_lieu"));
862
 
863
		(((DateField) hmIdentite.get("dfDateDeces"))).setValue(personne.getDate("deces_date"));
864
		((TextField) hmIdentite.get("tfLieuDeces")).setValue(personne.get("deces_lieu"));
865
 
866
		((ChampMultiValeursMultiTypes) hmIdentite.get("telephones")).peupler(personne.getString("truk_telephone"));
867
 
868
		//Courriel
869
		((ChampMultiValeurs) hmIdentite.get("courriels")).peupler(personne.getCourriel());
870
 
871
		//Sites web
872
		((ChampMultiValeurs) hmIdentite.get("sites")).peupler(personne.getString("truk_url"));
873
 
874
 
875
		// Sexe
876
		String strSexe = personne.get("ce_sexe");
877
		ComboBox<Valeur> cbSexe = (ComboBox<Valeur>) hmIdentite.get("cbSexe");
878
 
879
		if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)	{
880
			cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
881
		}	else	{
882
			cbSexe.setRawValue(strSexe);
883
		}
884
 
885
		((TextArea) hmIdentite.get("taDescription")).setRawValue((String) personne.get("description"));
886
 
887
		//Logo
888
		((ChampMultiValeurs) hmIdentite.get("logos")).peupler(personne.getString("truk_logo"));
889
 
890
		/*--------------------------------------------------
891
		                      Adresse
892
		 ---------------------------------------------------*/
893
 
894
		// Adresse
895
		((TextField<String>) hmAdresse.get("tfAdresse1")).setValue((String) personne.get("adresse_01"));
896
 
897
		// Complément
898
		((TextField<String>) hmAdresse.get("tfAdresse2")).setValue((String) personne.get("adresse_02"));
899
 
900
		//Boite postale
901
		((TextField<String>) hmAdresse.get("tfBoitePostale")).setValue((String) personne.get("bp"));
902
 
903
		//Pays
904
		String strPays = personne.get("pays");
905
		ComboBox<Valeur> cbPays = (ComboBox<Valeur>) hmAdresse.get("cbPays");
906
 
907
 
908
		if (cbPays.getStore().findModel("nom", strPays) != null)	{
909
			cbPays.setValue(cbPays.getStore().findModel("nom", strPays));
910
		}	else	{
911
			cbPays.setRawValue(strPays);
912
		}
913
 
914
		//Région
915
		String strRegion = personne.get("region");
916
		if ((strRegion!=null)&&(!strRegion.equals("")))	{
917
			ComboBox<Valeur> cbRegion = (ComboBox<Valeur>) hmAdresse.get("cbRegion");
918
			cbRegion.setVisible(true);
919
 
920
			if (cbRegion.getStore().findModel("nom", strRegion) != null)	{
921
				cbRegion.setValue(cbRegion.getStore().findModel("nom", strRegion));
922
			}	else	{
923
				cbRegion.setRawValue(strRegion);
924
			}
925
		}
926
 
927
		//Cp
928
		((TextField) hmAdresse.get("tfCodePostal")).setValue(personne.get("code_postal"));
929
 
930
		//Ville
931
		((TextField) hmAdresse.get("tfVille")).setValue(personne.get("ville"));
932
 
933
		gererEtatActivationBouton();
934
 
935
	}
730 jp_milcent 936
 
293 gduche 937
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
938
		HashMap hm = null;
939
		if (hashMapId.equals("hmIdentite"))	{
940
			hm = hmIdentite;
941
		} else if (hashMapId.equals("hmAdresse")){
942
			hm = hmAdresse;
943
		} else {
944
			hm = hmInfosNat;
945
		}
946
 
947
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 948
 
293 gduche 949
		store.removeAll();
950
		store.add(liste);
951
		((ComboBox) hm.get(idComboBox)).setStore(store);
952
	}
130 gduche 953
 
668 gduche 954
	private void gererEtatActivationBouton()	{
955
		if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
956
			enregistrer.setEnabled(false);
957
			enregistrerEtRevenir.setEnabled(false);
958
		} else	{
959
			enregistrer.setEnabled(true);
960
			enregistrerEtRevenir.setEnabled(true);
961
		}
962
	}
963
 
376 gduche 964
	public void reinitialiser()	{
461 gduche 965
		mediateur.afficherPopinChargement();
376 gduche 966
 
776 gduche 967
		mettreAJourPersonne(personneSauvegarde);
376 gduche 968
 
969
		mediateur.masquerPopinChargement();
776 gduche 970
 
376 gduche 971
	}
972
 
973
	public void binderPersonne(Personne personne)	{
731 jp_milcent 974
		binding = new FormBinding(this);
975
 
376 gduche 976
		personneSelectionnee = personne;
977
		binding.autoBind();
978
		binding.bind(personneSelectionnee);
979
 
980
		layout();
981
	}
130 gduche 982
 
376 gduche 983
	/**
984
	 * Enregistre les information de la personne en cours
985
	 *
986
	 */
676 gduche 987
	public boolean enregistrer()	{
988
		boolean success = false;
376 gduche 989
		LinkedList lstMessageErreur = new LinkedList<String>();
990
 
456 gduche 991
		ComboBox<Projet> cbProjets = (ComboBox<Projet>) hmIdentite.get("cbProjets");
992
		Projet projet = cbProjets.getValue();
993
		if (projet == null)	{
994
			lstMessageErreur.add("Le projet n'a pas été renseigné");
681 gduche 995
		} else {
996
			personneSelectionnee.set("ce_projet", projet.getId());
456 gduche 997
		}
461 gduche 998
 
999
		String strTfNom = ((TextField<String>) hmIdentite.get("tfNom")).getValue();
1000
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1001
			lstMessageErreur.add("Le nom n'a pas été saisi");
622 gduche 1002
		} else {
1003
			strTfNom = UtilString.ucFirst(strTfNom);
1004
			personneSelectionnee.set("nom", strTfNom);
461 gduche 1005
		}
456 gduche 1006
 
622 gduche 1007
		String strTfPrenom = ((TextField<String>) hmIdentite.get("tfPrenom")).getValue();
1008
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1009
 
376 gduche 1010
		//Préparer les données
1011
		ComboBox combo = (ComboBox) hmIdentite.get("cbSexe");
1012
		Valeur valeur;
1013
		String strValeur = "";
1014
 
678 gduche 1015
		valeur = (Valeur) combo.getValue();
1016
		if (valeur!=null)	{
1017
			personneSelectionnee.set("ce_sexe", valeur.getId());
1018
		}
376 gduche 1019
 
1020
		strValeur = obtenirValeurCombo("cbPrefixe");
1021
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1022
 
1023
		strValeur = obtenirValeurCombo("cbSuffixe");
1024
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1025
 
692 gduche 1026
		personneSelectionnee.set("truk_courriel", ((ChampMultiValeurs) hmIdentite.get("courriels")).getValeurs());
376 gduche 1027
 
386 gduche 1028
 
1029
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1030
		String strPrefixe = "";
1031
		combo = (ComboBox) hmIdentite.get("cbPrefixe");
1032
		valeur = (Valeur) combo.getValue();
1033
		if (valeur != null)	{
1034
			strPrefixe = valeur.getNom();
1035
		} else {
1036
			strPrefixe = combo.getRawValue();
1037
		}
1038
 
1039
		String strSuffixe = "";
1040
		combo = (ComboBox) hmIdentite.get("cbSuffixe");
1041
		valeur = (Valeur) combo.getValue();
1042
		if (valeur != null)	{
456 gduche 1043
			strSuffixe = valeur.getNom() + " ";
386 gduche 1044
		} else {
456 gduche 1045
			strSuffixe = combo.getRawValue() +" ";
386 gduche 1046
		}
376 gduche 1047
 
456 gduche 1048
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
376 gduche 1049
 
1050
 
456 gduche 1051
		DateField dfDateNaissance = (DateField) hmIdentite.get("dfDateNaissance");
1052
		Date naissanceDate = dfDateNaissance.getValue();
1053
		personneSelectionnee.setNaissanceDate(naissanceDate);
376 gduche 1054
 
456 gduche 1055
		Radio rbEstDecedee = (Radio) hmIdentite.get("rbEstDecedee");
1056
		if (rbEstDecedee.getValue().equals(true))	{
1057
 
1058
			DateField dfDecesDate = (DateField) hmIdentite.get("dfDateDeces");
1059
			Date decesDate = dfDecesDate.getValue();
1060
			if (decesDate == null)	{
1061
				decesDate = new Date();
1062
			}
1063
			personneSelectionnee.setDecesDate(decesDate);
1064
			personneSelectionnee.set("deces_lieu", ((TextField<String>) hmIdentite.get("tfLieuDeces")).getValue());
1065
		}
1066
 
1067
		personneSelectionnee.setDecesDate(new Date());
1068
 
376 gduche 1069
		strValeur = obtenirValeurCombo("cbPays");
676 gduche 1070
		personneSelectionnee.set("ce_truk_pays", strValeur);
376 gduche 1071
 
1072
		strValeur = obtenirValeurCombo("cbRegion");
676 gduche 1073
		personneSelectionnee.set("ce_truk_region", strValeur);
376 gduche 1074
 
722 gduche 1075
		personneSelectionnee.set("truk_telephone", ((ChampMultiValeursMultiTypes) hmIdentite.get("telephones")).getValeurs());
376 gduche 1076
 
701 gduche 1077
		String logoUrls = ((ChampMultiValeursImage) hmIdentite.get("logos")).getValeurs();
386 gduche 1078
		personneSelectionnee.set("truk_logo", logoUrls);
376 gduche 1079
 
692 gduche 1080
		personneSelectionnee.set("truk_url", ((ChampMultiValeurs) hmIdentite.get("sites")).getValeurs());
376 gduche 1081
 
461 gduche 1082
		if (lstMessageErreur.size() == 0)	{
386 gduche 1083
			mediateur.enregistrerPersonne(this, personneSelectionnee);
676 gduche 1084
			success = true;
456 gduche 1085
		} else {
1086
			String strMessagesErreur = "<span><br />";
386 gduche 1087
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1088
			while (itMessagesErreur.hasNext())	{
456 gduche 1089
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
386 gduche 1090
			}
456 gduche 1091
			strMessagesErreur += "</span>";
386 gduche 1092
 
1093
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
676 gduche 1094
 			success = false;
456 gduche 1095
		}
676 gduche 1096
 
1097
		return success;
376 gduche 1098
	}
1099
 
1100
	private String obtenirValeurCombo(String strComboName)	{
1101
		String strValeur = "";
1102
		Valeur valeur;
1103
 
1104
		ComboBox combo = (ComboBox) hmIdentite.get(strComboName);
1105
		if (combo == null)	{
1106
			combo = (ComboBox) hmAdresse.get(strComboName);
1107
		}
1108
		if (combo.getValue()!=null)	{
1109
			valeur = (Valeur) combo.getValue();
1110
			strValeur = valeur.getId();
1111
		} else {
1112
			strValeur = combo.getRawValue();
1113
		}
1114
 
1115
		return strValeur;
1116
	}
127 gduche 1117
}