Subversion Repositories eFlore/Applications.coel

Rev

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