Subversion Repositories eFlore/Applications.coel

Rev

Rev 1308 | Rev 1328 | 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.projet;
877 aurelien 2
 
3
import java.util.ArrayList;
4
 
980 jpm 5
import org.tela_botanica.client.ComposantClass;
877 aurelien 6
import org.tela_botanica.client.Mediateur;
1115 jpm 7
import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;
1327 cyprien 8
import org.tela_botanica.client.composants.ChampComboBoxRechercheTempsReelPaginable;
1218 cyprien 9
import org.tela_botanica.client.composants.InfoLogger;
1327 cyprien 10
import org.tela_botanica.client.composants.pagination.ProxyValeur;
877 aurelien 11
import org.tela_botanica.client.interfaces.Rafraichissable;
12
import org.tela_botanica.client.modeles.Information;
13
import org.tela_botanica.client.modeles.MenuApplicationId;
1327 cyprien 14
import org.tela_botanica.client.modeles.Valeur;
935 jpm 15
import org.tela_botanica.client.modeles.projet.Projet;
928 jpm 16
import org.tela_botanica.client.util.Debug;
877 aurelien 17
import org.tela_botanica.client.util.Pattern;
18
import org.tela_botanica.client.util.UtilArray;
928 jpm 19
import org.tela_botanica.client.util.UtilString;
935 jpm 20
import org.tela_botanica.client.vues.Formulaire;
877 aurelien 21
 
1298 cyprien 22
import com.extjs.gxt.ui.client.Style.Scroll;
1327 cyprien 23
import com.extjs.gxt.ui.client.data.ModelData;
24
import com.extjs.gxt.ui.client.data.ModelType;
1118 jpm 25
import com.extjs.gxt.ui.client.event.BaseEvent;
980 jpm 26
import com.extjs.gxt.ui.client.event.Events;
1118 jpm 27
import com.extjs.gxt.ui.client.event.Listener;
928 jpm 28
import com.extjs.gxt.ui.client.widget.Info;
877 aurelien 29
import com.extjs.gxt.ui.client.widget.MessageBox;
30
import com.extjs.gxt.ui.client.widget.form.CheckBox;
31
import com.extjs.gxt.ui.client.widget.form.FieldSet;
32
import com.extjs.gxt.ui.client.widget.form.TextArea;
33
import com.extjs.gxt.ui.client.widget.form.TextField;
34
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
35
import com.extjs.gxt.ui.client.widget.layout.FormData;
36
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
37
 
38
public class ProjetForm extends Formulaire implements Rafraichissable {
39
 
40
	private Projet projet;
878 aurelien 41
 
42
	private String listeValeurIndexationDureeId = "dureesIndexation";
43
	private String listeValeurIndexationFrequenceId = "frequencesIndexation";
887 aurelien 44
	private String listeLanguesId = "langues";
878 aurelien 45
 
877 aurelien 46
	private FieldSet generalitesFieldset = null;
47
	private TextField<String> nomChp = null;
48
	private TextField<String> abreviationChp = null;
886 aurelien 49
	private TextArea descriptionChp = null;
877 aurelien 50
	private TextArea resumeChp = null;
51
	private TextField<String> urlChp = null;
52
 
53
	private FieldSet complementFieldset = null;
54
	private TextField<String> motsClesChp = null;
55
	private TextField<String> citationChp = null;
56
	private TextField<String> licenceChp = null;
1327 cyprien 57
	private ChampComboBoxRechercheTempsReelPaginable langueChp = null;
877 aurelien 58
	private CheckBox markPublicChp = null;
59
 
60
	private FieldSet indexationFieldset = null;
61
	private TextField<String> indexationHeureChp = null;
1115 jpm 62
	private ChampComboBoxListeValeurs indexationDureeChp = null;
63
	private ChampComboBoxListeValeurs indexationFrequenceChp = null;
877 aurelien 64
 
65
	private boolean formulaireValideOk = false;
66
	private boolean projetValideOk = false;
67
 
68
	private Rafraichissable vueExterneARafraichirApresValidation = null;
69
 
70
 
71
	public ProjetForm(Mediateur mediateurCourrant, String projetId) {
72
		initialiserProjetForm(mediateurCourrant, projetId);
73
	}
74
 
75
	public ProjetForm(Mediateur mediateurCourrant, String projetId, Rafraichissable vueARafraichirApresValidation) {
76
		vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
77
		initialiserProjetForm(mediateurCourrant, projetId);
78
	}
79
 
878 aurelien 80
	private void initialiserProjetForm(Mediateur mediateurCourant, String projetId) {
877 aurelien 81
		projet = new Projet();
82
		projet.setId(projetId);
83
 
84
		String modeDeCreation = (projet.getId().isEmpty() ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
878 aurelien 85
		initialiserFormulaire(mediateurCourant, modeDeCreation, MenuApplicationId.PROJET);
877 aurelien 86
 
87
		panneauFormulaire.setLayout(new FlowLayout());
1298 cyprien 88
		panneauFormulaire.setScrollMode(Scroll.AUTO);
1094 jpm 89
		genererTitreFormulaire();
877 aurelien 90
 
91
		creerZoneGeneralites();
92
		panneauFormulaire.add(generalitesFieldset);
93
 
94
		creerZoneComplement();
95
		panneauFormulaire.add(complementFieldset);
96
 
97
		creerZoneIndexation();
98
		panneauFormulaire.add(indexationFieldset);
99
 
886 aurelien 100
		creerTabIndex();
101
 
877 aurelien 102
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
928 jpm 103
			mediateur.selectionnerProjet(this, projetId);
1118 jpm 104
		}
877 aurelien 105
	}
106
 
1094 jpm 107
	private void genererTitreFormulaire() {
928 jpm 108
		String titre = i18nC.projetTitreFormAjout();
877 aurelien 109
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
1094 jpm 110
			 titre = i18nC.projetTitreFormModif();
111
			 if (projet != null) {
112
				 titre += " - "+i18nC.id()+": "+projet.getId();
113
			 }
877 aurelien 114
		}
928 jpm 115
		panneauFormulaire.setHeading(titre);
877 aurelien 116
	}
117
 
118
	private void creerZoneGeneralites() {
119
		FormLayout layout = new FormLayout();
120
		layout.setLabelWidth(100);
121
 
122
		// Fieldset Infos Générales
123
		generalitesFieldset = new FieldSet();
928 jpm 124
		generalitesFieldset.setHeading(i18nC.projetTitreInfoGenerale());
877 aurelien 125
		generalitesFieldset.setCollapsible(true);
126
		generalitesFieldset.setLayout(layout);
127
 
128
		nomChp = new TextField<String>();
129
		nomChp.setName("cpu");
1118 jpm 130
		nomChp.setFieldLabel(i18nC.projetNom());
980 jpm 131
		nomChp.addStyleName(ComposantClass.OBLIGATOIRE);
132
		nomChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
877 aurelien 133
		generalitesFieldset.add(nomChp, new FormData(450, 0));
134
 
135
		abreviationChp = new TextField<String>();
1118 jpm 136
		abreviationChp.setFieldLabel(i18nC.projetAbreviation());
981 jpm 137
		abreviationChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 138
		abreviationChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
877 aurelien 139
		generalitesFieldset.add(abreviationChp, new FormData(450, 0));
140
 
886 aurelien 141
		descriptionChp = new TextArea();
1118 jpm 142
		descriptionChp.setFieldLabel(i18nC.projetDescription());
981 jpm 143
		descriptionChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 144
		descriptionChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
877 aurelien 145
		generalitesFieldset.add(descriptionChp, new FormData(450, 0));
146
 
147
		resumeChp = new TextArea();
1118 jpm 148
		resumeChp.setFieldLabel(i18nC.projetResume());
981 jpm 149
		resumeChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 150
		resumeChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
877 aurelien 151
		generalitesFieldset.add(resumeChp, new FormData(450, 0));
152
 
153
		urlChp = new TextField<String>();
1118 jpm 154
		urlChp.setFieldLabel(i18nC.projetUrl());
877 aurelien 155
		generalitesFieldset.add(urlChp, new FormData(450, 0));
156
	}
157
 
158
	private void creerZoneComplement() {
159
		FormLayout layout = new FormLayout();
160
		layout.setLabelWidth(100);
161
 
928 jpm 162
		// Fieldset Complément
877 aurelien 163
		complementFieldset = new FieldSet();
928 jpm 164
		complementFieldset.setHeading(i18nC.projetTitreComplement());
877 aurelien 165
		complementFieldset.setCollapsible(true);
166
		complementFieldset.setLayout(layout);
167
 
168
		motsClesChp = new TextField<String>();
1115 jpm 169
		motsClesChp.setFieldLabel(i18nC.projetMotsCles());
170
		complementFieldset.add(motsClesChp, new FormData(450, 0));
877 aurelien 171
 
172
		citationChp = new TextField<String>();
1115 jpm 173
		citationChp.setFieldLabel(i18nC.projetCitation());
174
		complementFieldset.add(citationChp, new FormData(450, 0));
877 aurelien 175
 
176
		licenceChp = new TextField<String>();
1115 jpm 177
		licenceChp.setFieldLabel(i18nC.projetLicence());
178
		complementFieldset.add(licenceChp, new FormData(450, 0));
877 aurelien 179
 
1327 cyprien 180
		//langueChp = new ChampComboBoxListeValeurs(i18nC.projetLangue(), listeLanguesId);
181
		ModelType modelTypesLangues = new ModelType();
182
		modelTypesLangues.setRoot("valeurs");
183
		modelTypesLangues.setTotalName("nbElements");
184
		modelTypesLangues.addField("cmlv_nom");
185
		modelTypesLangues.addField("cmlv_id_valeur");
186
		modelTypesLangues.addField("cmlv_abreviation");
187
		modelTypesLangues.addField("cmlv_description");
887 aurelien 188
 
1327 cyprien 189
		String displayNameLangues = "cmlv_nom";
190
		String nomListeTypes = "langues";
191
		ProxyValeur<ModelData> proxyLangues = new ProxyValeur<ModelData>(nomListeTypes);
192
 
193
		langueChp = new ChampComboBoxRechercheTempsReelPaginable(proxyLangues, modelTypesLangues, displayNameLangues);
194
		langueChp.setWidth(100,300);
195
		langueChp.getCombo().setTabIndex(tabIndex++);
196
		langueChp.getCombo().setFieldLabel("Pays");
197
		langueChp.getCombo().setForceSelection(true);
198
 
199
		complementFieldset.add(langueChp, new FormData(300, 0));
200
 
877 aurelien 201
		markPublicChp = new CheckBox();
1118 jpm 202
		markPublicChp.setFieldLabel(i18nC.projetMarkPublic());
203
		markPublicChp.addListener(Events.Change, new Listener<BaseEvent>() {
204
			public void handleEvent(BaseEvent be) {
205
				if (markPublicChp.getValue()) {
206
					indexationFieldset.show();
207
				} else {
208
					indexationFieldset.hide();
209
				}
210
			}
211
		});
877 aurelien 212
		complementFieldset.add(markPublicChp);
213
	}
214
 
215
	private void creerZoneIndexation() {
216
		FormLayout layout = new FormLayout();
217
		layout.setLabelWidth(100);
218
 
928 jpm 219
		// Fieldset Indexation
877 aurelien 220
		indexationFieldset = new FieldSet();
928 jpm 221
		indexationFieldset.setHeading(i18nC.projetTitreIndexation());
877 aurelien 222
		indexationFieldset.setCollapsible(true);
223
		indexationFieldset.setLayout(layout);
1118 jpm 224
		indexationFieldset.hide();
225
		indexationFieldset.addListener(Events.Hide, new Listener<BaseEvent>() {
226
			public void handleEvent(BaseEvent be) {
227
				indexationHeureChp.clear();
228
				indexationFrequenceChp.clear();
229
				indexationDureeChp.clear();
230
			}
231
		});
877 aurelien 232
 
233
		indexationHeureChp = new TextField<String>();
878 aurelien 234
		indexationHeureChp.setFieldLabel(i18nC.projetIndexationHeure());
1115 jpm 235
		indexationHeureChp.setToolTip(i18nC.projetMessageHeureMinute());
877 aurelien 236
		indexationFieldset.add(indexationHeureChp, new FormData(80, 0));
237
 
1115 jpm 238
		indexationFrequenceChp = new ChampComboBoxListeValeurs(i18nC.projetIndexationFrequence(), listeValeurIndexationFrequenceId);
878 aurelien 239
		indexationFieldset.add(indexationFrequenceChp, new FormData(120, 0));
240
 
1115 jpm 241
		indexationDureeChp = new ChampComboBoxListeValeurs(i18nC.projetIndexationDuree(), listeValeurIndexationDureeId);
877 aurelien 242
		indexationFieldset.add(indexationDureeChp, new FormData(80, 0));
243
 
244
	}
886 aurelien 245
 
246
	private void creerTabIndex() {
887 aurelien 247
		nomChp.setTabIndex(1);
248
		abreviationChp.setTabIndex(2);
249
		descriptionChp.setTabIndex(3);
250
		resumeChp.setTabIndex(4);
251
		urlChp.setTabIndex(5);
886 aurelien 252
 
253
		motsClesChp.setTabIndex(6);
254
		citationChp.setTabIndex(7);
255
		licenceChp.setTabIndex(8);
887 aurelien 256
		langueChp.setTabIndex(9);
257
		markPublicChp.setTabIndex(10);
886 aurelien 258
 
887 aurelien 259
		indexationHeureChp.setTabIndex(11);
260
		indexationFrequenceChp.setTabIndex(12);
261
		indexationDureeChp.setTabIndex(13);
886 aurelien 262
 
263
		nomChp.focus();
264
	}
877 aurelien 265
 
266
	public void rafraichir(Object nouvellesDonnees) {
928 jpm 267
		if (nouvellesDonnees instanceof Information) {
268
			Information info = (Information) nouvellesDonnees;
269
			rafraichirInformation(info);
1115 jpm 270
		} else {
271
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
878 aurelien 272
		}
273
 
877 aurelien 274
		if (etreValide()) {
275
			initialiserValidation();
276
			repandreRafraichissement();
1218 cyprien 277
			controlerFermeture();
877 aurelien 278
		}
279
	}
280
 
928 jpm 281
	private void rafraichirInformation(Information info) {
282
		final String type = info.getType();
283
 
284
		// Gestion des problèmes
285
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
286
			Debug.log("MESSAGES:\n"+info.getMessages().toString());
287
		}
288
 
289
		// Gestion des actions
290
		if (type.equals("selection_projet")) {
291
			if (info.getDonnee(0) != null) {
292
				projet = (Projet) info.getDonnee(0);
293
			}
294
			peuplerFormulaire();
1094 jpm 295
			genererTitreFormulaire();
1102 jpm 296
		}
297
		if (type.equals("ajout_projet") || type.equals("modif_projet")) {
928 jpm 298
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
1094 jpm 299
				projetValideOk = true;
928 jpm 300
				String projetId = (String) info.getDonnee(0);
1094 jpm 301
				if (vueExterneARafraichirApresValidation != null) {
302
					projet.setId(projetId);
303
				}
928 jpm 304
			}
305
		}
306
 
307
		// Gestion des messages
308
		if (type.equals("selection_projet")) {
1218 cyprien 309
			InfoLogger.display(i18nC.projetTitreFormModif(), info.toString());
928 jpm 310
		} else if (type.equals("modif_projet")) {
1218 cyprien 311
			InfoLogger.display(i18nC.projetTitreFormModif(), info.toString());
928 jpm 312
		} else if (type.equals("ajout_projet")) {
1094 jpm 313
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
314
				String projetId = (String) info.getDonnee(0);
1218 cyprien 315
				InfoLogger.display(i18nC.projetTitreFormAjout(), "Le projet '"+projetId+"' a bien été ajouté");
1094 jpm 316
			} else {
1218 cyprien 317
				InfoLogger.display(i18nC.projetTitreFormAjout(), info.toString(), true);
928 jpm 318
			}
319
		}
877 aurelien 320
	}
928 jpm 321
 
877 aurelien 322
	private Boolean etreValide() {
323
		Boolean valide = false;
324
		if (formulaireValideOk && projetValideOk) {
325
			valide = true;
326
		}
327
		return valide;
328
	}
329
 
330
	private void initialiserValidation() {
331
		formulaireValideOk = false;
332
		projetValideOk = false;
333
	}
334
 
335
	private void repandreRafraichissement() {
336
		if (vueExterneARafraichirApresValidation != null) {
878 aurelien 337
			String type = "projet_modifie";
877 aurelien 338
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
878 aurelien 339
				type = "projet_ajoute";
877 aurelien 340
			}
341
			Information info = new Information(type);
342
			info.setDonnee(0, projet);
343
			vueExterneARafraichirApresValidation.rafraichir(info);
344
		}
345
	}
346
 
347
	public boolean soumettreFormulaire() {
348
		formulaireValideOk = verifierFormulaire();
349
		if (formulaireValideOk) {
350
			Projet projetCollecte = collecterProjet();
351
			if (projetCollecte != null) {
352
				if (mode.equals(Formulaire.MODE_AJOUTER)) {
353
					mediateur.ajouterProjet(this, projetCollecte);
354
				} else if (mode.equals(Formulaire.MODE_MODIFIER)) {
355
					mediateur.modifierProjet(this, projetCollecte);
356
				}
357
			}
358
		}
359
		return formulaireValideOk;
360
	}
361
 
934 jpm 362
	public boolean verifierFormulaire() {
877 aurelien 363
		boolean valide = true;
364
		ArrayList<String> messages = new ArrayList<String>();
365
 
366
		String titre = nomChp.getValue();
367
		if (titre == null || titre.equals("")) {
1115 jpm 368
			messages.add(i18nC.projetMessageNom());
877 aurelien 369
		}
370
 
886 aurelien 371
		String abr = abreviationChp.getValue();
1115 jpm 372
		if (abr == null || abr.equals(i18nC.projetMessageAbreviation())) {
373
			messages.add(i18nC.projetMessageAbreviation());
886 aurelien 374
		}
375
 
376
		String desc = descriptionChp.getValue();
1115 jpm 377
		if (desc == null || desc.equals(i18nC.projetMessageDescription())) {
378
			messages.add(i18nC.projetDescription());
886 aurelien 379
		}
380
 
381
		String resume = resumeChp.getValue();
1115 jpm 382
		if (resume == null || resume.equals(i18nC.projetMessageResume())) {
383
			messages.add(i18nC.projetMessageResume());
886 aurelien 384
		}
385
 
877 aurelien 386
		String uri = urlChp.getValue();
886 aurelien 387
		if (uri != null && ! uri.trim().isEmpty() && ! uri.matches(Pattern.url)) {
1115 jpm 388
			messages.add(i18nC.messageUrlNonValide());
877 aurelien 389
		}
390
 
1118 jpm 391
		if (markPublicChp.getValue()) {
392
			String heure = indexationHeureChp.getValue();
393
			if (!UtilString.isEmpty(heure) && !heure.matches(Pattern.heureMinute)) {
1115 jpm 394
				messages.add(i18nC.projetMessageHeureMinute());
887 aurelien 395
			}
886 aurelien 396
		}
397
 
877 aurelien 398
		if (messages.size() != 0) {
399
			String[] tableauDeMessages = {};
400
			tableauDeMessages = messages.toArray(tableauDeMessages);
1115 jpm 401
			MessageBox.alert(i18nC.erreurSaisieTitre(), UtilArray.implode(tableauDeMessages, "<br />"), null);
877 aurelien 402
			valide = false;
403
		}
404
		return valide;
405
	}
406
 
407
	private void peuplerFormulaire() {
878 aurelien 408
		nomChp.setValue(projet.getNom());
409
		abreviationChp.setValue(projet.getAbreviation());
410
		descriptionChp.setValue(projet.getDescription());
411
		resumeChp.setValue(projet.getResume());
412
		urlChp.setValue(projet.getUrl());
413
 
414
		motsClesChp.setValue(projet.getMotsCles());
415
		citationChp.setValue(projet.getCitation());
416
		licenceChp.setValue(projet.getLicence());
1327 cyprien 417
		if (projet.getLangue().matches("[0-9]+")) {
418
			langueChp.getCombo().setValue(langueChp.getStore().findModel("cmlv_id_valeur", projet.getLangue()));
419
		} else {
420
			langueChp.getCombo().setRawValue(projet.getLangue());
421
		}
924 jpm 422
		if (projet.getMarkPublic().equals("1")) {
887 aurelien 423
			markPublicChp.setValue(true);
1118 jpm 424
			String[] heureTab = projet.getIndexationHeure().split(":");
425
			if (heureTab.length > 1) {
426
				String heure = heureTab[0]+":"+heureTab[1];
427
				if (heure.matches(Pattern.heureMinute)) {
428
					indexationHeureChp.setValue(heure);
429
				}
430
			}
431
			indexationFrequenceChp.peupler(projet.getIndexationFreq());
432
			indexationDureeChp.peupler(projet.getIndexationDuree());
887 aurelien 433
		} else {
434
			markPublicChp.setValue(false);
435
		}
878 aurelien 436
 
437
		doLayout(true);
877 aurelien 438
	}
439
 
440
	private Projet collecterProjet() {
887 aurelien 441
		Projet projetCollecte = (Projet) projet.cloner(new Projet());
877 aurelien 442
 
928 jpm 443
		projetCollecte.setNom(nomChp.getValue());
444
		projetCollecte.setAbreviation(abreviationChp.getValue());
445
		projetCollecte.setDescription(descriptionChp.getValue());
446
		projetCollecte.setResume(resumeChp.getValue());
447
		projetCollecte.setUrl(urlChp.getValue());
877 aurelien 448
 
928 jpm 449
		projetCollecte.setMotsCles(motsClesChp.getValue());
450
		projetCollecte.setCitation(citationChp.getValue());
451
		projetCollecte.setLicence(licenceChp.getValue());
1327 cyprien 452
		if (langueChp.getValeur() != null) {
453
			Debug.log("langueChp.getValeur()="+langueChp.getValeur());
454
			Valeur valeur = new Valeur(langueChp.getValeur());
455
			projetCollecte.setLangue(valeur.getId());
456
		} else {
457
			projetCollecte.setLangue("");
458
		}
928 jpm 459
		String markPublic = (markPublicChp.getValue()) ? "1" : "0";
460
		projetCollecte.setMarkPublic(markPublic);
887 aurelien 461
 
928 jpm 462
		projetCollecte.setIndexationHeure(indexationHeureChp.getValue());
1115 jpm 463
		projetCollecte.setIndexationFreq(indexationFrequenceChp.getValeur());
464
		projetCollecte.setIndexationDuree(indexationDureeChp.getValeur());
928 jpm 465
 
466
		Projet projetARetourner = null;
887 aurelien 467
		if (!projetCollecte.comparer(projet)) {
468
			projetARetourner = projet = projetCollecte;
469
		}
877 aurelien 470
		return projetARetourner;
471
	}
472
 
934 jpm 473
	public void reinitialiserFormulaire() {
877 aurelien 474
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
475
			mediateur.afficherFormProjet(projet.getId());
476
		} else {
477
			mediateur.afficherFormProjet(null);
478
		}
479
	}
908 aurelien 480
 
877 aurelien 481
}