663 |
benjamin |
1 |
package org.tela_botanica.del.client.vues.plateformedetermination.forum.interventions;
|
|
|
2 |
|
1001 |
aurelien |
3 |
import org.tela_botanica.del.client.cache.CacheClient;
|
978 |
gduche |
4 |
import org.tela_botanica.del.client.composants.fenetreoverlay.FenetreOverlayDefilanteVue;
|
|
|
5 |
import org.tela_botanica.del.client.composants.fenetreoverlay.FenetreOverlaySimplePresenteur;
|
|
|
6 |
import org.tela_botanica.del.client.composants.formulaires.formulairecommentaire.FormulaireCommentairePresenteur;
|
|
|
7 |
import org.tela_botanica.del.client.composants.formulaires.formulairecommentaire.FormulaireCommentaireVue;
|
663 |
benjamin |
8 |
import org.tela_botanica.del.client.composants.votes.barrerepartition.BarreRepartitionVotePresenteur;
|
|
|
9 |
import org.tela_botanica.del.client.composants.votes.barrerepartition.BarreRepartitionVoteVue;
|
1001 |
aurelien |
10 |
import org.tela_botanica.del.client.i18n.I18n;
|
663 |
benjamin |
11 |
import org.tela_botanica.del.client.modeles.Commentaire;
|
|
|
12 |
import org.tela_botanica.del.client.modeles.InterventionForum;
|
|
|
13 |
import org.tela_botanica.del.client.modeles.MoyenneVote;
|
|
|
14 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
1001 |
aurelien |
15 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
|
|
16 |
import org.tela_botanica.del.client.navigation.evenement.ajoutcommentaire.EvenementAjoutCommentaire;
|
|
|
17 |
import org.tela_botanica.del.client.navigation.evenement.ajoutcommentaire.GestionnaireEvenementAjoutCommentaire;
|
|
|
18 |
import org.tela_botanica.del.client.navigation.evenement.ajoutdetermination.EvenementAjoutDetermination;
|
|
|
19 |
import org.tela_botanica.del.client.navigation.evenement.ajoutdetermination.GestionnaireEvenementAjoutDetermination;
|
|
|
20 |
import org.tela_botanica.del.client.navigation.evenement.suppressioncommentaire.EvenementSuppressionCommentaire;
|
|
|
21 |
import org.tela_botanica.del.client.navigation.evenement.suppressiondetermination.EvenementSuppressionDetermination;
|
663 |
benjamin |
22 |
import org.tela_botanica.del.client.services.CalculVoteDeterminationService;
|
1001 |
aurelien |
23 |
import org.tela_botanica.del.client.services.rest.CommentaireService;
|
978 |
gduche |
24 |
import org.tela_botanica.del.client.services.rest.CommentaireServiceConcret;
|
1001 |
aurelien |
25 |
import org.tela_botanica.del.client.services.rest.PropositionDeterminationService;
|
959 |
benjamin |
26 |
import org.tela_botanica.del.client.services.rest.VoteDeterminationServiceConcret;
|
1001 |
aurelien |
27 |
import org.tela_botanica.del.client.services.rest.async.SuppressionCommentaireCallback;
|
|
|
28 |
import org.tela_botanica.del.client.services.rest.async.SuppressionPropositionDeterminationCallback;
|
663 |
benjamin |
29 |
import org.tela_botanica.del.client.vues.plateformedetermination.forum.ArbreCommentairePresenteur;
|
|
|
30 |
import org.tela_botanica.del.client.vues.plateformedetermination.forum.ArbreCommentaireVue;
|
|
|
31 |
|
978 |
gduche |
32 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
33 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
34 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
1001 |
aurelien |
35 |
import com.google.gwt.event.dom.client.HasMouseOutHandlers;
|
|
|
36 |
import com.google.gwt.event.dom.client.HasMouseOverHandlers;
|
|
|
37 |
import com.google.gwt.event.dom.client.MouseOutEvent;
|
|
|
38 |
import com.google.gwt.event.dom.client.MouseOutHandler;
|
|
|
39 |
import com.google.gwt.event.dom.client.MouseOverEvent;
|
|
|
40 |
import com.google.gwt.event.dom.client.MouseOverHandler;
|
978 |
gduche |
41 |
import com.google.gwt.user.client.Window;
|
663 |
benjamin |
42 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
43 |
import com.google.gwt.user.client.ui.IsWidget;
|
|
|
44 |
|
|
|
45 |
public class ForumInterventionPresenteur {
|
|
|
46 |
|
|
|
47 |
public interface Vue extends IsWidget {
|
|
|
48 |
void ajouterInterventionDetermination(PropositionDetermination determination, IsWidget barreRepartition, IsWidget arbreCommentaires);
|
|
|
49 |
void ajouterInterventionCommentaire(Commentaire commentaire, IsWidget arbreCommentaires);
|
978 |
gduche |
50 |
HasClickHandlers getRepondre();
|
|
|
51 |
HasWidgets getEnfants();
|
1001 |
aurelien |
52 |
HasClickHandlers getLienSuppression();
|
|
|
53 |
void afficherLienSuppression();
|
|
|
54 |
void cacherLienSuppression();
|
|
|
55 |
HasMouseOverHandlers getConteneurInterventionMouseOver();
|
|
|
56 |
HasMouseOutHandlers getConteneurInterventionMouseOut();
|
663 |
benjamin |
57 |
}
|
|
|
58 |
|
|
|
59 |
private Vue vue;
|
|
|
60 |
|
|
|
61 |
private InterventionForum interventionForum;
|
1001 |
aurelien |
62 |
|
|
|
63 |
private CommentaireService commentaireService;
|
|
|
64 |
|
|
|
65 |
private PropositionDeterminationService propositionDeterminationService;
|
|
|
66 |
|
|
|
67 |
private FenetreOverlaySimplePresenteur overlay;
|
663 |
benjamin |
68 |
|
1001 |
aurelien |
69 |
public ForumInterventionPresenteur(Vue vue, InterventionForum interventionForum, CommentaireService commentaireService, PropositionDeterminationService propositionDeterminationService) {
|
663 |
benjamin |
70 |
this.vue = vue;
|
|
|
71 |
this.interventionForum = interventionForum;
|
1001 |
aurelien |
72 |
this.commentaireService = commentaireService;
|
|
|
73 |
this.propositionDeterminationService = propositionDeterminationService;
|
663 |
benjamin |
74 |
}
|
|
|
75 |
|
|
|
76 |
public void go(HasWidgets composite) {
|
|
|
77 |
chargerIntervention();
|
|
|
78 |
composite.add(vue.asWidget());
|
978 |
gduche |
79 |
gererEvenements();
|
663 |
benjamin |
80 |
}
|
978 |
gduche |
81 |
|
1003 |
benjamin |
82 |
public void ajouterEnfant(ForumInterventionPresenteur presenteur) {
|
978 |
gduche |
83 |
presenteur.go(vue.getEnfants());
|
|
|
84 |
}
|
663 |
benjamin |
85 |
|
|
|
86 |
private void chargerIntervention() {
|
|
|
87 |
if (interventionForum instanceof PropositionDetermination) {
|
|
|
88 |
ajouterPropositionDetermination((PropositionDetermination) interventionForum);
|
|
|
89 |
} else if (interventionForum instanceof Commentaire) {
|
|
|
90 |
ajouterCommentaire((Commentaire) interventionForum);
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
private void ajouterPropositionDetermination(PropositionDetermination propositionDetermination) {
|
959 |
benjamin |
95 |
BarreRepartitionVotePresenteur barreRepartitionVotePresenteur = new BarreRepartitionVotePresenteur(new BarreRepartitionVoteVue(), new VoteDeterminationServiceConcret());
|
966 |
gduche |
96 |
barreRepartitionVotePresenteur.toggleNomEspece();
|
663 |
benjamin |
97 |
calculerEtAfficherVoteDetermination(barreRepartitionVotePresenteur, propositionDetermination);
|
|
|
98 |
ArbreCommentairePresenteur arbreCommentairePresenteur = new ArbreCommentairePresenteur(new ArbreCommentaireVue(), propositionDetermination);
|
|
|
99 |
vue.ajouterInterventionDetermination(propositionDetermination, barreRepartitionVotePresenteur.getBarreRepartitionVoteVue(), arbreCommentairePresenteur.getArbreCommentaireVue());
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
private void ajouterCommentaire(Commentaire proposition) {
|
|
|
103 |
ArbreCommentairePresenteur arbreCommentairePresenteur = new ArbreCommentairePresenteur(new ArbreCommentaireVue(), proposition);
|
|
|
104 |
vue.ajouterInterventionCommentaire(proposition, arbreCommentairePresenteur.getArbreCommentaireVue());
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
private void calculerEtAfficherVoteDetermination(BarreRepartitionVotePresenteur barreRepartitionVotePresenteur, PropositionDetermination propositionDetermination) {
|
|
|
108 |
MoyenneVote votes = CalculVoteDeterminationService.calculerVoteDetermination(propositionDetermination);
|
|
|
109 |
barreRepartitionVotePresenteur.afficherVotes(votes);
|
|
|
110 |
}
|
978 |
gduche |
111 |
|
|
|
112 |
private void gererEvenements() {
|
|
|
113 |
vue.getRepondre().addClickHandler(new ClickHandler() {
|
|
|
114 |
@Override
|
|
|
115 |
public void onClick(ClickEvent event) {
|
|
|
116 |
FormulaireCommentairePresenteur commentairePresenteur = new FormulaireCommentairePresenteur(interventionForum, new CommentaireServiceConcret(), new FormulaireCommentaireVue());
|
1001 |
aurelien |
117 |
overlay = new FenetreOverlaySimplePresenteur(new FenetreOverlayDefilanteVue());
|
|
|
118 |
overlay.ouvrirFenetreModale(commentairePresenteur);
|
978 |
gduche |
119 |
}
|
|
|
120 |
});
|
1001 |
aurelien |
121 |
|
|
|
122 |
vue.getConteneurInterventionMouseOver().addMouseOverHandler(new MouseOverHandler() {
|
|
|
123 |
@Override
|
|
|
124 |
public void onMouseOver(MouseOverEvent event) {
|
|
|
125 |
if(peutSupprimerIntervention()) {
|
|
|
126 |
vue.afficherLienSuppression();
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
});
|
|
|
130 |
|
|
|
131 |
vue.getConteneurInterventionMouseOut().addMouseOutHandler(new MouseOutHandler() {
|
|
|
132 |
@Override
|
|
|
133 |
public void onMouseOut(MouseOutEvent event) {
|
|
|
134 |
if(peutSupprimerIntervention()) {
|
|
|
135 |
vue.cacherLienSuppression();
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
});
|
|
|
139 |
|
|
|
140 |
vue.getLienSuppression().addClickHandler(new ClickHandler() {
|
|
|
141 |
@Override
|
|
|
142 |
public void onClick(ClickEvent event) {
|
|
|
143 |
|
|
|
144 |
String message = "";
|
|
|
145 |
if (interventionForum instanceof PropositionDetermination) {
|
|
|
146 |
message = I18n.getVocabulary().confirmationSuppressionDetermination();
|
|
|
147 |
} else if (interventionForum instanceof Commentaire) {
|
|
|
148 |
message = I18n.getVocabulary().confirmationSuppressionCommentaire();
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
if(Window.confirm(message)) {
|
|
|
152 |
supprimerIntervention();
|
|
|
153 |
}
|
|
|
154 |
}
|
|
|
155 |
});
|
|
|
156 |
vue.cacherLienSuppression();
|
|
|
157 |
|
|
|
158 |
BusEvenementiel.getInstance().addHandler(EvenementAjoutDetermination.TYPE, new GestionnaireEvenementAjoutDetermination() {
|
|
|
159 |
@Override
|
|
|
160 |
public void onAjoutDetermination(EvenementAjoutDetermination event) {
|
|
|
161 |
if(overlay != null && overlay.fenetreModaleEstOuverte()) {
|
|
|
162 |
overlay.fermerFenetreModale();
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
});
|
|
|
166 |
|
|
|
167 |
BusEvenementiel.getInstance().addHandler(EvenementAjoutCommentaire.TYPE, new GestionnaireEvenementAjoutCommentaire() {
|
|
|
168 |
@Override
|
|
|
169 |
public void onAjoutCommentaire(EvenementAjoutCommentaire event) {
|
|
|
170 |
if(overlay != null && overlay.fenetreModaleEstOuverte()) {
|
|
|
171 |
overlay.fermerFenetreModale();
|
|
|
172 |
}
|
|
|
173 |
}
|
|
|
174 |
});
|
978 |
gduche |
175 |
}
|
1001 |
aurelien |
176 |
|
|
|
177 |
private boolean peutSupprimerIntervention() {
|
1015 |
aurelien |
178 |
return (!interventionForum.aDesCommentaires() && interventionForum.getContributeur() != null && interventionForum.getContributeur().getId().equals(CacheClient.getInstance().getUtilisateur().getId()));
|
1001 |
aurelien |
179 |
}
|
|
|
180 |
|
|
|
181 |
private void supprimerIntervention() {
|
|
|
182 |
if(interventionForum instanceof PropositionDetermination) {
|
|
|
183 |
propositionDeterminationService.supprimerProposition((PropositionDetermination)interventionForum, new SuppressionPropositionDeterminationCallback() {
|
|
|
184 |
@Override
|
|
|
185 |
public void surRetour(String objetRetour) {
|
|
|
186 |
CacheClient.getInstance().getObservationCourante().supprimerIntervention(interventionForum);
|
|
|
187 |
BusEvenementiel.getInstance().fireEvent(new EvenementSuppressionDetermination((PropositionDetermination)interventionForum));
|
|
|
188 |
}
|
|
|
189 |
});
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
if(interventionForum instanceof Commentaire) {
|
|
|
193 |
commentaireService.supprimerCommentaire((Commentaire)interventionForum, new SuppressionCommentaireCallback() {
|
|
|
194 |
@Override
|
|
|
195 |
public void surRetour(String objetRetour) {
|
|
|
196 |
CacheClient.getInstance().getObservationCourante().supprimerIntervention(interventionForum);
|
|
|
197 |
BusEvenementiel.getInstance().fireEvent(new EvenementSuppressionCommentaire((Commentaire)interventionForum));
|
|
|
198 |
}
|
|
|
199 |
});
|
|
|
200 |
}
|
|
|
201 |
}
|
663 |
benjamin |
202 |
}
|