1860 |
aurelien |
1 |
package org.tela_botanica.client.vues.publication;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.Mediateur;
|
|
|
4 |
import org.tela_botanica.client.RegistreId;
|
|
|
5 |
import org.tela_botanica.client.modeles.publication.Publication;
|
|
|
6 |
import org.tela_botanica.client.modeles.publication.PublicationAsyncDao;
|
|
|
7 |
|
|
|
8 |
import com.extjs.gxt.ui.client.Registry;
|
|
|
9 |
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
|
|
10 |
import com.extjs.gxt.ui.client.widget.ContentPanel;
|
|
|
11 |
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
|
|
12 |
import com.extjs.gxt.ui.client.widget.Html;
|
|
|
13 |
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
|
|
14 |
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
|
1863 |
aurelien |
15 |
import com.google.gwt.core.client.Callback;
|
1860 |
aurelien |
16 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
17 |
import com.google.gwt.event.dom.client.ClickHandler;
|
1863 |
aurelien |
18 |
import com.google.gwt.json.client.JSONParser;
|
|
|
19 |
import com.google.gwt.json.client.JSONValue;
|
1860 |
aurelien |
20 |
import com.google.gwt.user.client.ui.Button;
|
|
|
21 |
import com.google.gwt.user.client.ui.FileUpload;
|
|
|
22 |
import com.google.gwt.user.client.ui.FormPanel;
|
|
|
23 |
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
|
|
|
24 |
import com.google.gwt.user.client.ui.FormPanel.SubmitEvent;
|
|
|
25 |
import com.google.gwt.user.client.ui.Hidden;
|
|
|
26 |
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
27 |
|
|
|
28 |
public abstract class PublicationImportForm extends LayoutContainer {
|
|
|
29 |
|
|
|
30 |
private Mediateur mediateurCourant = null;
|
|
|
31 |
|
|
|
32 |
public PublicationImportForm(Mediateur mediateurCourant) {
|
|
|
33 |
this.mediateurCourant= mediateurCourant;
|
|
|
34 |
|
|
|
35 |
final FormPanel form = new FormPanel();
|
|
|
36 |
form.setAction(PublicationAsyncDao.getUrlImport());
|
|
|
37 |
|
|
|
38 |
form.setEncoding(FormPanel.ENCODING_MULTIPART);
|
|
|
39 |
form.setMethod(FormPanel.METHOD_POST);
|
|
|
40 |
|
|
|
41 |
VerticalPanel panel = new VerticalPanel();
|
|
|
42 |
form.setWidget(panel);
|
|
|
43 |
|
|
|
44 |
FileUpload upload = new FileUpload();
|
|
|
45 |
upload.setName("import_publication");
|
|
|
46 |
panel.add(upload);
|
|
|
47 |
|
|
|
48 |
Hidden typeUpload = new Hidden("type", "publication");
|
|
|
49 |
Hidden utilisateur = new Hidden("ce_utilisateur", ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId());
|
|
|
50 |
|
|
|
51 |
panel.add(typeUpload);
|
|
|
52 |
panel.add(utilisateur);
|
|
|
53 |
|
|
|
54 |
HorizontalPanel boutonsPanel = new HorizontalPanel();
|
|
|
55 |
|
|
|
56 |
boutonsPanel.add(new Button(Mediateur.i18nC.importer(), new ClickHandler() {
|
|
|
57 |
public void onClick(ClickEvent event) {
|
|
|
58 |
form.submit();
|
|
|
59 |
}
|
|
|
60 |
}));
|
|
|
61 |
|
|
|
62 |
boutonsPanel.add(new Button(Mediateur.i18nC.annuler(), new ClickHandler() {
|
|
|
63 |
public void onClick(ClickEvent event) {
|
|
|
64 |
surClicAnnuler();
|
|
|
65 |
}
|
|
|
66 |
}));
|
|
|
67 |
|
|
|
68 |
form.addSubmitHandler(new FormPanel.SubmitHandler() {
|
|
|
69 |
@Override
|
|
|
70 |
public void onSubmit(SubmitEvent event) {
|
|
|
71 |
surSoumissionFormulaire(event);
|
|
|
72 |
}
|
|
|
73 |
});
|
|
|
74 |
|
|
|
75 |
form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
|
|
|
76 |
@Override
|
|
|
77 |
public void onSubmitComplete(SubmitCompleteEvent event) {
|
1863 |
aurelien |
78 |
String resultat = event.getResults();
|
|
|
79 |
// Le formulaire est envoyé à travers un iframe caché, ce qui pose problème
|
|
|
80 |
// à certains navigateurs pour lire le retour
|
|
|
81 |
// si rien n'est renvoyé, on demande les stats d'upload au service par une autre requête
|
|
|
82 |
if(resultat == null || resultat.isEmpty()) {
|
|
|
83 |
PublicationAsyncDao.demanderStatistiquesDernierImport(new Callback<JSONValue, String>() {
|
|
|
84 |
|
|
|
85 |
@Override
|
|
|
86 |
public void onSuccess(JSONValue result) {
|
|
|
87 |
surFormulaireEnvoye(result);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
@Override
|
|
|
91 |
public void onFailure(String reason) {
|
|
|
92 |
// TODO Auto-generated method stub
|
|
|
93 |
}
|
|
|
94 |
});
|
|
|
95 |
} else {
|
|
|
96 |
JSONValue responseValue = JSONParser.parseStrict(resultat);
|
|
|
97 |
surFormulaireEnvoye(responseValue);
|
|
|
98 |
}
|
1860 |
aurelien |
99 |
}
|
|
|
100 |
});
|
|
|
101 |
|
|
|
102 |
Html indicationImportForm = new Html("<div id=\"indication_import_csv\"><a target=\"_blank\" href=\"documents/import_publications.csv\">"+Mediateur.i18nC.telechargerModeleImportPubli()+"</a><br />");
|
|
|
103 |
|
|
|
104 |
add(indicationImportForm);
|
|
|
105 |
add(form);
|
|
|
106 |
add(boutonsPanel);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
public abstract void surSoumissionFormulaire(SubmitEvent event);
|
1863 |
aurelien |
110 |
public abstract void surFormulaireEnvoye(JSONValue reponse);
|
1860 |
aurelien |
111 |
public abstract void surClicAnnuler();
|
|
|
112 |
}
|