Subversion Repositories eFlore/Applications.coel

Rev

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