Subversion Repositories eFlore/Applications.coel

Rev

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