Search in sources :

Example 6 with FileUploadField

use of com.extjs.gxt.ui.client.widget.form.FileUploadField in project kapua by eclipse.

the class SSLFileUploadDialog method onRender.

@Override
protected void onRender(Element parent, int pos) {
    super.onRender(parent, pos);
    setLayout(new FormLayout());
    setBodyBorder(false);
    setModal(true);
    setButtons("");
    setAutoWidth(true);
    setScrollMode(Scroll.AUTO);
    setHideOnButtonClick(false);
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(false);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setBodyBorder(false);
    m_formPanel.setAction(m_url);
    m_formPanel.setEncoding(Encoding.MULTIPART);
    m_formPanel.setMethod(Method.POST);
    m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
    m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {

        HiddenField<Boolean> success = new HiddenField<Boolean>();

        @Override
        public void handleEvent(FormEvent be) {
            String htmlResponse = be.getResultHtml();
            if (htmlResponse == null || htmlResponse.isEmpty()) {
                success = new HiddenField<Boolean>();
                success.setName("success");
                success.setValue(true);
                m_hiddenFields.set(0, success);
            } else {
                String errMsg = htmlResponse;
                int startIdx = htmlResponse.indexOf("<pre>");
                int endIndex = htmlResponse.indexOf("</pre>");
                if (startIdx != -1 && endIndex != -1) {
                    errMsg = htmlResponse.substring(startIdx + 5, endIndex);
                }
                MessageBox.alert(MSGS.error(), MSGS.fileUploadFailure() + ": " + errMsg, null);
                success = new HiddenField<Boolean>();
                success.setName("success");
                success.setValue(false);
                m_hiddenFields.set(0, success);
            }
            hide();
        }
    });
    m_fileUploadFieldCert = new FileUploadField();
    m_fileUploadFieldCert.setAllowBlank(false);
    m_fileUploadFieldCert.setName("uploadedSSLCert");
    m_fileUploadFieldCert.setFieldLabel("SSL Certificate");
    m_formPanel.add(m_fileUploadFieldCert);
    m_fileUploadFieldKey = new FileUploadField();
    m_fileUploadFieldKey.setAllowBlank(false);
    m_fileUploadFieldKey.setName("uploadedSSLKey");
    m_fileUploadFieldKey.setFieldLabel("SSL Key");
    m_formPanel.add(m_fileUploadFieldKey);
    if (m_hiddenFields != null) {
        for (HiddenField<?> hf : m_hiddenFields) {
            m_formPanel.add(hf);
        }
    }
    // 
    // xsrfToken Hidden field
    // 
    gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

        @Override
        public void onFailure(Throwable ex) {
            FailureHandler.handle(ex);
        }

        @Override
        public void onSuccess(GwtXSRFToken token) {
            xsrfTokenField.setValue(token.getToken());
        }
    });
    xsrfTokenField = new HiddenField<String>();
    xsrfTokenField.setId("xsrfToken");
    xsrfTokenField.setName("xsrfToken");
    xsrfTokenField.setValue("");
    // Add the xsrf hidden field to the form panel
    m_formPanel.add(xsrfTokenField);
    add(m_formPanel);
}
Also used : FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) HiddenField(com.extjs.gxt.ui.client.widget.form.HiddenField) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) FileUploadField(com.extjs.gxt.ui.client.widget.form.FileUploadField) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) FormEvent(com.extjs.gxt.ui.client.event.FormEvent)

Aggregations

FormEvent (com.extjs.gxt.ui.client.event.FormEvent)6 FileUploadField (com.extjs.gxt.ui.client.widget.form.FileUploadField)6 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)6 FormLayout (com.extjs.gxt.ui.client.widget.layout.FormLayout)5 FormData (com.extjs.gxt.ui.client.widget.layout.FormData)3 GwtXSRFToken (org.eclipse.kura.web.shared.model.GwtXSRFToken)3 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)2 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)2 GwtXSRFToken (org.eclipse.kapua.app.console.shared.model.GwtXSRFToken)2 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 Listener (com.extjs.gxt.ui.client.event.Listener)1 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)1 Margins (com.extjs.gxt.ui.client.util.Margins)1 ContentPanel (com.extjs.gxt.ui.client.widget.ContentPanel)1 LayoutContainer (com.extjs.gxt.ui.client.widget.LayoutContainer)1 TabItem (com.extjs.gxt.ui.client.widget.TabItem)1 TabPanel (com.extjs.gxt.ui.client.widget.TabPanel)1 HiddenField (com.extjs.gxt.ui.client.widget.form.HiddenField)1 TextArea (com.extjs.gxt.ui.client.widget.form.TextArea)1