Subversion Repositories eFlore/Applications.coel

Rev

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