985 |
jpm |
1 |
package org.tela_botanica.client.vues.commentaire;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
|
|
|
5 |
import org.tela_botanica.client.ComposantClass;
|
|
|
6 |
import org.tela_botanica.client.Mediateur;
|
989 |
jpm |
7 |
import org.tela_botanica.client.composants.ChampSliderPourcentage;
|
985 |
jpm |
8 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
9 |
import org.tela_botanica.client.modeles.Information;
|
|
|
10 |
import org.tela_botanica.client.modeles.MenuApplicationId;
|
989 |
jpm |
11 |
import org.tela_botanica.client.modeles.commentaire.Commentaire;
|
|
|
12 |
import org.tela_botanica.client.util.Debug;
|
985 |
jpm |
13 |
import org.tela_botanica.client.util.UtilArray;
|
|
|
14 |
import org.tela_botanica.client.util.UtilString;
|
|
|
15 |
import org.tela_botanica.client.vues.Formulaire;
|
|
|
16 |
|
|
|
17 |
import com.extjs.gxt.ui.client.event.Events;
|
|
|
18 |
import com.extjs.gxt.ui.client.widget.MessageBox;
|
989 |
jpm |
19 |
import com.extjs.gxt.ui.client.widget.form.CheckBox;
|
|
|
20 |
import com.extjs.gxt.ui.client.widget.form.TextArea;
|
985 |
jpm |
21 |
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
22 |
import com.extjs.gxt.ui.client.widget.layout.FormData;
|
|
|
23 |
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
public class CommentaireForm extends Formulaire implements Rafraichissable {
|
|
|
27 |
|
989 |
jpm |
28 |
private Commentaire commentaire;
|
|
|
29 |
|
|
|
30 |
private TextField<String> titreChp;
|
|
|
31 |
private TextArea texteChp;
|
|
|
32 |
private ChampSliderPourcentage ponderationChp;
|
|
|
33 |
private CheckBox publicChp;
|
985 |
jpm |
34 |
|
|
|
35 |
private static boolean formulaireValideOk = false;
|
989 |
jpm |
36 |
private static boolean commentaireValideOk = false;
|
985 |
jpm |
37 |
|
989 |
jpm |
38 |
public CommentaireForm(Mediateur mediateurCourrant, String commentaireId) {
|
|
|
39 |
initialiserCommentaireForm(mediateurCourrant, commentaireId);
|
985 |
jpm |
40 |
}
|
|
|
41 |
|
989 |
jpm |
42 |
public CommentaireForm(Mediateur mediateurCourrant, String commentaireId, Rafraichissable vueARafraichirApresValidation) {
|
985 |
jpm |
43 |
vueExterneARafraichirApresValidation = vueARafraichirApresValidation;
|
989 |
jpm |
44 |
initialiserCommentaireForm(mediateurCourrant, commentaireId);
|
985 |
jpm |
45 |
}
|
|
|
46 |
|
989 |
jpm |
47 |
private void initialiserCommentaireForm(Mediateur mediateurCourrant, String commentaireId) {
|
985 |
jpm |
48 |
initialiserValidation();
|
|
|
49 |
|
989 |
jpm |
50 |
commentaire = new Commentaire();
|
|
|
51 |
commentaire.setId(commentaireId);
|
985 |
jpm |
52 |
|
989 |
jpm |
53 |
String modeDeCreation = (UtilString.isEmpty(commentaire.getId()) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
|
|
|
54 |
initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COMMENTAIRE);
|
985 |
jpm |
55 |
|
989 |
jpm |
56 |
panneauFormulaire.setLayout(new FormLayout());
|
985 |
jpm |
57 |
String titre = genererTitreFormulaire();
|
|
|
58 |
panneauFormulaire.setHeading(titre);
|
|
|
59 |
|
989 |
jpm |
60 |
creerChamps();
|
|
|
61 |
|
985 |
jpm |
62 |
if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
|
989 |
jpm |
63 |
mediateur.selectionnerCommentaire(this, commentaireId);
|
985 |
jpm |
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
private String genererTitreFormulaire() {
|
989 |
jpm |
68 |
String titre = i18nC.commentaireTitreFormAjout();
|
985 |
jpm |
69 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
989 |
jpm |
70 |
titre = i18nC.commentaireTitreFormModif()+" - "+i18nC.id()+": "+commentaire.getId();
|
985 |
jpm |
71 |
}
|
|
|
72 |
return titre;
|
|
|
73 |
}
|
|
|
74 |
|
989 |
jpm |
75 |
private void creerChamps() {
|
985 |
jpm |
76 |
titreChp = new TextField<String>();
|
989 |
jpm |
77 |
titreChp.setFieldLabel(i18nC.commentaireTitre());
|
985 |
jpm |
78 |
titreChp.addStyleName(ComposantClass.OBLIGATOIRE);
|
|
|
79 |
titreChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
|
989 |
jpm |
80 |
panneauFormulaire.add(titreChp, new FormData(450, 0));
|
985 |
jpm |
81 |
|
989 |
jpm |
82 |
texteChp = new TextArea();
|
|
|
83 |
texteChp.setFieldLabel(i18nC.commentaireTexte());
|
|
|
84 |
panneauFormulaire.add(texteChp, new FormData(450, 250));
|
985 |
jpm |
85 |
|
989 |
jpm |
86 |
ponderationChp = new ChampSliderPourcentage(i18nC.commentairePonderation());
|
|
|
87 |
panneauFormulaire.add(ponderationChp, new FormData(450, 0));
|
|
|
88 |
|
|
|
89 |
publicChp = new CheckBox();
|
|
|
90 |
publicChp.setFieldLabel(i18nC.donneePublic());
|
|
|
91 |
panneauFormulaire.add(publicChp, new FormData(50, 0));
|
985 |
jpm |
92 |
}
|
|
|
93 |
|
|
|
94 |
public void rafraichir(Object nouvellesDonnees) {
|
989 |
jpm |
95 |
if (nouvellesDonnees instanceof Commentaire) {
|
985 |
jpm |
96 |
// Si on a reçu les details d'une publication
|
989 |
jpm |
97 |
rafraichirCommentaire((Commentaire) nouvellesDonnees);
|
985 |
jpm |
98 |
} else if (nouvellesDonnees instanceof Information) {
|
|
|
99 |
rafraichirInformation((Information) nouvellesDonnees);
|
|
|
100 |
} else {
|
989 |
jpm |
101 |
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
|
985 |
jpm |
102 |
}
|
|
|
103 |
|
|
|
104 |
if (etreValide()) {
|
|
|
105 |
initialiserValidation();
|
|
|
106 |
repandreRafraichissement();
|
|
|
107 |
controlerFermetureApresRafraichissement();
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
989 |
jpm |
111 |
private void rafraichirCommentaire(Commentaire commentaireRecu) {
|
|
|
112 |
commentaire = commentaireRecu;
|
985 |
jpm |
113 |
peuplerFormulaire();
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
private void rafraichirInformation(Information info) {
|
989 |
jpm |
117 |
String type = info.getType();
|
|
|
118 |
if (type.equals("ajout_commentaire") || type.equals("modif_commentaire")) {
|
|
|
119 |
commentaireValideOk = true;
|
|
|
120 |
commentaire.setId((String) info.getDonnee(0));
|
985 |
jpm |
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
private Boolean etreValide() {
|
|
|
125 |
Boolean valide = false;
|
989 |
jpm |
126 |
Debug.log("formulaire"+formulaireValideOk+" - Commentaire :"+commentaireValideOk);
|
|
|
127 |
if (formulaireValideOk && commentaireValideOk) {
|
985 |
jpm |
128 |
valide = true;
|
|
|
129 |
}
|
|
|
130 |
return valide;
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
private void initialiserValidation() {
|
|
|
134 |
formulaireValideOk = false;
|
989 |
jpm |
135 |
commentaireValideOk = false;
|
985 |
jpm |
136 |
}
|
|
|
137 |
|
|
|
138 |
private void repandreRafraichissement() {
|
|
|
139 |
if (vueExterneARafraichirApresValidation != null) {
|
989 |
jpm |
140 |
String type = "commentaire_modifiee";
|
985 |
jpm |
141 |
if (mode.equals(Formulaire.MODE_AJOUTER)) {
|
989 |
jpm |
142 |
type = "commentaire_ajoutee";
|
985 |
jpm |
143 |
}
|
|
|
144 |
Information info = new Information(type);
|
989 |
jpm |
145 |
info.setDonnee(0, commentaire);
|
985 |
jpm |
146 |
vueExterneARafraichirApresValidation.rafraichir(info);
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
public boolean soumettreFormulaire() {
|
|
|
151 |
formulaireValideOk = verifierFormulaire();
|
989 |
jpm |
152 |
Debug.log("Form?"+formulaireValideOk);
|
985 |
jpm |
153 |
if (formulaireValideOk) {
|
989 |
jpm |
154 |
soumettreCommentaire();
|
985 |
jpm |
155 |
}
|
|
|
156 |
return formulaireValideOk;
|
|
|
157 |
}
|
|
|
158 |
|
989 |
jpm |
159 |
private void soumettreCommentaire() {
|
|
|
160 |
Commentaire commentaireCollectee = collecterCommentaire();
|
|
|
161 |
if (commentaireCollectee != null) {
|
|
|
162 |
Debug.log("Info public collectée ? ok");
|
985 |
jpm |
163 |
if (mode.equals(Formulaire.MODE_AJOUTER)) {
|
989 |
jpm |
164 |
mediateur.ajouterCommentaire(this, commentaireCollectee);
|
985 |
jpm |
165 |
} else if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
989 |
jpm |
166 |
mediateur.modifierCommentaire(this, commentaireCollectee);
|
985 |
jpm |
167 |
}
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
public boolean verifierFormulaire() {
|
|
|
172 |
boolean valide = true;
|
|
|
173 |
ArrayList<String> messages = new ArrayList<String>();
|
|
|
174 |
|
|
|
175 |
String titre = titreChp.getValue();
|
|
|
176 |
if (titre == null || titre.equals("")) {
|
989 |
jpm |
177 |
messages.add(i18nC.commentaireMessageTitre());
|
985 |
jpm |
178 |
}
|
|
|
179 |
|
|
|
180 |
if (messages.size() != 0) {
|
|
|
181 |
String[] tableauDeMessages = {};
|
|
|
182 |
tableauDeMessages = messages.toArray(tableauDeMessages);
|
989 |
jpm |
183 |
MessageBox.alert(i18nC.erreurSaisieTitre(), UtilArray.implode(tableauDeMessages, "<br />"), null);
|
985 |
jpm |
184 |
valide = false;
|
|
|
185 |
}
|
|
|
186 |
return valide;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
private void peuplerFormulaire() {
|
989 |
jpm |
190 |
titreChp.setValue(commentaire.getTitre());
|
|
|
191 |
texteChp.setValue(commentaire.getTexte());
|
|
|
192 |
ponderationChp.peupler(commentaire.getPonderation());
|
|
|
193 |
boolean acces = (commentaire.etrePublic() ? true : false);
|
|
|
194 |
publicChp.setValue(acces);
|
985 |
jpm |
195 |
}
|
|
|
196 |
|
989 |
jpm |
197 |
private Commentaire collecterCommentaire() {
|
|
|
198 |
Commentaire commentaireCollectee = (Commentaire) commentaire.cloner(new Commentaire());
|
985 |
jpm |
199 |
|
|
|
200 |
String titre = titreChp.getValue();
|
989 |
jpm |
201 |
commentaireCollectee.setTitre(titre);
|
985 |
jpm |
202 |
|
989 |
jpm |
203 |
String texte = texteChp.getValue();
|
|
|
204 |
commentaireCollectee.setTexte(texte);
|
985 |
jpm |
205 |
|
989 |
jpm |
206 |
String ponderation = ponderationChp.getValeur();
|
|
|
207 |
commentaireCollectee.setPonderation(ponderation);
|
985 |
jpm |
208 |
|
989 |
jpm |
209 |
String acces = (publicChp.getValue() ? "1" : "0");
|
|
|
210 |
commentaireCollectee.setPublic(acces);
|
985 |
jpm |
211 |
|
989 |
jpm |
212 |
Commentaire commentaireARetourner = null;
|
|
|
213 |
if (!commentaireCollectee.comparer(commentaire)) {
|
|
|
214 |
commentaireARetourner = commentaire = commentaireCollectee;
|
985 |
jpm |
215 |
}
|
989 |
jpm |
216 |
return commentaireARetourner;
|
985 |
jpm |
217 |
}
|
|
|
218 |
|
|
|
219 |
public void reinitialiserFormulaire() {
|
|
|
220 |
if (mode.equals(Formulaire.MODE_MODIFIER)) {
|
989 |
jpm |
221 |
mediateur.afficherFormPublication(commentaire.getId());
|
985 |
jpm |
222 |
} else {
|
|
|
223 |
mediateur.afficherFormPublication(null);
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
}
|