Subversion Repositories eFlore/Applications.coel

Rev

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