Subversion Repositories eFlore/Applications.coel

Rev

Rev 981 | Rev 1014 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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