Subversion Repositories eFlore/Applications.coel

Rev

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

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