437 |
aurelien |
1 |
package org.tela_botanica.client.vues.observation;
|
|
|
2 |
|
2657 |
aurelien |
3 |
import java.util.Iterator;
|
|
|
4 |
import java.util.Map;
|
|
|
5 |
|
2630 |
mathias |
6 |
import org.tela_botanica.client.i18n.Msg;
|
989 |
aurelien |
7 |
import org.tela_botanica.client.modeles.objets.Configuration;
|
1323 |
aurelien |
8 |
import org.tela_botanica.client.modeles.objets.Utilisateur;
|
437 |
aurelien |
9 |
import org.tela_botanica.client.observation.ObservationMediateur;
|
2657 |
aurelien |
10 |
import org.tela_botanica.client.util.Util;
|
2630 |
mathias |
11 |
|
437 |
aurelien |
12 |
import com.google.gwt.user.client.ui.FileUpload;
|
|
|
13 |
import com.google.gwt.user.client.ui.FormPanel;
|
|
|
14 |
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
|
|
|
15 |
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
|
|
|
16 |
import com.google.gwt.user.client.ui.HTML;
|
|
|
17 |
import com.google.gwt.user.client.ui.HasAlignment;
|
1292 |
aurelien |
18 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
481 |
david |
19 |
import com.google.gwt.user.client.ui.Hidden;
|
437 |
aurelien |
20 |
import com.google.gwt.user.client.ui.VerticalPanel;
|
|
|
21 |
import com.gwtext.client.core.EventObject;
|
|
|
22 |
import com.gwtext.client.widgets.Button;
|
|
|
23 |
import com.gwtext.client.widgets.Window;
|
|
|
24 |
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
|
|
|
25 |
|
|
|
26 |
public class FormulaireImportObservationVue {
|
|
|
27 |
|
|
|
28 |
private ObservationMediateur oMediateur = null;
|
481 |
david |
29 |
private Window nPan = null;
|
|
|
30 |
private Hidden identifiant = null;
|
437 |
aurelien |
31 |
|
481 |
david |
32 |
|
437 |
aurelien |
33 |
public FormulaireImportObservationVue(ObservationMediateur om) {
|
481 |
david |
34 |
|
437 |
aurelien |
35 |
this.oMediateur = om;
|
481 |
david |
36 |
|
2630 |
mathias |
37 |
nPan = new Window(Msg.get("import-observations"));
|
481 |
david |
38 |
identifiant = new Hidden();
|
1323 |
aurelien |
39 |
identifiant.setName("utilisateur");
|
|
|
40 |
identifiant.setValue(Utilisateur.getInstance().getIdentifiantUtilisateurConsulte());
|
437 |
aurelien |
41 |
|
|
|
42 |
final FormPanel form = new FormPanel();
|
2630 |
mathias |
43 |
final Button boutonValidation = new Button(Msg.get("envoyer"));
|
481 |
david |
44 |
|
437 |
aurelien |
45 |
form.setEncoding(FormPanel.ENCODING_MULTIPART);
|
|
|
46 |
form.setMethod(FormPanel.METHOD_POST);
|
|
|
47 |
form.setWidth("275px");
|
460 |
aurelien |
48 |
nPan.setWidth("275px");
|
437 |
aurelien |
49 |
|
|
|
50 |
VerticalPanel holder = new VerticalPanel();
|
|
|
51 |
|
|
|
52 |
FileUpload upload = new FileUpload();
|
|
|
53 |
upload.setName("upload");
|
|
|
54 |
holder.add(upload);
|
|
|
55 |
holder.add(boutonValidation);
|
481 |
david |
56 |
holder.add(identifiant);
|
454 |
aurelien |
57 |
|
2630 |
mathias |
58 |
HTML lienVersDocumentModele = new HTML("<a href=\"modele_import.xls\">" + Msg.get("telecharger-modele") + "</a>");
|
454 |
aurelien |
59 |
|
|
|
60 |
holder.add(lienVersDocumentModele);
|
437 |
aurelien |
61 |
|
1292 |
aurelien |
62 |
holder.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
|
437 |
aurelien |
63 |
|
|
|
64 |
boutonValidation.addListener(new ButtonListenerAdapter() {
|
|
|
65 |
|
1292 |
aurelien |
66 |
@Override
|
437 |
aurelien |
67 |
public void onClick(Button button, EventObject e) {
|
|
|
68 |
form.submit();
|
|
|
69 |
}
|
|
|
70 |
});
|
|
|
71 |
|
|
|
72 |
form.add(holder);
|
|
|
73 |
|
|
|
74 |
nPan.add(form);
|
1672 |
aurelien |
75 |
form.setAction(Configuration.getServiceBaseUrl() + "/ImportXLS");
|
437 |
aurelien |
76 |
|
|
|
77 |
form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
|
|
|
78 |
|
1292 |
aurelien |
79 |
@Override
|
437 |
aurelien |
80 |
public void onSubmitComplete(SubmitCompleteEvent event) {
|
444 |
david |
81 |
nPan.close();
|
2657 |
aurelien |
82 |
String message = "";
|
|
|
83 |
Map<String, String> retourImport = Util.parserRetourImportObs(event.getResults());
|
|
|
84 |
for (Iterator<String> iterator = retourImport.keySet().iterator(); iterator
|
|
|
85 |
.hasNext();) {
|
|
|
86 |
String indexRapport = iterator.next();
|
|
|
87 |
// on ne met pas de "-" dans les clés json, mais par contre nos clé i18n
|
|
|
88 |
// sont séparées par des tirets, donc on remplace
|
|
|
89 |
String cleI18n = indexRapport.replace("_", "-");
|
|
|
90 |
Util.LogVersFirebug(cleI18n);
|
2658 |
aurelien |
91 |
String[] StrParams = {retourImport.get(indexRapport).replace("\"", "")};
|
2657 |
aurelien |
92 |
message += Msg.get(cleI18n, StrParams)+"\n";
|
|
|
93 |
}
|
|
|
94 |
com.google.gwt.user.client.Window.alert(message);
|
446 |
aurelien |
95 |
oMediateur.obtenirDernierePageObservation();
|
437 |
aurelien |
96 |
}
|
|
|
97 |
});
|
481 |
david |
98 |
}
|
|
|
99 |
|
|
|
100 |
public void afficher() {
|
437 |
aurelien |
101 |
nPan.show();
|
|
|
102 |
}
|
|
|
103 |
}
|