Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
150 gduche 1
package org.tela_botanica.client.vues;
2
 
253 gduche 3
import java.util.Collection;
197 gduche 4
import java.util.HashMap;
5
import java.util.Iterator;
253 gduche 6
import java.util.LinkedList;
7
import java.util.MissingResourceException;
189 gduche 8
 
197 gduche 9
 
439 gduche 10
import org.tela_botanica.client.ComposantClass;
435 gduche 11
import org.tela_botanica.client.ComposantId;
305 gduche 12
import org.tela_botanica.client.Mediateur;
150 gduche 13
import org.tela_botanica.client.RegistreId;
253 gduche 14
import org.tela_botanica.client.i18n.Constantes;
150 gduche 15
import org.tela_botanica.client.interfaces.Rafraichissable;
305 gduche 16
import org.tela_botanica.client.modeles.Configuration;
150 gduche 17
import org.tela_botanica.client.modeles.Personne;
305 gduche 18
import org.tela_botanica.client.modeles.Valeur;
19
import org.tela_botanica.client.modeles.ValeurListe;
259 gduche 20
import org.tela_botanica.client.util.UtilTruk;
150 gduche 21
 
22
import com.extjs.gxt.ui.client.Registry;
23
import com.extjs.gxt.ui.client.Style.Scroll;
253 gduche 24
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
435 gduche 25
import com.extjs.gxt.ui.client.util.Format;
26
import com.extjs.gxt.ui.client.util.Params;
215 aurelien 27
import com.extjs.gxt.ui.client.widget.ContentPanel;
435 gduche 28
import com.extjs.gxt.ui.client.widget.Html;
269 gduche 29
import com.extjs.gxt.ui.client.widget.LayoutContainer;
189 gduche 30
import com.extjs.gxt.ui.client.widget.TabItem;
31
import com.extjs.gxt.ui.client.widget.TabPanel;
435 gduche 32
import com.extjs.gxt.ui.client.widget.Text;
197 gduche 33
import com.extjs.gxt.ui.client.widget.form.FieldSet;
246 gduche 34
import com.extjs.gxt.ui.client.widget.form.LabelField;
435 gduche 35
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
36
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
150 gduche 37
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
197 gduche 38
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
39
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
435 gduche 40
import com.extjs.gxt.ui.client.widget.layout.RowData;
41
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
253 gduche 42
import com.extjs.gxt.ui.client.widget.layout.TableData;
197 gduche 43
import com.extjs.gxt.ui.client.widget.layout.TableLayout;
280 gduche 44
 
253 gduche 45
import com.google.gwt.core.client.GWT;
435 gduche 46
import com.google.gwt.i18n.client.DateTimeFormat;
197 gduche 47
import com.google.gwt.user.client.ui.Image;
150 gduche 48
 
436 gduche 49
public class PersonneDetailVue extends LayoutContainer implements Rafraichissable {
150 gduche 50
 
435 gduche 51
 
52
	private LayoutContainer lcDetailHaut;
53
 
197 gduche 54
	// Le panneau détail se compose de formulaires tabulés
269 gduche 55
	private TabPanel tabPanel;
189 gduche 56
 
197 gduche 57
	// Onglet 1 : identite & contact
215 aurelien 58
	private TabItem tabIdentite;
59
 
197 gduche 60
	private FieldSet fsIdentite;
61
	private FieldSet fsContact;
189 gduche 62
 
200 gduche 63
	// Onglet 2 : Adresses
64
	private TabItem tabAdresse;
65
	private FieldSet fsAdressePerso;
198 gduche 66
		// contient : adresse perso / adresse pro
67
 
215 aurelien 68
	// Onglet 3 : Informations naturalistes
69
	private TabItem tabInfosNat;
269 gduche 70
	private FieldSet fsSpec;
198 gduche 71
 
435 gduche 72
	//Onglet 4 : logos
73
	private TabItem tabLogos;
74
 
75
 
305 gduche 76
	private Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
267 gduche 77
 
435 gduche 78
 
439 gduche 79
	//Templatesstyle='display:inline-block; padding-left:15px; width:70%; font-size:11px'
80
	private String enteteTpl = "<div id='{css_id}'>"+
435 gduche 81
							   "<h1>{nom}</h1>"+
439 gduche 82
							   "<h2><a href='{mail}'>{mail}</a></h2>" +
83
							   "</div>";
435 gduche 84
 
85
 
86
	private String tabIdentiteTpl = "<div class='coel-fieldset'>" +
87
									"		<span><b>Nom Complet:</b></span> {nom_complet}<br />" +
88
									"		<span><b>Autres noms:</b></span> {nom_autre}<br />" +
89
									"		<span><b>Abréviation:</b></span> {abreviation}<br />" +
90
									"		<span><b>Autres Abréviations:</b></b></span> {abreviation_autre}<br /><br />" +
91
									"		<span><b>Date de naissance</b></span> {naissance_date}<br />" +
92
									"		<span><b>Lieu de naissance:</b></span> {naissance_lieu}<br /><br />" +
93
									"		<span><b>Date de décès:</b></span> {deces_date}<br />" +
94
									"		<span><b>Lieu de décès:</b></span> {deces_lieu}<br /><br />" +
95
									"</div>" +
96
									"<div class='coel-fieldset'>" +
97
									"		<span style='vertical-align:top'><b>Description:</b></span> {description}<br />" +
98
									"</div>";
99
 
100
 
436 gduche 101
	public PersonneDetailVue() {
189 gduche 102
 
435 gduche 103
		setLayout(new RowLayout());
104
 
105
		ContentPanel cp = new ContentPanel();
106
		cp.setLayout(new FlowLayout());
107
 
108
		lcDetailHaut = new LayoutContainer();
109
		lcDetailHaut.setLayout(new RowLayout());
110
		//this.add(lcDetailHaut, new RowData(1, 0.2));
111
		cp.setTopComponent(lcDetailHaut);
112
 
113
		add(lcDetailHaut);
114
 
115
 
269 gduche 116
		tabPanel = new TabPanel();
435 gduche 117
		this.add(tabPanel, new RowData(1, 1));
269 gduche 118
 
198 gduche 119
		//Constructeur de la classe
150 gduche 120
		Registry.register(RegistreId.PANNEAU_PERSONNE_DETAIL, this);
435 gduche 121
		//setLayout(new FitLayout());
150 gduche 122
 
215 aurelien 123
		tabIdentite = new TabItem("Identité");
435 gduche 124
		tabIdentite.setLayout(new FitLayout());
215 aurelien 125
		tabIdentite.setScrollMode(Scroll.AUTO);
253 gduche 126
 
197 gduche 127
		fsIdentite = new FieldSet();
128
		fsIdentite.setLayout(new FormLayout());
129
 
130
 
131
		fsContact = new FieldSet();
132
		fsContact.setLayout(new FormLayout());
133
 
269 gduche 134
		tabPanel.add(tabIdentite);
197 gduche 135
 
200 gduche 136
		//Onglet Adresse:
259 gduche 137
		tabAdresse = new TabItem("Adresses");
200 gduche 138
		fsAdressePerso = new FieldSet();
139
		fsAdressePerso.setLayout(new FormLayout());
140
 
269 gduche 141
		tabPanel.add(tabAdresse);
200 gduche 142
 
215 aurelien 143
		//Onglet info naturalistes
144
		tabInfosNat = new TabItem("Informations naturalistes");
269 gduche 145
		fsSpec = new FieldSet();
146
		fsSpec.setLayout(new FormLayout());
321 gduche 147
		tabInfosNat.setScrollMode(Scroll.AUTO);
200 gduche 148
 
269 gduche 149
		tabPanel.add(tabInfosNat);
198 gduche 150
 
435 gduche 151
		tabLogos = new TabItem("Logos");
152
		tabLogos.setLayout(new FlowLayout());
153
 
154
		tabPanel.add(tabLogos);
150 gduche 155
	}
156
 
305 gduche 157
 
321 gduche 158
	private HashMap hmLabelFieldRegion = new HashMap();
305 gduche 159
 
150 gduche 160
	public void afficherDetailPersonne(Personne personne) {
161
		if (personne != null) {
198 gduche 162
 
163
			//MAJ Identité : Configurer les fieldSet
150 gduche 164
 
435 gduche 165
			Params enteteParams = new Params();
439 gduche 166
			enteteParams.set("css_id", ComposantId.ZONE_DETAIL_ENTETE);
167
			enteteParams.set("css_meta", ComposantClass.META);
435 gduche 168
			enteteParams.set("nom", (String) personne.get("fmt_nom_complet"));
169
			enteteParams.set("mail", (String) personne.get("courriel_princ"));
183 gduche 170
 
435 gduche 171
			LinkedList lstLogos = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_logo");
172
			if (lstLogos!=null && lstLogos.size() > 0)	{
173
 
174
				tabLogos.removeAll();
175
				String urlLogoPrinc = (String) lstLogos.get(0);
176
				if (!urlLogoPrinc.trim().equals(""))	{
177
					enteteTpl = "<div style='position:absolute; right:0; width:30%; text-align:right'><img src='{image}' alt='logo' height='45px'/></div>" + enteteTpl;
178
					enteteParams.set("image", urlLogoPrinc);
253 gduche 179
				}
246 gduche 180
 
435 gduche 181
				Iterator<String> itLogo = lstLogos.iterator();
182
				while (itLogo.hasNext()){
183
					String urlLogoCourant = itLogo.next();
184
					Image imgCourante = new Image(urlLogoCourant);
185
					tabLogos.add(imgCourante);
186
				}
187
 
188
				tabLogos.enable();
189
			} else {
190
				tabLogos.disable();
191
			}
150 gduche 192
 
435 gduche 193
			lcDetailHaut.el().setInnerHtml(Format.substitute(enteteTpl, enteteParams));
183 gduche 194
 
435 gduche 195
			Params tabIdentiteParams = new Params();
196
			tabIdentiteParams.set("nom_complet", personne.getString("fmt_nom_complet"));
197
			tabIdentiteParams.set("abreviation", personne.getString("abreviation"));
198
			tabIdentiteParams.set("naissance_date", personne.getString("naissance_date"));
199
			tabIdentiteParams.set("naissance_lieu", personne.getString("naissance_lieu"));
200
			tabIdentiteParams.set("deces_date", personne.getString("deces_date"));
201
			tabIdentiteParams.set("deces_lieu", personne.getString("deces_lieu"));
202
			tabIdentiteParams.set("description", personne.getString("description"));
203
 
215 aurelien 204
			fsAdressePerso.removeAll();
269 gduche 205
			fsSpec.removeAll();
321 gduche 206
			tabInfosNat.removeAll();
197 gduche 207
 
259 gduche 208
			// Nom autre : champ truk; non-typé
209
			LinkedList<String> nomsAutre = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_nom_autre");
435 gduche 210
			String listeNoms = "";
259 gduche 211
			if ((nomsAutre != null)&&(nomsAutre.size() > 0))	{
435 gduche 212
				listeNoms = UtilTruk.traiterTrukListe(nomsAutre, ", ");
259 gduche 213
			}
435 gduche 214
			tabIdentiteParams.set("nom_autre", listeNoms);
197 gduche 215
 
259 gduche 216
			// Abréviations, autre : non-typé
217
			LinkedList<String> abrevAutres = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_abreviation_autre");
435 gduche 218
			String listeAbrev = "";
259 gduche 219
			if ((abrevAutres != null)&&(abrevAutres.size() > 0))	{
435 gduche 220
				listeAbrev = UtilTruk.traiterTrukListe(abrevAutres, ", ");
259 gduche 221
			}
435 gduche 222
			tabIdentiteParams.set("abreviation_autre", listeAbrev);
197 gduche 223
 
435 gduche 224
			tabIdentite.el().setInnerHtml(Format.substitute(tabIdentiteTpl, tabIdentiteParams));
197 gduche 225
 
435 gduche 226
			// CONTACT > Plusieurs téléphones possible, typés
227
			Constantes constantesI18n = (Constantes) GWT.create(Constantes.class);
197 gduche 228
 
229
 
253 gduche 230
			HashMap<String, String> mapTelephones = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");
231
			if ((mapTelephones != null)&&(mapTelephones.size() > 0))	{
232
 
233
				Collection<String> telephoneKeys = mapTelephones.keySet();
234
				Iterator<String> itTelephones = telephoneKeys.iterator();
235
 
236
				while (itTelephones.hasNext())	{
237
					String key = itTelephones.next();
238
					LabelField telephoneLabel = new LabelField();
239
					String label = "";
240
					try {
241
						label = constantesI18n.getString(key);
242
					}
243
					catch (MissingResourceException e)	{
244
						label = key;
245
					}
246
 
247
					telephoneLabel.setFieldLabel( label + ":");
248
 
249
					telephoneLabel.setValue(mapTelephones.get(key));
250
 
251
					fsContact.add(telephoneLabel);
252
				}
215 aurelien 253
			}
197 gduche 254
 
253 gduche 255
			// Fax
256
			// > Plusieurs fax possible, typés
257
 
258
			HashMap<String, String> mapFax = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_fax");
259
			if ((mapFax != null)&&(mapFax.size() > 0))	{
260
 
261
				Collection<String> faxKeys = mapFax.keySet();
262
				Iterator<String> itFax = faxKeys.iterator();
263
 
264
				while (itFax.hasNext())	{
265
					String key = itFax.next();
266
					LabelField faxLabel = new LabelField();
267
					String label = "";
268
					try {
269
						label = constantesI18n.getString(key);
270
					}
271
					catch (MissingResourceException e)	{
272
						label = key;
273
					}
274
 
275
					faxLabel.setFieldLabel( label + ":");
276
 
277
					faxLabel.setValue(mapTelephones.get(key));
278
 
279
					fsContact.add(faxLabel);
280
				}
281
			}
282
 
283
			// Courriel
284
			// Courriel est un champ truk de la forme "Adresse@adr.com;; adr2@adr.fr ..."
285
 
286
			LinkedList<String> listeCourriel = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");
287
			if ((listeCourriel!=null)&&(listeCourriel.size() > 0))	{
288
				String strLabelCourriel = "Courriel";
289
				if (listeCourriel.size() > 1)	{
290
					strLabelCourriel += "s";
291
				}
292
 
293
				LabelField labelCourriel = new LabelField();
294
				labelCourriel.setFieldLabel(strLabelCourriel);
295
 
296
				String valeurCourriel = "";
297
				Iterator<String> itCourriel = listeCourriel.iterator();
298
				while (itCourriel.hasNext())	{
299
					String valeurCourante = itCourriel.next();
300
					valeurCourriel += "<a href=\"mailto:" + valeurCourante + "\">" + valeurCourante + "</a><br />";
301
 
302
				}
303
 
304
				labelCourriel.setValue(valeurCourriel);
305
				fsContact.add(labelCourriel);
306
			}
307
 
308
 
260 gduche 309
			// Url Site Webs
310
			LinkedList listeUrl = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_url");
311
			if (listeUrl!=null && listeUrl.size() > 0)	{
312
				String strUrl = "";
313
				Iterator<String> urlIt = listeUrl.iterator();
314
				while (urlIt.hasNext())	{
315
					String urlCourante = urlIt.next();
316
					strUrl += "<a href=\""+urlCourante+"\">" + urlCourante + "</a> <br/>";
317
 
318
 
319
				}
320
 
321
				LabelField urlLabelField = new LabelField();
322
				urlLabelField.setFieldLabel("Url:");
323
				urlLabelField.setValue(strUrl);
324
				fsContact.add(urlLabelField);
325
			}
326
 
435 gduche 327
			tabIdentite.setStyleAttribute("padding", "15px");
328
			//tabIdentite.add(fsContact);
260 gduche 329
 
197 gduche 330
 
215 aurelien 331
			fsAdressePerso.setHeading("Adresse personnelle");
332
 
198 gduche 333
			/*
334
			 * Adresses :
215 aurelien 335
			 * */
197 gduche 336
			String adresse01 = (String) personne.obtenirValeurChamp("adresse_01");
266 gduche 337
			ajouterLabelField(fsAdressePerso, "Adresse", adresse01);
197 gduche 338
 
339
			String adresse02 = (String) personne.obtenirValeurChamp("adresse_02");
266 gduche 340
			ajouterLabelField(fsAdressePerso, "", adresse02);
197 gduche 341
 
342
			String boitePostale = (String) personne.obtenirValeurChamp("bp");
266 gduche 343
			ajouterLabelField(fsAdressePerso, "Boite Postale", boitePostale);
197 gduche 344
 
345
			String codePostal = (String) personne.obtenirValeurChamp("code_postal");
266 gduche 346
			ajouterLabelField(fsAdressePerso, "Code postal", codePostal);
197 gduche 347
 
348
			String ville = (String) personne.obtenirValeurChamp("ville");
266 gduche 349
			ajouterLabelField(fsAdressePerso, "Ville", ville);
197 gduche 350
 
351
			String region = (String) personne.obtenirValeurChamp("region");
266 gduche 352
			ajouterLabelField(fsAdressePerso, "Région", region);
197 gduche 353
 
354
			String pays = (String) personne.obtenirValeurChamp("pays");
266 gduche 355
			ajouterLabelField(fsAdressePerso, "Pays", pays);
197 gduche 356
 
215 aurelien 357
			fsAdressePerso.addText("<br >");
358
			fsAdressePerso.setWidth("350px");
197 gduche 359
 
215 aurelien 360
			tabAdresse.add(fsAdressePerso);
246 gduche 361
 
215 aurelien 362
 
305 gduche 363
			// Infos naturalistes
260 gduche 364
 
365
			// Biographie
267 gduche 366
			// Spécialité (typé)
367
 
269 gduche 368
			fsSpec.setHeading("Spécialités");
369
			tabInfosNat.add(fsSpec);
267 gduche 370
 
371
			HashMap hmSpecialite = (HashMap) personne.getChaineDenormaliseAsMapOrList("ce_truk_specialite");
372
			if ((hmSpecialite != null)&&(hmSpecialite.size() > 0))	{
373
 
374
				Collection<String> specialiteKeys = hmSpecialite.keySet();
375
				Iterator<String> itSpec = specialiteKeys.iterator();
376
 
377
				while (itSpec.hasNext())	{
378
					String key = itSpec.next();
379
					LabelField specLabel = new LabelField();
380
					String label = "";
381
					try {
382
						label = constantesI18n.getString(key);
383
					}
384
					catch (MissingResourceException e)	{
385
						label = key;
386
					}
387
 
388
					specLabel.setFieldLabel( label + ":");
389
 
390
					specLabel.setValue(hmSpecialite.get(key));
391
 
269 gduche 392
					fsSpec.add(specLabel);
267 gduche 393
				}
394
			}
269 gduche 395
 
396
			// Récolte
397
			LinkedList<String> lstRecolte = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_recolte");
398
			if ((lstRecolte!=null)&&(lstRecolte.size()>0))	{
399
				FieldSet fsRecolte = new FieldSet();
400
				fsRecolte.setHeading("Récoltes");
401
				fsRecolte.setLayout(new FormLayout());
402
 
403
				Iterator<String> itRecolte = lstRecolte.iterator();
404
				while (itRecolte.hasNext())	{
405
 
406
					String recolteCourante = itRecolte.next();
407
					LabelField lfRecolte = new LabelField();
408
					String[] splitRecolte = recolteCourante.split("\\|");
409
 
410
					String labelRecolte = "";
411
					if (splitRecolte.length > 1)	{
280 gduche 412
						lfRecolte.setValue(splitRecolte[1]);
269 gduche 413
					}
414
 
280 gduche 415
					lfRecolte.setFieldLabel(splitRecolte[0]);
305 gduche 416
					fsRecolte.add(lfRecolte);
269 gduche 417
 
321 gduche 418
					LinkedList<LabelField> lstComposantsRegion = (LinkedList<LabelField>) hmLabelFieldRegion.get(splitRecolte[0]);
269 gduche 419
 
305 gduche 420
					if (lstComposantsRegion == null)	{
421
						lstComposantsRegion = new LinkedList<LabelField>();
422
					}
269 gduche 423
 
305 gduche 424
					lstComposantsRegion.add(lfRecolte);
321 gduche 425
					hmLabelFieldRegion.remove(splitRecolte[0]);
426
					hmLabelFieldRegion.put(splitRecolte[0], lstComposantsRegion);
305 gduche 427
 
269 gduche 428
				}
429
 
430
				tabInfosNat.add(fsRecolte);
431
			}
305 gduche 432
 
433
			changerLabelRegions();
260 gduche 434
			// tabInfosNat
150 gduche 435
			layout();
197 gduche 436
		}
437
	}
305 gduche 438
 
439
 
440
	private void changerLabelRegions()	{
441
 
321 gduche 442
		Collection<String> colClesComposants = hmLabelFieldRegion.keySet();
305 gduche 443
		Iterator<String> itComposants = colClesComposants.iterator();
444
 
445
		while (itComposants.hasNext())	{
446
			String region = itComposants.next();
447
			mediateur.obtenirValeurEtRafraichir(this, "region", region);
448
		}
449
	}
197 gduche 450
 
266 gduche 451
	private void ajouterLabelField(FieldSet fs, String tfLabel, Object tfValue)	{
197 gduche 452
 
453
		if ((tfValue!=null)&&(!tfValue.toString().trim().equals("")))	{
189 gduche 454
 
246 gduche 455
 
456
			LabelField tf = new LabelField();
197 gduche 457
 
246 gduche 458
			tf.setFieldLabel(tfLabel + ":");
197 gduche 459
			if ((tfLabel==null)||("".equals(tfLabel)))	{
460
				tf.setHideLabel(true);
461
				tf.setStyleAttribute("margin", "0 0 0 105px");
462
			}
463
			tf.setValue(tfValue);
464
 
200 gduche 465
			//Ajout au fieldSet
466
			fs.add(tf);
467
		}
468
	}
469
 
266 gduche 470
 
197 gduche 471
 
305 gduche 472
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
197 gduche 473
 
305 gduche 474
	public void rafraichir(Object nouvellesDonnees) {
227 aurelien 475
 
476
		// Si on a reçu une personne on en affiche les détails
305 gduche 477
		if (nouvellesDonnees instanceof Personne) {
478
			afficherDetailPersonne((Personne) nouvellesDonnees);
479
		} else if (nouvellesDonnees instanceof ValeurListe)	{
480
 
481
			ValeurListe listeValeur = (ValeurListe) nouvellesDonnees;
482
			if (listeValeur.getId().equals(config.getListeId("region")))	{
483
 
484
				Collection colCleListeValeur = listeValeur.keySet();
485
 
486
				Iterator<String> itLv = colCleListeValeur.iterator();
487
 
488
				while (itLv.hasNext())	{
489
					String idRegion = itLv.next();
490
					Valeur region = listeValeur.get(idRegion);
491
 
492
 
493
 
494
					if (region != null)	{
495
 
496
						String strRegionId = region.getAbreviation();
497
 
321 gduche 498
						LinkedList<LabelField> listComposantsRegion = (LinkedList) hmLabelFieldRegion.get(strRegionId);
305 gduche 499
						for (int i=0; i < listComposantsRegion.size(); i++)	{
500
							LabelField lfRegion = listComposantsRegion.get(i);
501
							lfRegion.setFieldLabel(region.getNom());
502
						}
503
 
504
					}
505
				}
506
			}
507
		}
150 gduche 508
	}
509
 
197 gduche 510
}