Subversion Repositories eFlore/Applications.coel

Rev

Rev 989 | Rev 1032 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 989 Rev 999
1
package org.tela_botanica.client.vues.commentaire;
1
package org.tela_botanica.client.vues.commentaire;
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
 
4
 
5
import org.tela_botanica.client.ComposantClass;
5
import org.tela_botanica.client.ComposantClass;
6
import org.tela_botanica.client.Mediateur;
6
import org.tela_botanica.client.Mediateur;
7
import org.tela_botanica.client.composants.ChampSliderPourcentage;
7
import org.tela_botanica.client.composants.ChampSliderPourcentage;
8
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.interfaces.Rafraichissable;
9
import org.tela_botanica.client.modeles.Information;
9
import org.tela_botanica.client.modeles.Information;
10
import org.tela_botanica.client.modeles.MenuApplicationId;
10
import org.tela_botanica.client.modeles.MenuApplicationId;
11
import org.tela_botanica.client.modeles.commentaire.Commentaire;
11
import org.tela_botanica.client.modeles.commentaire.Commentaire;
-
 
12
import org.tela_botanica.client.modeles.projet.Projet;
-
 
13
import org.tela_botanica.client.modeles.projet.ProjetListe;
12
import org.tela_botanica.client.util.Debug;
14
import org.tela_botanica.client.util.Debug;
13
import org.tela_botanica.client.util.UtilArray;
15
import org.tela_botanica.client.util.UtilArray;
14
import org.tela_botanica.client.util.UtilString;
16
import org.tela_botanica.client.util.UtilString;
15
import org.tela_botanica.client.vues.Formulaire;
17
import org.tela_botanica.client.vues.Formulaire;
-
 
18
 
16
 
19
import com.extjs.gxt.ui.client.event.BaseEvent;
-
 
20
import com.extjs.gxt.ui.client.event.Events;
-
 
21
import com.extjs.gxt.ui.client.event.Listener;
17
import com.extjs.gxt.ui.client.event.Events;
22
import com.extjs.gxt.ui.client.store.ListStore;
18
import com.extjs.gxt.ui.client.widget.MessageBox;
23
import com.extjs.gxt.ui.client.widget.MessageBox;
-
 
24
import com.extjs.gxt.ui.client.widget.form.CheckBox;
-
 
25
import com.extjs.gxt.ui.client.widget.form.ComboBox;
19
import com.extjs.gxt.ui.client.widget.form.CheckBox;
26
import com.extjs.gxt.ui.client.widget.form.Field;
20
import com.extjs.gxt.ui.client.widget.form.TextArea;
27
import com.extjs.gxt.ui.client.widget.form.TextArea;
-
 
28
import com.extjs.gxt.ui.client.widget.form.TextField;
-
 
29
import com.extjs.gxt.ui.client.widget.form.Validator;
21
import com.extjs.gxt.ui.client.widget.form.TextField;
30
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
22
import com.extjs.gxt.ui.client.widget.layout.FormData;
31
import com.extjs.gxt.ui.client.widget.layout.FormData;
23
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
32
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
24
 
33
 
25
 
34
 
26
public class CommentaireForm extends Formulaire implements Rafraichissable {
35
public class CommentaireForm extends Formulaire implements Rafraichissable {
27
	
36
	
28
	private Commentaire commentaire;
37
	private Commentaire commentaire;
-
 
38
 
29
 
39
	private ComboBox<Projet> projetsCombo = null;
30
	private TextField<String> titreChp;
40
	private TextField<String> titreChp;
31
	private TextArea texteChp;
41
	private TextArea texteChp;
32
	private ChampSliderPourcentage ponderationChp;
42
	private ChampSliderPourcentage ponderationChp;
33
	private CheckBox publicChp;
43
	private CheckBox publicChp;
34
	
44
	
35
	private static boolean formulaireValideOk = false;
45
	private static boolean formulaireValideOk = false;
36
	private static boolean commentaireValideOk = false;
46
	private static boolean commentaireValideOk = false;
37
 
47
 
38
	public CommentaireForm(Mediateur mediateurCourrant, String commentaireId) {
48
	public CommentaireForm(Mediateur mediateurCourrant, String commentaireId) {
39
		initialiserCommentaireForm(mediateurCourrant, commentaireId);
49
		initialiserCommentaireForm(mediateurCourrant, commentaireId);
40
	}
50
	}
41
 
51
 
42
	public CommentaireForm(Mediateur mediateurCourrant, String commentaireId, Rafraichissable vueARafraichirApresValidation) {
52
	public CommentaireForm(Mediateur mediateurCourrant, String commentaireId, Rafraichissable vueARafraichirApresValidation) {
43
		vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
53
		vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
44
		initialiserCommentaireForm(mediateurCourrant, commentaireId);
54
		initialiserCommentaireForm(mediateurCourrant, commentaireId);
45
	}
55
	}
46
	
56
	
47
	private void initialiserCommentaireForm(Mediateur mediateurCourrant, String commentaireId) {
57
	private void initialiserCommentaireForm(Mediateur mediateurCourrant, String commentaireId) {
48
		initialiserValidation();
58
		initialiserValidation();
49
		
59
		
50
		commentaire = new Commentaire();
60
		commentaire = new Commentaire();
51
		commentaire.setId(commentaireId);
61
		commentaire.setId(commentaireId);
52
		
62
		
53
		String modeDeCreation = (UtilString.isEmpty(commentaire.getId()) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
63
		String modeDeCreation = (UtilString.isEmpty(commentaire.getId()) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
54
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COMMENTAIRE);
64
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COMMENTAIRE);
55
		
65
		
56
		panneauFormulaire.setLayout(new FormLayout());
66
		panneauFormulaire.setLayout(new FormLayout());
57
		String titre = genererTitreFormulaire();
67
		String titre = genererTitreFormulaire();
58
		panneauFormulaire.setHeading(titre);
68
		panneauFormulaire.setHeading(titre);
59
 
69
 
60
		creerChamps();
70
		creerChamps();
61
 
71
 
62
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
72
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
63
			mediateur.selectionnerCommentaire(this, commentaireId);
73
			mediateur.selectionnerCommentaire(this, commentaireId);
64
		}
74
		}
65
	}
75
	}
66
	
76
	
67
	private String genererTitreFormulaire() {
77
	private String genererTitreFormulaire() {
68
		String titre = i18nC.commentaireTitreFormAjout();
78
		String titre = i18nC.commentaireTitreFormAjout();
69
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
79
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
70
			 titre = i18nC.commentaireTitreFormModif()+" - "+i18nC.id()+": "+commentaire.getId();
80
			 titre = i18nC.commentaireTitreFormModif()+" - "+i18nC.id()+": "+commentaire.getId();
71
		}
81
		}
72
		return titre;
82
		return titre;
73
	}
83
	}
74
	
84
	
75
	private void creerChamps() {
85
	private void creerChamps() {
-
 
86
		projetsCombo = new ComboBox<Projet>();
-
 
87
		projetsCombo.setTabIndex(tabIndex++);
-
 
88
		projetsCombo.setFieldLabel(i18nC.projetChamp());
-
 
89
		projetsCombo.setDisplayField("nom");
-
 
90
		projetsCombo.setForceSelection(true);
-
 
91
		projetsCombo.setValidator(new Validator() {
-
 
92
			@Override
-
 
93
			public String validate(Field<?> field, String value) {
-
 
94
				String retour = null;
-
 
95
				if (field.getRawValue().equals("")) {
-
 
96
					field.setValue(null);
-
 
97
				} else if (projetsCombo.getStore().findModel("nom", field.getRawValue()) == null) {
-
 
98
					String contenuBrut = field.getRawValue();
-
 
99
					field.setValue(null);
-
 
100
					field.setRawValue(contenuBrut);
-
 
101
					retour = "Veuillez sélectionner une valeur ou laisser le champ vide";
-
 
102
				}
-
 
103
				return retour;
-
 
104
			}
-
 
105
		});
-
 
106
		projetsCombo.setTriggerAction(TriggerAction.ALL);
-
 
107
		projetsCombo.setStore(new ListStore<Projet>());
-
 
108
		projetsCombo.addStyleName(ComposantClass.OBLIGATOIRE);
-
 
109
		projetsCombo.addListener(Events.Valid, new Listener<BaseEvent>() {
-
 
110
			@Override
-
 
111
			public void handleEvent(BaseEvent be) {
-
 
112
				Projet valeur = projetsCombo.getValue();
-
 
113
				// Gestion du style obligatoire
-
 
114
				projetsCombo.removeStyleName(ComposantClass.OBLIGATOIRE);
-
 
115
				projetsCombo.removeStyleName(ComposantClass.OBLIGATOIRE_OK);
-
 
116
				if (valeur != null) {
-
 
117
					projetsCombo.addStyleName(ComposantClass.OBLIGATOIRE_OK);
-
 
118
				} else {
-
 
119
					projetsCombo.addStyleName(ComposantClass.OBLIGATOIRE);
-
 
120
				}
-
 
121
			}
-
 
122
		});
-
 
123
		panneauFormulaire.add(projetsCombo, new FormData(450, 0));
-
 
124
		mediateur.selectionnerProjet(this, null);
-
 
125
		
76
		titreChp = new TextField<String>();
126
		titreChp = new TextField<String>();
77
		titreChp.setFieldLabel(i18nC.commentaireTitre());
127
		titreChp.setFieldLabel(i18nC.commentaireTitre());
78
		titreChp.addStyleName(ComposantClass.OBLIGATOIRE);
128
		titreChp.addStyleName(ComposantClass.OBLIGATOIRE);
79
		titreChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
129
		titreChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
80
		panneauFormulaire.add(titreChp, new FormData(450, 0));
130
		panneauFormulaire.add(titreChp, new FormData(450, 0));
81
		
131
		
82
		texteChp = new TextArea();
132
		texteChp = new TextArea();
83
		texteChp.setFieldLabel(i18nC.commentaireTexte());
133
		texteChp.setFieldLabel(i18nC.commentaireTexte());
84
		panneauFormulaire.add(texteChp, new FormData(450, 250));
134
		panneauFormulaire.add(texteChp, new FormData(450, 250));
85
		
135
		
86
		ponderationChp = new ChampSliderPourcentage(i18nC.commentairePonderation());
136
		ponderationChp = new ChampSliderPourcentage(i18nC.commentairePonderation());
87
		panneauFormulaire.add(ponderationChp, new FormData(450, 0));
137
		panneauFormulaire.add(ponderationChp, new FormData(450, 0));
88
		
138
		
89
		publicChp = new CheckBox();
139
		publicChp = new CheckBox();
90
		publicChp.setFieldLabel(i18nC.donneePublic());
140
		publicChp.setFieldLabel(i18nC.donneePublic());
91
		panneauFormulaire.add(publicChp, new FormData(50, 0));
141
		panneauFormulaire.add(publicChp, new FormData(50, 0));
92
	}
142
	}
93
	
143
	
94
	public void rafraichir(Object nouvellesDonnees) {
144
	public void rafraichir(Object nouvellesDonnees) {
95
		if (nouvellesDonnees instanceof Commentaire) {
145
		if (nouvellesDonnees instanceof Commentaire) {
96
			// Si on a reçu les details d'une publication
146
			// Si on a reçu les details d'une publication
97
			rafraichirCommentaire((Commentaire) nouvellesDonnees);
147
			rafraichirCommentaire((Commentaire) nouvellesDonnees);
-
 
148
		} else if (nouvellesDonnees instanceof ProjetListe) {
-
 
149
			ProjetListe projets = (ProjetListe) nouvellesDonnees;
-
 
150
			Formulaire.rafraichirComboBox(projets, projetsCombo);
-
 
151
			setValeurComboProjets();
98
		} else if (nouvellesDonnees instanceof Information) {
152
		} else if (nouvellesDonnees instanceof Information) {
99
			rafraichirInformation((Information) nouvellesDonnees);	
153
			rafraichirInformation((Information) nouvellesDonnees);	
100
		} else {
154
		} else {
101
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
155
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
102
		}
156
		}
103
		
157
		
104
		if (etreValide()) {
158
		if (etreValide()) {
105
			initialiserValidation();
159
			initialiserValidation();
106
			repandreRafraichissement();
160
			repandreRafraichissement();
107
			controlerFermetureApresRafraichissement();
161
			controlerFermetureApresRafraichissement();
108
		}
162
		}
109
	}
163
	}
110
	
164
	
111
	private void rafraichirCommentaire(Commentaire commentaireRecu) {
165
	private void rafraichirCommentaire(Commentaire commentaireRecu) {
112
		commentaire = commentaireRecu;
166
		commentaire = commentaireRecu;
113
		peuplerFormulaire();
167
		peuplerFormulaire();
114
	}
168
	}
-
 
169
	
-
 
170
	private String getValeurComboProjets() {
-
 
171
		String valeur = "";
-
 
172
		if (projetsCombo.getValue() != null) {
-
 
173
			valeur = projetsCombo.getValue().getId();
-
 
174
		}
-
 
175
		return valeur;
-
 
176
	}
-
 
177
	private void setValeurComboProjets() {
-
 
178
		if (projetsCombo.getStore() != null ) {
-
 
179
			if (mode.equals(Formulaire.MODE_MODIFIER) && commentaire != null) {
-
 
180
				projetsCombo.setValue(projetsCombo.getStore().findModel("id_projet", commentaire.getIdProjet()));
-
 
181
			} else if (mode.equals(Formulaire.MODE_AJOUTER)) {
-
 
182
				projetsCombo.setValue(projetsCombo.getStore().findModel("id_projet", mediateur.getProjetId()));
-
 
183
			}
-
 
184
		}
-
 
185
	}
115
	
186
	
116
	private void rafraichirInformation(Information info) {
187
	private void rafraichirInformation(Information info) {
117
		String type = info.getType();
188
		String type = info.getType();
118
		if (type.equals("ajout_commentaire") || type.equals("modif_commentaire")) {
189
		if (type.equals("ajout_commentaire") || type.equals("modif_commentaire")) {
119
			commentaireValideOk = true;
190
			commentaireValideOk = true;
120
			commentaire.setId((String) info.getDonnee(0));
191
			commentaire.setId((String) info.getDonnee(0));
121
		}
192
		}
122
	}
193
	}
123
 
194
 
124
	private Boolean etreValide() {
195
	private Boolean etreValide() {
125
		Boolean valide = false;
196
		Boolean valide = false;
126
		Debug.log("formulaire"+formulaireValideOk+" - Commentaire :"+commentaireValideOk);
197
		Debug.log("formulaire"+formulaireValideOk+" - Commentaire :"+commentaireValideOk);
127
		if (formulaireValideOk && commentaireValideOk) {
198
		if (formulaireValideOk && commentaireValideOk) {
128
			valide = true;
199
			valide = true;
129
		}
200
		}
130
		return valide;
201
		return valide;
131
	}
202
	}
132
	
203
	
133
	private void initialiserValidation() {
204
	private void initialiserValidation() {
134
		formulaireValideOk = false;
205
		formulaireValideOk = false;
135
		commentaireValideOk = false;
206
		commentaireValideOk = false;
136
	}
207
	}
137
	
208
	
138
	private void repandreRafraichissement() {
209
	private void repandreRafraichissement() {
139
		if (vueExterneARafraichirApresValidation != null) {
210
		if (vueExterneARafraichirApresValidation != null) {
140
			String type = "commentaire_modifiee";
211
			String type = "commentaire_modifiee";
141
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
212
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
142
				type = "commentaire_ajoutee";
213
				type = "commentaire_ajoutee";
143
			}
214
			}
144
			Information info = new Information(type);
215
			Information info = new Information(type);
145
			info.setDonnee(0, commentaire);
216
			info.setDonnee(0, commentaire);
146
			vueExterneARafraichirApresValidation.rafraichir(info);
217
			vueExterneARafraichirApresValidation.rafraichir(info);
147
		}
218
		}
148
	}
219
	}
149
	
220
	
150
	public boolean soumettreFormulaire() {
221
	public boolean soumettreFormulaire() {
151
		formulaireValideOk = verifierFormulaire();
222
		formulaireValideOk = verifierFormulaire();
152
		Debug.log("Form?"+formulaireValideOk);
223
		Debug.log("Form?"+formulaireValideOk);
153
		if (formulaireValideOk) {
224
		if (formulaireValideOk) {
154
			soumettreCommentaire();
225
			soumettreCommentaire();
155
		}
226
		}
156
		return formulaireValideOk;
227
		return formulaireValideOk;
157
	}
228
	}
158
	
229
	
159
	private void soumettreCommentaire() {
230
	private void soumettreCommentaire() {
160
		Commentaire commentaireCollectee = collecterCommentaire();
231
		Commentaire commentaireCollectee = collecterCommentaire();
161
		if (commentaireCollectee != null) {
232
		if (commentaireCollectee != null) {
162
			Debug.log("Info public collectée ? ok");
233
			Debug.log("Info public collectée ? ok");
163
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
234
			if (mode.equals(Formulaire.MODE_AJOUTER)) {
164
				mediateur.ajouterCommentaire(this, commentaireCollectee);
235
				mediateur.ajouterCommentaire(this, commentaireCollectee);
165
			} else if (mode.equals(Formulaire.MODE_MODIFIER)) {
236
			} else if (mode.equals(Formulaire.MODE_MODIFIER)) {
166
				mediateur.modifierCommentaire(this, commentaireCollectee);
237
				mediateur.modifierCommentaire(this, commentaireCollectee);
167
			}
238
			}
168
		}
239
		}
169
	}
240
	}
170
	
241
	
171
	public boolean verifierFormulaire() {
242
	public boolean verifierFormulaire() {
172
		boolean valide = true;
243
		boolean valide = true;
173
		ArrayList<String> messages = new ArrayList<String>();
244
		ArrayList<String> messages = new ArrayList<String>();
174
		
245
		
175
		String titre = titreChp.getValue();
246
		String titre = titreChp.getValue();
176
		if (titre == null || titre.equals("")) {
247
		if (titre == null || titre.equals("")) {
177
			messages.add(i18nC.commentaireMessageTitre());
248
			messages.add(i18nC.commentaireMessageTitre());
178
		}
249
		}
179
		
250
		
180
		if (messages.size() != 0) {
251
		if (messages.size() != 0) {
181
			String[] tableauDeMessages = {};
252
			String[] tableauDeMessages = {};
182
			tableauDeMessages = messages.toArray(tableauDeMessages);
253
			tableauDeMessages = messages.toArray(tableauDeMessages);
183
			MessageBox.alert(i18nC.erreurSaisieTitre(), UtilArray.implode(tableauDeMessages, "<br />"), null);
254
			MessageBox.alert(i18nC.erreurSaisieTitre(), UtilArray.implode(tableauDeMessages, "<br />"), null);
184
			valide = false;
255
			valide = false;
185
		}
256
		}
186
		return valide;		
257
		return valide;		
187
	}
258
	}
188
	
259
	
189
	private void peuplerFormulaire() {
260
	private void peuplerFormulaire() {
-
 
261
		setValeurComboProjets();
190
		titreChp.setValue(commentaire.getTitre());
262
		titreChp.setValue(commentaire.getTitre());
191
		texteChp.setValue(commentaire.getTexte());
263
		texteChp.setValue(commentaire.getTexte());
192
		ponderationChp.peupler(commentaire.getPonderation());
264
		ponderationChp.peupler(commentaire.getPonderation());
193
		boolean acces = (commentaire.etrePublic() ? true : false);
265
		boolean acces = (commentaire.etrePublic() ? true : false);
194
		publicChp.setValue(acces);
266
		publicChp.setValue(acces);
195
	}
267
	}
196
	
268
	
197
	private Commentaire collecterCommentaire() {
269
	private Commentaire collecterCommentaire() {
198
		Commentaire commentaireCollectee = (Commentaire) commentaire.cloner(new Commentaire());
270
		Commentaire commentaireCollectee = (Commentaire) commentaire.cloner(new Commentaire());
-
 
271
		
-
 
272
		commentaireCollectee.setIdProjet(getValeurComboProjets());
199
		
273
		
200
		String titre = titreChp.getValue();
274
		String titre = titreChp.getValue();
201
		commentaireCollectee.setTitre(titre);
275
		commentaireCollectee.setTitre(titre);
202
		
276
		
203
		String texte = texteChp.getValue();
277
		String texte = texteChp.getValue();
204
		commentaireCollectee.setTexte(texte);
278
		commentaireCollectee.setTexte(texte);
205
		
279
		
206
		String ponderation = ponderationChp.getValeur();
280
		String ponderation = ponderationChp.getValeur();
207
		commentaireCollectee.setPonderation(ponderation);
281
		commentaireCollectee.setPonderation(ponderation);
208
		
282
		
209
		String acces = (publicChp.getValue() ? "1" : "0");
283
		String acces = (publicChp.getValue() ? "1" : "0");
210
		commentaireCollectee.setPublic(acces);
284
		commentaireCollectee.setPublic(acces);
211
		
285
		
212
		Commentaire commentaireARetourner = null;
286
		Commentaire commentaireARetourner = null;
213
		if (!commentaireCollectee.comparer(commentaire)) {
287
		if (!commentaireCollectee.comparer(commentaire)) {
214
			commentaireARetourner = commentaire = commentaireCollectee;
288
			commentaireARetourner = commentaire = commentaireCollectee;
215
		}
289
		}
216
		return commentaireARetourner;
290
		return commentaireARetourner;
217
	}
291
	}
218
	
292
	
219
	public void reinitialiserFormulaire() {
293
	public void reinitialiserFormulaire() {
220
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
294
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
221
			mediateur.afficherFormPublication(commentaire.getId());
295
			mediateur.afficherFormPublication(commentaire.getId());
222
		} else {
296
		} else {
223
			mediateur.afficherFormPublication(null);
297
			mediateur.afficherFormPublication(null);
224
		}
298
		}
225
	}
299
	}
226
}
300
}