Subversion Repositories eFlore/Applications.cel

Rev

Rev 1813 | Rev 2657 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.vues.observation;

import org.tela_botanica.client.i18n.Msg;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.modeles.objets.Utilisateur;
import org.tela_botanica.client.observation.ObservationMediateur;

import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;

public class FormulaireImportObservationVue {
        
        private ObservationMediateur oMediateur = null;
        private  Window nPan = null;
        private Hidden identifiant = null;
        
        
        public FormulaireImportObservationVue(ObservationMediateur om) {
        
                this.oMediateur = om;

                nPan = new Window(Msg.get("import-observations"));
                identifiant = new Hidden();
                identifiant.setName("utilisateur");
                identifiant.setValue(Utilisateur.getInstance().getIdentifiantUtilisateurConsulte());
                
                final FormPanel form = new FormPanel();
                final Button boutonValidation = new Button(Msg.get("envoyer"));
                
                form.setEncoding(FormPanel.ENCODING_MULTIPART);
                form.setMethod(FormPanel.METHOD_POST);
                form.setWidth("275px");
                nPan.setWidth("275px");

                VerticalPanel holder = new VerticalPanel();

                FileUpload upload = new FileUpload();
                upload.setName("upload");
                holder.add(upload);
                holder.add(boutonValidation);
                holder.add(identifiant);
                
                HTML lienVersDocumentModele = new HTML("<a href=\"modele_import.xls\">" + Msg.get("telecharger-modele") + "</a>");
                
                holder.add(lienVersDocumentModele);

                holder.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
                
                boutonValidation.addListener(new ButtonListenerAdapter() {
                                                
                        @Override
                        public void onClick(Button button, EventObject e) {
                                form.submit();
                        }
                });

                form.add(holder);
                
                nPan.add(form);
                form.setAction(Configuration.getServiceBaseUrl() + "/ImportXLS");
                
                form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
                        
                        @Override
                        public void onSubmitComplete(SubmitCompleteEvent event) {
                                nPan.close();
                                // TODO: le résultat est du texte, mais à l'avenir il faudrait utiliser du JSON
                                com.google.gwt.user.client.Window.alert(event.getResults());
                                oMediateur.obtenirDernierePageObservation();
                        }
                });
        }
        
        public void afficher() {
                nPan.show();
        }
}