Subversion Repositories eFlore/Applications.coel

Rev

Rev 936 | Rev 977 | 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;
150 gduche 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
 
435 gduche 9
import org.tela_botanica.client.ComposantId;
305 gduche 10
import org.tela_botanica.client.Mediateur;
150 gduche 11
import org.tela_botanica.client.RegistreId;
907 jpm 12
import org.tela_botanica.client.configuration.Configuration;
150 gduche 13
import org.tela_botanica.client.interfaces.Rafraichissable;
305 gduche 14
import org.tela_botanica.client.modeles.Valeur;
15
import org.tela_botanica.client.modeles.ValeurListe;
935 jpm 16
import org.tela_botanica.client.modeles.personne.Personne;
915 jpm 17
import org.tela_botanica.client.util.Debug;
936 jpm 18
import org.tela_botanica.client.vues.DetailVue;
527 gduche 19
 
150 gduche 20
import com.extjs.gxt.ui.client.Registry;
21
import com.extjs.gxt.ui.client.Style.Scroll;
435 gduche 22
import com.extjs.gxt.ui.client.util.Format;
23
import com.extjs.gxt.ui.client.util.Params;
215 aurelien 24
import com.extjs.gxt.ui.client.widget.ContentPanel;
527 gduche 25
import com.extjs.gxt.ui.client.widget.Html;
189 gduche 26
import com.extjs.gxt.ui.client.widget.TabItem;
27
import com.extjs.gxt.ui.client.widget.TabPanel;
197 gduche 28
import com.extjs.gxt.ui.client.widget.form.FieldSet;
246 gduche 29
import com.extjs.gxt.ui.client.widget.form.LabelField;
527 gduche 30
import com.extjs.gxt.ui.client.widget.layout.AnchorLayout;
150 gduche 31
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
197 gduche 32
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
33
import com.google.gwt.user.client.ui.Image;
150 gduche 34
 
527 gduche 35
public class PersonneDetailVue extends DetailVue implements Rafraichissable {
150 gduche 36
 
269 gduche 37
	private TabPanel tabPanel;
527 gduche 38
	private Html entete;
915 jpm 39
 
215 aurelien 40
	private TabItem tabIdentite;
200 gduche 41
	private TabItem tabAdresse;
215 aurelien 42
	private TabItem tabInfosNat;
435 gduche 43
	private TabItem tabLogos;
820 gduche 44
 
915 jpm 45
	private HashMap hmLabelFieldRegion = new HashMap();
46
 
47
	private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);
48
	private boolean ontologieRecue = false;
49
	private Personne personneAAfficher = null;
50
 
51
 
820 gduche 52
	private void chargerOntologie() {
53
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
54
	}
435 gduche 55
 
820 gduche 56
 
527 gduche 57
	public PersonneDetailVue(Mediateur mediateur) {
58
		super(mediateur);
820 gduche 59
		chargerOntologie();
435 gduche 60
 
820 gduche 61
		mediateur.obtenirListeValeurEtRafraichir(this, "pays");
62
 
63
		setLayout(new FitLayout());
64
 
527 gduche 65
		entete = new Html();
66
		entete.setId(ComposantId.ZONE_DETAIL_ENTETE);
820 gduche 67
 
527 gduche 68
		ContentPanel panneauPrincipal = new ContentPanel();
69
		panneauPrincipal.setLayout(new FitLayout());
70
		panneauPrincipal.setHeaderVisible(false);
71
		panneauPrincipal.setBodyBorder(true);
72
		panneauPrincipal.setTopComponent(entete);
820 gduche 73
 
915 jpm 74
		tabIdentite = new TabItem(i18nC.personneIdentite());
527 gduche 75
		tabIdentite.setLayout(new AnchorLayout());
820 gduche 76
		tabIdentite.setScrollMode(Scroll.AUTO);
77
 
915 jpm 78
		tabAdresse = new TabItem(i18nC.personneAdresses());
472 gduche 79
		tabAdresse.setLayout(new FitLayout());
80
		tabAdresse.setScrollMode(Scroll.AUTO);
820 gduche 81
 
915 jpm 82
		tabInfosNat = new TabItem(i18nC.personneInfoNat());
321 gduche 83
		tabInfosNat.setScrollMode(Scroll.AUTO);
820 gduche 84
 
915 jpm 85
		tabLogos = new TabItem(i18nC.personneLogos());
680 gduche 86
		tabLogos.setScrollMode(Scroll.AUTO);
435 gduche 87
		tabLogos.setLayout(new FlowLayout());
820 gduche 88
 
527 gduche 89
		tabPanel = new TabPanel();
90
		tabPanel.setId(ComposantId.ZONE_DETAIL_CORPS);
91
		tabPanel.setBodyBorder(false);
820 gduche 92
 
527 gduche 93
		tabPanel.add(tabIdentite);
94
		tabPanel.add(tabAdresse);
95
		tabPanel.add(tabInfosNat);
435 gduche 96
		tabPanel.add(tabLogos);
820 gduche 97
 
527 gduche 98
		panneauPrincipal.add(tabPanel);
99
		add(panneauPrincipal);
150 gduche 100
	}
101
 
102
	public void afficherDetailPersonne(Personne personne) {
103
		if (personne != null) {
527 gduche 104
			String tplEntete = initialiserTplEntete();
820 gduche 105
 
435 gduche 106
			Params enteteParams = new Params();
107
			enteteParams.set("nom", (String) personne.get("fmt_nom_complet"));
947 gduche 108
			enteteParams.set("mail", (String) personne.getCourrielPrinc());
820 gduche 109
 
110
			LinkedList lstLogos = (LinkedList) personne
111
					.getChaineDenormaliseAsMapOrList("truk_logo");
112
			if (lstLogos != null && lstLogos.size() > 0) {
113
 
435 gduche 114
				tabLogos.removeAll();
115
				String urlLogoPrinc = (String) lstLogos.get(0);
820 gduche 116
				if (!urlLogoPrinc.trim().equals("")) {
117
					tplEntete = "<div id='personne-logo-div'><img src='{image}' alt='logo' /></div>"
118
							+ tplEntete;
435 gduche 119
					enteteParams.set("image", urlLogoPrinc);
253 gduche 120
				}
820 gduche 121
 
435 gduche 122
				Iterator<String> itLogo = lstLogos.iterator();
820 gduche 123
				while (itLogo.hasNext()) {
435 gduche 124
					String urlLogoCourant = itLogo.next();
125
					Image imgCourante = new Image(urlLogoCourant);
820 gduche 126
					tabLogos.add(imgCourante);
435 gduche 127
				}
527 gduche 128
				tabLogos.enable();
820 gduche 129
 
435 gduche 130
			} else {
472 gduche 131
				enteteParams.set("image", "");
435 gduche 132
				tabLogos.disable();
472 gduche 133
			}
820 gduche 134
 
915 jpm 135
			entete.el().setInnerHtml(Format.substitute(tplEntete, enteteParams));
820 gduche 136
 
527 gduche 137
			String tplIdentite = initialiserTplIdentite();
820 gduche 138
 
435 gduche 139
			Params tabIdentiteParams = new Params();
828 gduche 140
			tabIdentiteParams.set("nom_complet", personne.getString("fmt_nom_complet"));
141
			tabIdentiteParams.set("abreviation", personne.getString("abreviation"));
142
			tabIdentiteParams.set("naissance_date", personne.getNaissanceDate());
143
			tabIdentiteParams.set("naissance_lieu", personne.getString("naissance_lieu"));
144
			String tplDeces = "";
145
			if (personne.estDecedee())	{
146
				tplDeces = " <h2>Décès:</h2>"
147
						+ " <span><b>"
915 jpm 148
						+ i18nC.personneDateDeces()
828 gduche 149
						+ ":</b></span> {deces_date}<br />"
150
						+ " 	 <span><b>"
915 jpm 151
						+ i18nC.personneLieuDeces()
828 gduche 152
						+ ":</b></span> {deces_lieu}<br /><br />";
153
 
154
				tabIdentiteParams.set("deces_date", personne.getDecesDate());
155
				tabIdentiteParams.set("deces_lieu", personne.getString("deces_lieu"));
156
			}
157
 
158
			Params paramsDeces = new Params();
159
			paramsDeces.set("tplDeces", tplDeces);
160
			tplIdentite = Format.substitute(tplIdentite, paramsDeces);
161
 
162
			tabIdentiteParams.set("description", personne.getString("description"));
820 gduche 163
 
321 gduche 164
			tabInfosNat.removeAll();
820 gduche 165
 
166
			tabIdentiteParams.set("nom_autre", construireTxtTruck(personne.getString("truk_nom_autre")));
167
			tabIdentiteParams.set("abreviation_autre", construireTxtTruck(personne.getString("truk_abreviation_autre")));
168
 
169
			HashMap<String, String> mapTelephones = (HashMap<String, String>) personne
170
					.getChaineDenormaliseAsMapOrList("truk_telephone");
171
			if ((mapTelephones != null) && (mapTelephones.size() > 0)) {
172
 
253 gduche 173
				Collection<String> telephoneKeys = mapTelephones.keySet();
174
				Iterator<String> itTelephones = telephoneKeys.iterator();
820 gduche 175
 
176
				while (itTelephones.hasNext()) {
253 gduche 177
					String key = itTelephones.next();
472 gduche 178
					String label = mapTelephones.get(key);
820 gduche 179
 
253 gduche 180
					try {
915 jpm 181
						label = i18nC.getString(label);
820 gduche 182
					} catch (MissingResourceException e) {
253 gduche 183
					}
820 gduche 184
 
527 gduche 185
					tplIdentite += "<b>" + label + ":</b> " + key;
186
					tplIdentite += "<br />";
253 gduche 187
				}
215 aurelien 188
			}
820 gduche 189
 
190
			// Courriel :Champ truk de la forme
191
			// "Adresse@adr.com;; adr2@adr.fr ..."
192
			LinkedList<String> listeCourriel = (LinkedList<String>) personne
193
					.getChaineDenormaliseAsMapOrList("truk_courriel");
194
			if ((listeCourriel != null) && (listeCourriel.size() > 0)) {
253 gduche 195
				String strLabelCourriel = "Courriel";
820 gduche 196
				if (listeCourriel.size() > 1) {
197
					strLabelCourriel += "s";
253 gduche 198
				}
820 gduche 199
 
253 gduche 200
				String valeurCourriel = "";
201
				Iterator<String> itCourriel = listeCourriel.iterator();
820 gduche 202
				while (itCourriel.hasNext()) {
253 gduche 203
					String valeurCourante = itCourriel.next();
820 gduche 204
					valeurCourriel += "<br /><a href=\"mailto:"
205
							+ valeurCourante + "\">" + valeurCourante + "</a>";
253 gduche 206
				}
527 gduche 207
				tplIdentite += valeurCourriel;
253 gduche 208
			}
472 gduche 209
 
260 gduche 210
			// Url Site Webs
820 gduche 211
			LinkedList listeUrl = (LinkedList) personne
212
					.getChaineDenormaliseAsMapOrList("truk_url");
213
			if (listeUrl != null && listeUrl.size() > 0) {
214
 
527 gduche 215
				tplIdentite += "<br /><br /><b>Sites web:</b><br /><span style='display:inline-block'>";
260 gduche 216
				String strUrl = "";
217
				Iterator<String> urlIt = listeUrl.iterator();
820 gduche 218
				while (urlIt.hasNext()) {
260 gduche 219
					String urlCourante = urlIt.next();
820 gduche 220
					strUrl += "<a href=\"" + urlCourante + "\">" + urlCourante
221
							+ "</a> <br/>";
260 gduche 222
				}
527 gduche 223
				tplIdentite += strUrl + "</span><br />";
820 gduche 224
			}
225
 
527 gduche 226
			tplIdentite += "</div>";
820 gduche 227
 
527 gduche 228
			afficherOnglet(tplIdentite, tabIdentiteParams, tabIdentite);
820 gduche 229
 
230
			String tabAdresseTpl = "<div class='{css_corps}'>"
231
					+ "	<div class='{css_fieldset}'>"
232
					+ "		<h2>Adresse personnelle:</h2>"
233
					+ "		{adresse01} <br />" + "		{adresse02} <br />"
234
					+ "		{boitePostale}<br />"
235
					+ "		{codePostal} {region}<br />"
236
					+ "		<span style='uppercase'>{pays}</span><br />"
237
					+ "</div>";
238
			// Adresses :
472 gduche 239
			Params paramAdresseTpl = new Params();
820 gduche 240
			paramAdresseTpl.set("adresse01", (String) personne
241
					.obtenirValeurChamp("adresse_01"));
242
			paramAdresseTpl.set("adresse02", (String) personne
243
					.obtenirValeurChamp("adresse_02"));
244
			paramAdresseTpl.set("boitePostale", (String) personne
245
					.obtenirValeurChamp("bp"));
246
			paramAdresseTpl.set("codePostal", (String) personne
247
					.obtenirValeurChamp("code_postal"));
248
			paramAdresseTpl.set("ville", (String) personne
249
					.obtenirValeurChamp("ville"));
250
			paramAdresseTpl.set("region", (String) personne
251
					.obtenirValeurChamp("region"));
252
			paramAdresseTpl.set("pays", (String) personne
253
					.obtenirValeurChamp("pays"));
254
 
472 gduche 255
			afficherOnglet(tabAdresseTpl, paramAdresseTpl, tabAdresse);
256
			tabAdresse.setStyleAttribute("padding", "15px");
215 aurelien 257
 
472 gduche 258
			// Infos naturalistes :Biographie, Spécialité (typé)
820 gduche 259
			String tplInfosNat = "<div class='{css_corps}'>"
260
					+ "	<div class='{css_fieldset}'>" + "		<h2>"
915 jpm 261
					+ i18nC.personneSpecialite() + "</h1>"
820 gduche 262
					+ "			{specialites}" + "		<h2>"
915 jpm 263
					+ i18nC.personneRecolte() + "</h2>"
820 gduche 264
					+ "		{recoltes}" + "  </div>" + "</div>";
527 gduche 265
			Params prmInfosNat = new Params();
820 gduche 266
 
267
			// TODO : replace id region par valeur
268
 
797 gduche 269
			String specialite = construireTxtTruck(personne.getSpecialite());
270
			prmInfosNat.set("specialites", specialite);
820 gduche 271
 
272
			String recolte = construireTxtListeOntologie(personne.getString("truk_recolte"));
797 gduche 273
			prmInfosNat.set("recoltes", recolte);
820 gduche 274
 
797 gduche 275
			afficherOnglet(tplInfosNat, prmInfosNat, tabInfosNat);
276
			tabAdresse.setStyleAttribute("padding", "15px");
820 gduche 277
 
305 gduche 278
			changerLabelRegions();
150 gduche 279
			layout();
820 gduche 280
		}
197 gduche 281
	}
820 gduche 282
 
283
	public String initialiserTplEntete() {
284
		return "<div id='{css_id}'>" + "<h1>{nom}</h1>"
285
				+ "<h2><a href='{mail}'>{mail}</a></h2>" + "</div>";
472 gduche 286
	}
820 gduche 287
 
527 gduche 288
	public String initialiserTplIdentite() {
820 gduche 289
		return "<div class='{css_corps}'>" + "	<div class='{css_fieldset}'>"
290
				+ "	 <h2>Noms:</h2>" + "	 <span><b>"
915 jpm 291
				+ i18nC.personneNomComplet()
820 gduche 292
				+ ":</b></span> {nom_complet}<br />"
293
				+ "	 <span><b>"
915 jpm 294
				+ i18nC.personneNomAutre()
820 gduche 295
				+ ":</b></span> {nom_autre}<br />"
296
				+ "	 <span><b>"
915 jpm 297
				+ i18nC.personneAbreviation()
820 gduche 298
				+ ":</b></span> {abreviation}<br />"
299
				+ " 	 <span><b>"
915 jpm 300
				+ i18nC.personneAbreviationAutre()
820 gduche 301
				+ ":</b></b></span> {abreviation_autre}<br /><br />"
302
				+ "	 <h2>Naissance:</h2>"
303
				+ " 	 <span><b>"
915 jpm 304
				+ i18nC.personneDateNaissance()
828 gduche 305
				+ ":</b></span> {naissance_date}<br />"
820 gduche 306
				+ " 	 <span><b>"
915 jpm 307
				+ i18nC.personneLieuNaissance()
820 gduche 308
				+ ":</b></span> {naissance_lieu}<br /><br />"
828 gduche 309
				+ "{tplDeces}"
820 gduche 310
				+ " 	</div>"
311
				+ "</div>"
312
				+ "<div class='{css_corps}'>"
313
				+ "	<div class='css_fieldset'> "
314
				+ "	<h2>Description:</h2>"
315
				+ " 		{description}<br />" + "	</div>" + "<br />";
527 gduche 316
	}
820 gduche 317
 
318
	private void changerLabelRegions() {
321 gduche 319
		Collection<String> colClesComposants = hmLabelFieldRegion.keySet();
305 gduche 320
		Iterator<String> itComposants = colClesComposants.iterator();
820 gduche 321
 
322
		while (itComposants.hasNext()) {
305 gduche 323
			String region = itComposants.next();
324
			mediateur.obtenirValeurEtRafraichir(this, "region", region);
325
		}
326
	}
197 gduche 327
 
820 gduche 328
	private void ajouterLabelField(FieldSet fs, String tfLabel, Object tfValue) {
329
		if ((tfValue != null) && (!tfValue.toString().trim().equals(""))) {
330
 
246 gduche 331
			LabelField tf = new LabelField();
820 gduche 332
 
246 gduche 333
			tf.setFieldLabel(tfLabel + ":");
820 gduche 334
			if ((tfLabel == null) || ("".equals(tfLabel))) {
197 gduche 335
				tf.setHideLabel(true);
336
				tf.setStyleAttribute("margin", "0 0 0 105px");
337
			}
338
			tf.setValue(tfValue);
820 gduche 339
 
340
			// Ajout au fieldSet
200 gduche 341
			fs.add(tf);
342
		}
343
	}
344
 
305 gduche 345
	public void rafraichir(Object nouvellesDonnees) {
227 aurelien 346
		// Si on a reçu une personne on en affiche les détails
305 gduche 347
		if (nouvellesDonnees instanceof Personne) {
915 jpm 348
			personneAAfficher = (Personne) nouvellesDonnees;
820 gduche 349
		} else if (nouvellesDonnees instanceof ValeurListe) {
350
			ValeurListe ontologieReceptionnee = (ValeurListe) nouvellesDonnees;
351
			ajouterListeValeursAOntologie(ontologieReceptionnee);
352
			ontologieRecue = true;
353
 
354
			// Remplacer ci-dessous par Ontologie
305 gduche 355
			ValeurListe listeValeur = (ValeurListe) nouvellesDonnees;
820 gduche 356
			if (listeValeur.getId().equals(config.getListeId("region"))) {
357
 
305 gduche 358
				Collection colCleListeValeur = listeValeur.keySet();
359
				Iterator<String> itLv = colCleListeValeur.iterator();
820 gduche 360
				while (itLv.hasNext()) {
305 gduche 361
					String idRegion = itLv.next();
362
					Valeur region = listeValeur.get(idRegion);
820 gduche 363
 
364
					if (region != null) {
365
 
305 gduche 366
						String strRegionId = region.getAbreviation();
820 gduche 367
 
321 gduche 368
						LinkedList<LabelField> listComposantsRegion = (LinkedList) hmLabelFieldRegion.get(strRegionId);
820 gduche 369
						for (int i = 0; i < listComposantsRegion.size(); i++) {
305 gduche 370
							LabelField lfRegion = listComposantsRegion.get(i);
820 gduche 371
							lfRegion.setFieldLabel(region.getNom());
305 gduche 372
						}
820 gduche 373
 
305 gduche 374
					}
375
				}
376
			}
377
		}
915 jpm 378
 
379
		if (ontologieRecue && personneAAfficher != null)	{
380
			afficherDetailPersonne(personneAAfficher);
381
		}
150 gduche 382
	}
383
 
197 gduche 384
}