Subversion Repositories eFlore/Applications.coel

Rev

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

package org.tela_botanica.client.vues.publication;

import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.modeles.publication.Publication;
import org.tela_botanica.client.modeles.publication.PublicationAsyncDao;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
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.SubmitEvent;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.VerticalPanel;

public abstract class PublicationImportForm extends LayoutContainer {

        private Mediateur mediateurCourant = null;

        public PublicationImportForm(Mediateur mediateurCourant) {
                this.mediateurCourant= mediateurCourant; 
                                                
            final FormPanel form = new FormPanel();
            form.setAction(PublicationAsyncDao.getUrlImport());

            form.setEncoding(FormPanel.ENCODING_MULTIPART);
            form.setMethod(FormPanel.METHOD_POST);
                    
            VerticalPanel panel = new VerticalPanel();
            form.setWidget(panel);

            FileUpload upload = new FileUpload();
            upload.setName("import_publication");
            panel.add(upload);
            
            Hidden typeUpload = new Hidden("type", "publication");
            Hidden utilisateur = new Hidden("ce_utilisateur", ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId());
            
            panel.add(typeUpload);
            panel.add(utilisateur);

            HorizontalPanel boutonsPanel = new HorizontalPanel();
           
            boutonsPanel.add(new Button(Mediateur.i18nC.importer(), new ClickHandler() {
              public void onClick(ClickEvent event) {
                form.submit();
              }
            }));
            
            boutonsPanel.add(new Button(Mediateur.i18nC.annuler(), new ClickHandler() {
              public void onClick(ClickEvent event) {
                  surClicAnnuler();
              }
            }));

            form.addSubmitHandler(new FormPanel.SubmitHandler() {
                        @Override
                        public void onSubmit(SubmitEvent event) {
                                surSoumissionFormulaire(event);
                        }
            });
            
            form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
                        @Override
                        public void onSubmitComplete(SubmitCompleteEvent event) {
                                surFormulaireEnvoye(event);
                        }
            });
            
            Html indicationImportForm = new Html("<div id=\"indication_import_csv\"><a target=\"_blank\" href=\"documents/import_publications.csv\">"+Mediateur.i18nC.telechargerModeleImportPubli()+"</a><br />");
            
            add(indicationImportForm);
            add(form);
            add(boutonsPanel);
        }
        
        public abstract void surSoumissionFormulaire(SubmitEvent event);
        public abstract void surFormulaireEnvoye(SubmitCompleteEvent event);
        public abstract void surClicAnnuler();
}