Subversion Repositories eFlore/Applications.coel

Rev

Rev 1186 | Rev 1262 | 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) {
1239 cyprien 676
Debug.log("|> PersonneForm.creerComposantsPubli() : A MODIFIER ! ajout publi");
991 gduche 677
				/*StructureAPersonne membreDuPersonnel = new StructureAPersonne("", StructureAPersonne.ROLE_EQUIPE, StructureAPersonne.ETAT_AJOUTE);
678
				ajouterMembreAGrillePersonnel(membreDuPersonnel);*/
679
			}
680
		});
681
		toolBar.add(ajouterPubli);
682
 
683
		toolBar.add(new SeparatorToolItem());
684
 
685
		Button supprimerPubli = new Button("Supprimer");
686
		supprimerPubli.setIcon(Images.ICONES.vcardSupprimer());
687
		supprimerPubli.addSelectionListener(new SelectionListener<ButtonEvent>() {
688
			@Override
689
			public void componentSelected(ButtonEvent ce) {
690
				/*StructureAPersonne personne = grillePersonnel.getSelectionModel().getSelectedItem();
691
				if (personne != null) {
692
					// Ajout de la personne supprimée à la liste
693
					if (personne.getIdPersonne() != null && !personne.getIdPersonne().equals("")) {
694
						personnelSupprime.put(personne.getId(), personne);
695
					}
696
 
697
					// Suppression de l'enregistrement de la grille
698
					grillePersonnel.getStore().remove(personne);
699
 
700
					// Désactivation du bouton supprimer si la grille contient plus d'élément
701
					if (grillePersonnel.getStore().getCount() == 0) {
702
						//TODO : check : Item -> component
703
						ce.getComponent().disable();
704
					}
705
				}*/
706
				Window.alert("supprimer");
707
			}
708
		});
709
		toolBar.add(supprimerPubli);
710
 
711
		toolBar.add(new SeparatorToolItem());
712
 
713
		Button rafraichirPersonnelBtn = new Button("Rafraichir");
714
		rafraichirPersonnelBtn.setIcon(Images.ICONES.rafraichir());
715
		rafraichirPersonnelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {
716
			@Override
717
			public void componentSelected(ButtonEvent ce) {
718
				//rafraichirPersonnel();
719
				Window.alert("rafraichir");
720
			}
721
		});
722
		toolBar.add(rafraichirPersonnelBtn);
723
 
724
		//Ajout d'une ComboBox
725
		storePubli = new ListStore<Publication>();
726
		storePubli.add(new ArrayList<Publication>());
727
 
728
		cbPubli = new ComboBox<Publication>();
729
		cbPubli.setWidth(200);
730
		cbPubli.setEmptyText("Chercher une publication existante...");
731
		cbPubli.setTriggerAction(TriggerAction.ALL);
732
		cbPubli.setEditable(true);
733
		cbPubli.setDisplayField("fmt_nom_complet");
734
		cbPubli.setStore(storePubli);
735
		cbPubli.addKeyListener(new KeyListener() {
736
 
737
			public void componentKeyUp(ComponentEvent ce) {
738
				if (!ce.isNavKeyPress() && cbPubli.getRawValue() != null && cbPubli.getRawValue().length() > 0) {
739
					rafraichirPublicationsExistante(cbPubli.getRawValue());
740
				}
741
			}
742
 
743
		});
744
 
745
		toolBar.add(cbPubli);
746
		toolBar.add(new SeparatorToolItem());
747
		cp.setTopComponent(toolBar);
748
 
749
 
750
		tiPubli.add(cp);
751
	}
752
 
753
	public void rafraichirPublicationsExistante(String nomPubli)	{
1239 cyprien 754
 
755
Debug.log("|> PersonneForm.rafraichirPublicationsExistante()");
756
 
991 gduche 757
		nomPubli +="%";
758
		mediateur.selectionnerPublicationParNomComplet(this, null, nomPubli);
759
	}
760
 
276 gduche 761
	/**
762
	 * Ajouter le bouton annuler à la barre d'outils donnée
763
	 *
764
	 * @param barreOutils la barre d'outils à modifier
765
	 * */
356 gduche 766
	public static void ajouterBoutonAnnuler(ButtonBar barreOutils)	{
276 gduche 767
 
768
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
356 gduche 769
		Button annuler = new Button("Revenir à la liste");
488 gduche 770
		annuler.addSelectionListener(new SelectionListener<ButtonEvent>() {
771
			public void componentSelected(ButtonEvent ce) {
276 gduche 772
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
773
			}
774
		});
775
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
776
		barreOutils.add(annuler);
777
	}
778
 
293 gduche 779
	public void obtenirListeRegionParPays(String strPays)	{
780
		mediateur.obtenirListeRegionsEtRafraichir(this, "region", strPays);
781
	}
276 gduche 782
 
730 jp_milcent 783
	// RAFRAICHISSEMENT DU PANNEAU
784
 
283 gduche 785
	public void rafraichir(Object nouvellesDonnees) {
1239 cyprien 786
 
787
Debug.log("|> PersonneForm.rafraichir(Object nouvellesDonnees) BEGIN");
788
 
991 gduche 789
		if (nouvellesDonnees instanceof PublicationAPersonneListe)	{
1239 cyprien 790
 
791
Debug.log("|--> PersonneForm.rafraichir(Object nouvellesDonnees) : nouvellesDonnees instanceof PublicationAPersonneListe");
792
 
991 gduche 793
			Information info = new Information();
794
			info.setType("publication_liees");
795
			info.setDonnee(0, (PublicationAPersonneListe) nouvellesDonnees);
1239 cyprien 796
 
797
Debug.log("|--> tiPubli.rafraichir(info)");
991 gduche 798
			tiPubli.rafraichir(info);
1239 cyprien 799
 
991 gduche 800
		} else if (nouvellesDonnees instanceof ValeurListe) {
1014 gduche 801
 
1239 cyprien 802
Debug.log("|--> PersonneForm.rafraichir(Object nouvellesDonnees) : nouvellesDonnees instanceof ValeurListe");
803
 
804
 
283 gduche 805
			ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
806
 
807
			// Créer une liste de valeurs
808
			List<Valeur> liste = new ArrayList<Valeur>();
809
			for (Iterator<String> it = listeValeurs.keySet().iterator(); it.hasNext();) {
810
				liste.add(listeValeurs.get(it.next()));
811
			}
1014 gduche 812
			if (listeValeurs.getId().equals(config.getListeId("relationPersonnePublication")))	{
1239 cyprien 813
 
814
Debug.log("|--> tiPubli.rafraichir(nouvellesDonnees)");
1014 gduche 815
				tiPubli.rafraichir(nouvellesDonnees);
1239 cyprien 816
 
817
 
1014 gduche 818
			} else if (listeValeurs.getId().equals(config.getListeId("prefixe")))	{
319 gduche 819
				remplirCombobox("cbPrefixe", liste, "hmIdentite");
293 gduche 820
			} else if (listeValeurs.getId().equals(config.getListeId("suffixes"))) {
821
				remplirCombobox("cbSuffixe", liste, "hmIdentite");
822
			} else if (listeValeurs.getId().equals(config.getListeId("sexe"))) {
1101 gduche 823
 
824
				//Ajout de la valeur "Inconnu"
825
				ComboBox<Valeur> cbSexe = hmAdresse.getComboBoxValeur("cbSexe");
826
				Valeur inconnu = new Valeur();
827
				inconnu.set("nom", "Inconnu");
828
				inconnu.set("id", "0");
829
				liste.add(0, inconnu);
830
 
293 gduche 831
				remplirCombobox("cbSexe", liste, "hmIdentite");
1101 gduche 832
 
833
				/*List<Valeur> selection = new LinkedList<Valeur>();
834
				selection.add(inconnu);
835
				cbSexe.setSelection(s);*/
836
 
837
 
293 gduche 838
			} else if (listeValeurs.getId().equals(config.getListeId("tel"))) {
839
				remplirCombobox("cbTelephone", liste, "hmIdentite");
730 jp_milcent 840
 
319 gduche 841
				//Préselection du tél
973 gduche 842
				ComboBox<Valeur> cbTelephone = hmIdentite.getComboBoxValeur("cbTelephone");
319 gduche 843
				cbTelephone.setValue(liste.get(1));
293 gduche 844
			} else if (listeValeurs.getId().equals(config.getListeId("pays")))	{
845
				remplirCombobox("cbPays", liste, "hmAdresse");
846
			} else if (listeValeurs.getId().equals(config.getListeId("region")))	{
847
				remplirCombobox("cbRegion", liste, "hmAdresse");
1033 gduche 848
				mettreAJourRegion();
976 gduche 849
				hmAdresse.getComboBox("cbRegion").setVisible(true);
1026 gduche 850
 
283 gduche 851
			}
456 gduche 852
		} else if (nouvellesDonnees instanceof ProjetListe) {
1239 cyprien 853
 
854
 
855
Debug.log("|--> PersonneForm.rafraichir(Object nouvellesDonnees) : nouvellesDonnees instanceof ProjetListe");
856
 
456 gduche 857
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
730 jp_milcent 858
			List<Projet> liste = projets.toList();
456 gduche 859
 
973 gduche 860
			ComboBox cbProjets = hmIdentite.getComboBox("cbProjets");
456 gduche 861
			ListStore<Projet> storeProjets= cbProjets.getStore();
862
			storeProjets.removeAll();
863
			storeProjets.add(liste);
864
			cbProjets.setStore(storeProjets);
991 gduche 865
		} else if (nouvellesDonnees instanceof PublicationListe)	{
1239 cyprien 866
 
867
Debug.log("|> PersonneForm.rafraichir");
868
Debug.log("|--> nouvellesDonnees instanceof PublicationListe");
869
 
991 gduche 870
 
871
			PublicationListe publicationListe = (PublicationListe) nouvellesDonnees;
1239 cyprien 872
 
873
Debug.log("|--> nouvellesDonnees ="+publicationListe.toString());
874
 
991 gduche 875
			List<Publication> liste = publicationListe.toList();
1239 cyprien 876
 
991 gduche 877
			storePubli.removeAll();
878
			storePubli.add(liste);
879
			cbPubli.setStore(storePubli);
880
 
352 gduche 881
		} else if (nouvellesDonnees instanceof Information)	{
1239 cyprien 882
 
883
Debug.log("|--> PersonneForm.rafraichir(Object nouvellesDonnees) : nouvellesDonnees instanceof Information");
884
 
352 gduche 885
			Information info = (Information) nouvellesDonnees;
386 gduche 886
			if (info.getType().equals("ajout_personne"))	{
884 jpm 887
				if (info.getDonnee(0) != null) {
888
					personneSelectionnee.setId(info.getDonnee(0).toString());
889
					GWT.log("Ajout de la personne " + personneSelectionnee.getId(), null);
1239 cyprien 890
					InfoLogger.display("Enregistrement", "La personne a été ajoutée (id: " + personneSelectionnee.getId() + ")");
884 jpm 891
					repandreRafraichissement();
892
					if (clicBoutonvalidation)	{
893
						mediateur.clicMenu(menuIdCourant);
894
					}
895
				} else {
1239 cyprien 896
					InfoLogger.display("Enregistrement", info.getMessages().toString());
852 gduche 897
				}
433 gduche 898
			} else if (info.getType().equals("modification_personne"))	{
1239 cyprien 899
				InfoLogger.display("Enregistrement", "Les modifications apportées à la personne " + personneSelectionnee.getId() + " ont été correctement enregistrées.");
884 jpm 900
				repandreRafraichissement();
852 gduche 901
				if (clicBoutonvalidation)	{
902
					mediateur.clicMenu(menuIdCourant);
903
				}
884 jpm 904
			} else if (info.getType().equals("maj_utilisateur"))	{
668 gduche 905
				gererEtatActivationBouton();
386 gduche 906
			} else if (info.getDonnee(0) instanceof PersonneListe)	{
776 gduche 907
 
730 jp_milcent 908
				Collection colPersonneListe = ((PersonneListe) info.getDonnee(0)).values();
909
				Iterator itPersonneListe = colPersonneListe.iterator();
910
				Personne personne = (Personne) itPersonneListe.next();
911
 
991 gduche 912
				//TODO : Je vois pas l'intérêt des lignes ci dessous..
730 jp_milcent 913
				personneSauvegarde = new Personne();
914
				personneSauvegarde = (Personne) personne.cloner(personneSauvegarde);
915
 
916
				binderPersonne(personne);
917
 
776 gduche 918
				mettreAJourPersonne(personne);
730 jp_milcent 919
 
920
				nouvellesDonnees = null;
921
			} else {
1239 cyprien 922
				InfoLogger.display("messages", info.getMessages().toString());
730 jp_milcent 923
			}
776 gduche 924
		}
283 gduche 925
 
730 jp_milcent 926
		if (nouvellesDonnees == null) {
1239 cyprien 927
 
928
Debug.log("|--> PersonneForm.rafraichir(Object nouvellesDonnees) : nouvellesDonnees == null");
929
 
973 gduche 930
			ComboBox<Valeur> cb= hmIdentite.getComboBoxValeur("cbPrefixe");
293 gduche 931
 
932
			//Met à jour le nom Complet du formulaire
283 gduche 933
			String valeurRetour = "";
934
 
935
			// Prefixe
936
			String prefixe = "";
973 gduche 937
			Valeur valPrefixe = cb.getValue();
283 gduche 938
 
939
			if (valPrefixe != null)	{
940
				prefixe = valPrefixe.getNom();
293 gduche 941
			} else 	{
973 gduche 942
				prefixe =  (String) cb.getRawValue();
293 gduche 943
			}
283 gduche 944
 
945
			// Prénom
973 gduche 946
			String prenom = (String) hmIdentite.getTextField("tfPrenom").getValue();
283 gduche 947
 
948
			// Nom
973 gduche 949
			String nom = (String) hmIdentite.getTextField("tfNom").getValue();
283 gduche 950
 
951
			// Suffixe
973 gduche 952
			ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe");
953
 
283 gduche 954
			String suffixe = "";
973 gduche 955
			Valeur valSuffixe = cbSuffixe.getValue();
283 gduche 956
 
957
			if (valSuffixe != null)	{
958
				suffixe = valSuffixe.getNom();
293 gduche 959
			} else 	{
973 gduche 960
				suffixe =  (String) cbSuffixe.getRawValue();
283 gduche 961
			}
962
 
963
			// Mettre à jour la valeur
964
			valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
965
			valeurRetour = valeurRetour.replaceAll("null", "");
966
 
973 gduche 967
			hmIdentite.getLabelField("nomComplet").setValue(valeurRetour);
283 gduche 968
 
969
			if (!valeurRetour.trim().equals(""))	{
973 gduche 970
				hmIdentite.getLabelField("nomComplet").show();
283 gduche 971
			} else {
973 gduche 972
				hmIdentite.getLabelField("nomComplet").hide();
283 gduche 973
			}
974
		}
338 gduche 975
 
976
		mediateur.masquerPopinChargement();
456 gduche 977
 
461 gduche 978
		if (this.mode.equals(MODE_AJOUTER))	{
668 gduche 979
			gererEtatActivationBouton();
456 gduche 980
		}
1239 cyprien 981
 
982
Debug.log("|> PersonneForm.rafraichir(Object nouvellesDonnees) END");
127 gduche 983
	}
984
 
884 jpm 985
	private void repandreRafraichissement() {
1239 cyprien 986
 
987
Debug.log("|> PersonneForm.repandreRafraichissement()");
988
 
884 jpm 989
		if (vueExterneARafraichirApresValidation != null) {
990
			String type = "personne_modifiee";
991
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
992
				type = "personne_ajoutee";
993
			}
994
			Information info = new Information(type);
995
			info.setDonnee(0, personneSelectionnee);
996
			vueExterneARafraichirApresValidation.rafraichir(info);
997
		}
998
	}
999
 
1026 gduche 1000
	private void mettreAJourRegion()	{
1033 gduche 1001
		//Met à jour la combo box en sélectionnant la valeur enregistrée pour la personne
1026 gduche 1002
		ComboBox<Valeur> cbRegion = hmAdresse.getComboBoxValeur("cbRegion");
1036 gduche 1003
		if (personneSelectionnee.get("ce_truk_region").toString().startsWith("AUTRE##")) {
1004
			cbRegion.setRawValue(personneSelectionnee.get("ce_truk_region").toString().replaceFirst("^AUTRE##", ""));
1005
		} else if (personneSelectionnee.get("ce_truk_region") != null && cbRegion.getStore().getCount() > 0)	{
1026 gduche 1006
			Valeur valeurRegion = cbRegion.getStore().findModel("id_valeur", personneSelectionnee.get("ce_truk_region"));
1007
			if (valeurRegion!=null)	{
1008
				cbRegion.setValue(valeurRegion);
1009
			}
1010
		}
1011
	}
1036 gduche 1012
 
776 gduche 1013
	private void mettreAJourPersonne(Personne personne)	{
1239 cyprien 1014
 
1015
Debug.log("|> BEGIN PersonneForm.mettreAJourPersonne()");
1016
 
1017
 
776 gduche 1018
		//Mise à jour de la personne
1019
		//Personne personne = (Personne) nouvellesDonnees;
973 gduche 1020
		ComboBox cbProjets = hmIdentite.getComboBox("cbProjets");
776 gduche 1021
		cbProjets.setValue(cbProjets.getStore().findModel("id_projet", personne.get("ce_projet")));
1022
 
1023
		//Prefixe
1024
		String prefixe = personne.get("ce_truk_prefix");
973 gduche 1025
		ComboBox<Valeur> cbPrefixe = hmIdentite.getComboBoxValeur("cbPrefixe");
776 gduche 1026
 
1027
 
1028
		String prefixeCourant = personne.get("ce_truk_prefix");
1029
		if (cbPrefixe.getStore().findModel("id_valeur", prefixeCourant) != null)	{
1030
			cbPrefixe.setValue(cbPrefixe.getStore().findModel("id_valeur", prefixeCourant));
1031
		}	else	{
1032
			cbPrefixe.setRawValue(prefixeCourant);
1033
		}
1034
 
973 gduche 1035
		hmIdentite.getTextField("tfPrenom").setValue(personne.get("prenom"));
1036
		hmIdentite.getTextField("tfNom").setValue(personne.get("nom"));
776 gduche 1037
 
1038
		//Suffixe
1039
		String suffixe = personne.get("ce_truk_suffixe");
973 gduche 1040
		ComboBox<Valeur> cbSuffixe = hmIdentite.getComboBoxValeur("cbSuffixe");
776 gduche 1041
 
1042
		String suffixeCourant = personne.get("ce_truk_suffix");
1043
		if (cbSuffixe.getStore().findModel("id_valeur", suffixeCourant) != null)	{
1044
			cbSuffixe.setValue(cbSuffixe.getStore().findModel("id_valeur", suffixeCourant));
1045
		}	else	{
1046
			cbSuffixe.setRawValue(suffixeCourant);
1047
		}
1048
 
973 gduche 1049
		hmIdentite.getChampMultiValeurs("nomAutre").peupler(personne.getString("truk_nom_autre"));
1050
		hmIdentite.getTextField("tfAbreviation").setValue(personne.get("abreviation"));
1051
		hmIdentite.getChampMultiValeurs("abreviationAutre").peupler(personne.getString("truk_abreviation_autre"));
776 gduche 1052
 
973 gduche 1053
		hmIdentite.getDateField("dfDateNaissance").setValue(personne.getDate("naissance_date"));
1054
		hmIdentite.getTextField("tfLieuNaissance").setValue(personne.get("naissance_lieu"));
776 gduche 1055
 
1186 gduche 1056
 
829 gduche 1057
		if (personne.estDecedee())	{
973 gduche 1058
			hmIdentite.getDateField("dfDateDeces").setValue(personne.getDate("deces_date"));
1059
			hmIdentite.getTextField("tfLieuDeces").setValue(personne.get("deces_lieu"));
1060
			Radio rbEstDecede = hmIdentite.getRadio("rbEstDecedee");
829 gduche 1061
			rbEstDecede.setValue(true);
1062
		}
776 gduche 1063
 
973 gduche 1064
		hmIdentite.getChampMultiValeurs("telephones").peupler(personne.getString("truk_telephone"));
776 gduche 1065
 
1066
		//Courriel
973 gduche 1067
		hmIdentite.getChampMultiValeurs("courriels").peupler(personne.getCourriel());
776 gduche 1068
 
1069
		//Sites web
973 gduche 1070
		hmIdentite.getChampMultiValeurs("sites").peupler(personne.getString("truk_url"));
776 gduche 1071
 
1072
		// Sexe
1073
		String strSexe = personne.get("ce_sexe");
973 gduche 1074
		ComboBox<Valeur> cbSexe = hmIdentite.getComboBoxValeur("cbSexe");
776 gduche 1075
 
1076
		if (cbSexe.getStore().findModel("id_valeur", strSexe) != null)	{
1077
			cbSexe.setValue(cbSexe.getStore().findModel("id_valeur", strSexe));
1078
		}
1079
 
973 gduche 1080
		hmIdentite.getTextArea("taDescription").setRawValue((String) personne.get("description"));
776 gduche 1081
 
1082
		//Logo
973 gduche 1083
		hmIdentite.getChampMultiValeurs("logos").peupler(personne.getString("truk_logo"));
776 gduche 1084
 
1085
		/*--------------------------------------------------
1086
		                      Adresse
1087
		 ---------------------------------------------------*/
1088
 
1089
		// Adresse
976 gduche 1090
		hmAdresse.getTextField("tfAdresse1").setValue((String) personne.get("adresse_01"));
776 gduche 1091
 
1092
		// Complément
976 gduche 1093
		hmAdresse.getTextField("tfAdresse2").setValue((String) personne.get("adresse_02"));
776 gduche 1094
 
1095
		//Boite postale
976 gduche 1096
		hmAdresse.getTextField("tfBoitePostale").setValue((String) personne.get("bp"));
776 gduche 1097
 
1098
		//Pays
1026 gduche 1099
		String strPays = personne.get("ce_truk_pays");
976 gduche 1100
		ComboBox<Valeur> cbPays = hmAdresse.getComboBoxValeur("cbPays");
1026 gduche 1101
		if (cbPays.getStore().findModel("id_valeur", strPays) != null)	{
1102
			cbPays.setValue(cbPays.getStore().findModel("id_valeur", strPays));
1103
			cbPays.fireEvent(Events.OnChange);
776 gduche 1104
		}	else	{
1105
			cbPays.setRawValue(strPays);
1106
		}
1107
 
1026 gduche 1108
		//Région : doit être chargé après chargement de la liste des régions...
1109
		String strRegion = personne.get("ce_truk_region");
1110
 
776 gduche 1111
		if ((strRegion!=null)&&(!strRegion.equals("")))	{
976 gduche 1112
			ComboBox<Valeur> cbRegion = hmAdresse.getComboBoxValeur("cbRegion");
1026 gduche 1113
			System.out.println(cbRegion.getStore().getCount());
776 gduche 1114
			cbRegion.setVisible(true);
1115
 
1026 gduche 1116
			if (cbRegion.getStore().findModel("id_valeur", strRegion) != null)	{
1117
				cbRegion.setValue(cbRegion.getStore().findModel("id_valeur", strRegion));
776 gduche 1118
			}	else	{
1119
				cbRegion.setRawValue(strRegion);
1120
			}
1121
		}
1122
 
1123
		//Cp
976 gduche 1124
		hmAdresse.getTextField("tfCodePostal").setValue(personne.get("code_postal"));
776 gduche 1125
 
1126
		//Ville
976 gduche 1127
		hmAdresse.getTextField("tfVille").setValue(personne.get("ville"));
776 gduche 1128
 
821 gduche 1129
		/*--------------------------------------------------------
1130
		 * 					Infos naturalistes
1131
		 * -----------------------------------------------------*/
1132
 
979 gduche 1133
		hmInfosNat.getChampMultiValeurs("specialite").peupler(personne.getString("ce_truk_specialite"));
976 gduche 1134
		String tr = personne.getString("truk_recolte");
979 gduche 1135
		hmInfosNat.getChampMultiValeursMultiTypes("recolte").peupler(tr);
991 gduche 1136
 
1137
		//Onglet publi
1239 cyprien 1138
 
1139
Debug.log("|--> appel à tiPubli.mettreAJourPersonne()");
991 gduche 1140
		tiPubli.mettreAJourPersonne();
776 gduche 1141
		gererEtatActivationBouton();
1239 cyprien 1142
 
1143
Debug.log("|> BEGIN PersonneForm.mettreAJourPersonne()");
776 gduche 1144
	}
730 jp_milcent 1145
 
293 gduche 1146
	public void remplirCombobox(String idComboBox, List liste, String hashMapId)	{
1147
		HashMap hm = null;
1148
		if (hashMapId.equals("hmIdentite"))	{
1149
			hm = hmIdentite;
1150
		} else if (hashMapId.equals("hmAdresse")){
1151
			hm = hmAdresse;
1152
		} else {
1153
			hm = hmInfosNat;
1154
		}
1155
 
1156
		ListStore<Valeur> store = ((ComboBox) hm.get(idComboBox)).getStore();
376 gduche 1157
 
293 gduche 1158
		store.removeAll();
1159
		store.add(liste);
1160
		((ComboBox) hm.get(idComboBox)).setStore(store);
1161
	}
130 gduche 1162
 
668 gduche 1163
	private void gererEtatActivationBouton()	{
850 gduche 1164
	/*	if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie() == false)	{
668 gduche 1165
			enregistrer.setEnabled(false);
1166
			enregistrerEtRevenir.setEnabled(false);
1167
		} else	{
1168
			enregistrer.setEnabled(true);
1169
			enregistrerEtRevenir.setEnabled(true);
850 gduche 1170
		}*/
668 gduche 1171
	}
1172
 
850 gduche 1173
	public void reinitialiserFormulaire()	{
461 gduche 1174
		mediateur.afficherPopinChargement();
776 gduche 1175
		mettreAJourPersonne(personneSauvegarde);
376 gduche 1176
		mediateur.masquerPopinChargement();
1177
	}
1178
 
1179
	public void binderPersonne(Personne personne)	{
1239 cyprien 1180
 
1181
Debug.log("|> BEGIN PersonneForm.binderPersonne()");
1182
 
850 gduche 1183
		binding = new FormBinding(getFormulaire());
731 jp_milcent 1184
 
376 gduche 1185
		personneSelectionnee = personne;
1186 gduche 1186
 
1187
		FieldBinding f = new FieldBinding((RadioGroup) hmIdentite.get("rbgDeces"), null);
376 gduche 1188
		binding.autoBind();
1186 gduche 1189
		binding.removeFieldBinding(f);
1190
 
376 gduche 1191
		binding.bind(personneSelectionnee);
1192
		layout();
1239 cyprien 1193
 
1194
Debug.log("|> END PersonneForm.binderPersonne()");
1195
 
376 gduche 1196
	}
973 gduche 1197
 
376 gduche 1198
	private String obtenirValeurCombo(String strComboName)	{
1199
		String strValeur = "";
1200
		Valeur valeur;
1201
 
973 gduche 1202
		ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur(strComboName);
376 gduche 1203
		if (combo == null)	{
976 gduche 1204
			combo = hmAdresse.getComboBoxValeur(strComboName);
376 gduche 1205
		}
829 gduche 1206
		strValeur = combo.getRawValue();
1026 gduche 1207
		valeur = combo.getValue();
829 gduche 1208
		if (valeur != null)	{
1209
			strValeur = valeur.getId();
1210
		}
1211
 
376 gduche 1212
		return strValeur;
1213
	}
850 gduche 1214
 
934 jpm 1215
	public boolean soumettreFormulaire() {
1014 gduche 1216
		tiPubli.collecter();
850 gduche 1217
		if (verifierFormulaire())	{
991 gduche 1218
			tiPubli.soumettre();
850 gduche 1219
			mediateur.enregistrerPersonne(this, personneSelectionnee);
1220
		}
1221
		return true;
1222
	}
1223
 
934 jpm 1224
	public boolean verifierFormulaire() {
884 jpm 1225
		boolean success = true;
1226
		LinkedList<String> lstMessageErreur = new LinkedList<String>();
850 gduche 1227
 
973 gduche 1228
		ComboBox<Projet> cbProjets = hmIdentite.getComboBox("cbProjets");
850 gduche 1229
		Projet projet = cbProjets.getValue();
1230
		if (projet == null)	{
1231
			lstMessageErreur.add("Le projet n'a pas été renseigné");
1232
		} else {
1233
			personneSelectionnee.set("ce_projet", projet.getId());
1234
		}
1235
 
973 gduche 1236
		String strTfNom = (String) hmIdentite.getTextField("tfNom").getValue();
850 gduche 1237
		if ((strTfNom == null)||(strTfNom.trim().equals("")))	{
1238
			lstMessageErreur.add("Le nom n'a pas été saisi");
1239
		} else {
1240
			strTfNom = UtilString.ucFirst(strTfNom);
1241
			personneSelectionnee.set("nom", strTfNom);
1242
		}
1243
 
973 gduche 1244
		String strTfPrenom = (String) hmIdentite.getTextField("tfPrenom").getValue();
850 gduche 1245
		personneSelectionnee.set("prenom", UtilString.ucFirst(strTfPrenom));
1246
 
1247
		//Préparer les données
973 gduche 1248
		ComboBox<Valeur> combo = hmIdentite.getComboBoxValeur("cbSexe");
850 gduche 1249
		Valeur valeur;
1250
		String strValeur = "";
1251
 
973 gduche 1252
		valeur = combo.getValue();
850 gduche 1253
		if (valeur!=null)	{
1254
			personneSelectionnee.set("ce_sexe", valeur.getId());
1255
		}
1256
 
1257
		strValeur = obtenirValeurCombo("cbPrefixe");
1258
		personneSelectionnee.set("ce_truk_prefix", strValeur);
1259
 
1260
		strValeur = obtenirValeurCombo("cbSuffixe");
1261
		personneSelectionnee.set("ce_truk_suffix", strValeur);
1262
 
973 gduche 1263
		String nomAutre = hmIdentite.getChampMultiValeurs("nomAutre").getValeurs();
850 gduche 1264
		personneSelectionnee.set("truk_nom_autre", nomAutre);
1265
 
973 gduche 1266
		String abreviationAutre = hmIdentite.getChampMultiValeurs("abreviationAutre").getValeurs();
850 gduche 1267
		personneSelectionnee.set("truk_abreviation_autre", abreviationAutre);
1268
 
973 gduche 1269
		personneSelectionnee.set("truk_courriel", hmIdentite.getChampMultiValeurs("courriels").getValeurs());
850 gduche 1270
 
1271
 
1272
		//Pour le nom complet, on enregistre dans la bdd la valeur du prefixe/suffixe et non l'id
1273
		String strPrefixe = "";
973 gduche 1274
		combo = hmIdentite.getComboBoxValeur("cbPrefixe");
1275
		valeur = combo.getValue();
850 gduche 1276
		if (valeur != null)	{
1277
			strPrefixe = valeur.getNom();
1278
		} else {
1279
			strPrefixe = combo.getRawValue();
1280
		}
1281
 
1282
		String strSuffixe = "";
973 gduche 1283
		combo = hmIdentite.getComboBox("cbSuffixe");
1284
		valeur = combo.getValue();
850 gduche 1285
		if (valeur != null)	{
1286
			strSuffixe = valeur.getNom() + " ";
1287
		} else {
1288
			strSuffixe = combo.getRawValue() +" ";
1289
		}
1290
 
1291
		personneSelectionnee.setFmtNomComplet(strPrefixe, strSuffixe);
1292
 
973 gduche 1293
		DateField dfDateNaissance = hmIdentite.getDateField("dfDateNaissance");
850 gduche 1294
		Date naissanceDate = dfDateNaissance.getValue();
1295
		personneSelectionnee.setNaissanceDate(naissanceDate);
1296
 
973 gduche 1297
		Radio rbEstDecedee = hmIdentite.getRadio("rbEstDecedee");
850 gduche 1298
		if (rbEstDecedee.getValue() == true)	{
973 gduche 1299
			DateField dfDecesDate = hmIdentite.getDateField("dfDateDeces");
1300
			String decesLieu = (String) hmIdentite.getTextField("tfLieuDeces").getValue();
850 gduche 1301
			personneSelectionnee.setDeces(dfDecesDate.getValue(), decesLieu);
1302
		}	else	{
1303
			personneSelectionnee.setNonDecedee();
1304
		}
1305
 
1306
		strValeur = obtenirValeurCombo("cbPays");
1307
		personneSelectionnee.set("ce_truk_pays", strValeur);
1308
 
1026 gduche 1309
		strValeur = obtenirValeurCombo("cbRegion");
1036 gduche 1310
		ComboBox<Valeur> cbRegions = hmAdresse.getComboBoxValeur("cbRegion");
1311
		if (cbRegions.getStore().findModel("id", strValeur) == null)	{
1312
			strValeur = "AUTRE##" + strValeur;
1313
		}
850 gduche 1314
		personneSelectionnee.set("ce_truk_region", strValeur);
1315
 
973 gduche 1316
		personneSelectionnee.set("truk_telephone", hmIdentite.getChampMultiValeursMultiTypes("telephones").getValeurs());
850 gduche 1317
 
973 gduche 1318
		String logoUrls = hmIdentite.getChampMultiValeursImage("logos").getValeurs();
850 gduche 1319
		personneSelectionnee.set("truk_logo", logoUrls);
1320
 
973 gduche 1321
		personneSelectionnee.set("truk_url", hmIdentite.getChampMultiValeurs("sites").getValeurs());
850 gduche 1322
 
1323
		//Infos Naturalistes
1324
		String recolte = ((ChampMultiValeursMultiTypes) hmInfosNat.get("recolte")).getValeurs();
1325
		personneSelectionnee.set("truk_recolte", recolte);
1326
 
1327
		String specialite = ((ChampMultiValeurs) hmInfosNat.get("specialite")).getValeurs();
1328
		personneSelectionnee.set("ce_truk_specialite", specialite);
1329
 
1014 gduche 1330
		lstMessageErreur.addAll(tiPubli.verifier());
850 gduche 1331
 
884 jpm 1332
		if (lstMessageErreur.size() != 0)	{
850 gduche 1333
			String strMessagesErreur = "<span><br />";
1334
			Iterator<String> itMessagesErreur = lstMessageErreur.iterator();
1335
			while (itMessagesErreur.hasNext())	{
1336
				strMessagesErreur += "<br /> - " + itMessagesErreur.next();
1337
			}
1338
			strMessagesErreur += "</span>";
1339
 
1340
 			MessageBox.alert("Erreurs", "Les erreurs suivantes ont été commises : \n" + strMessagesErreur, null);
1341
 			success = false;
1342
		}
1343
 
1344
		return success;
1345
	}
127 gduche 1346
}