Subversion Repositories eFlore/Applications.coel

Rev

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