Subversion Repositories eFlore/Applications.coel

Rev

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

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