Search in sources :

Example 1 with FileFieldSizeCheckBehavior

use of org.wicketstuff.html5.fileapi.FileFieldSizeCheckBehavior in project projectforge by micromata.

the class DatevImportForm method init.

@SuppressWarnings("serial")
@Override
protected void init() {
    super.init();
    this.setOutputMarkupId(true);
    Bytes maxSize = Bytes.valueOf(configurationService.getMaxFileSizeDatev());
    this.setMaxSize(maxSize);
    gridBuilder.newGridPanel();
    String hint = I18nHelper.getLocalizedMessage("finance.datev.upload.hint", NumberHelper.formatBytes(maxSize.bytes()));
    final FieldsetPanel fs = gridBuilder.newFieldset(getString("file"), hint);
    fileUploadField = new FileUploadField(FileUploadPanel.WICKET_ID);
    fs.add(new FileUploadPanel(fs.newChildId(), fileUploadField));
    fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID, new Model<String>("uploadAccounts")) {

        @Override
        public final void onSubmit() {
            parentPage.importAccountList();
        }
    }, getString("finance.datev.uploadAccountList"), SingleButtonPanel.NORMAL).setTooltip(getString("common.import.upload.tooltip")));
    fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID, new Model<String>("uploadRecords")) {

        @Override
        public final void onSubmit() {
            parentPage.importAccountRecords();
        }
    }, getString("finance.datev.uploadAccountingRecords"), SingleButtonPanel.NORMAL).setTooltip(getString("common.import.upload.tooltip")));
    addClearButton(fs);
    addImportFilterRadio(gridBuilder);
    // Statistics
    new BusinessAssessment4Fieldset(gridBuilder) {

        /**
         * @see org.projectforge.web.fibu.BusinessAssessment4Fieldset#getBusinessAssessment()
         */
        @Override
        protected BusinessAssessment getBusinessAssessment() {
            return storagePanel.businessAssessment;
        }

        @Override
        public boolean isVisible() {
            return storagePanel.businessAssessment != null;
        }
    };
    gridBuilder.newGridPanel();
    final DivPanel panel = gridBuilder.getPanel();
    storagePanel = new DatevImportStoragePanel(panel.newChildId(), parentPage, importFilter);
    panel.add(storagePanel);
    this.fileUploadField.add(new FileFieldSizeCheckBehavior() {

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final FileList fileList) {
            // return form to remove errors
            target.add(DatevImportForm.this.feedbackPanel);
        }

        @Override
        protected void addErrorMsg(AjaxRequestTarget target, FileList fileList) {
            DatevImportForm.this.addError("common.uploadpanel.filetolarge", NumberHelper.formatBytes(maxSize.bytes()));
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final FileList fileList) {
            // clear input field to avoid uploading the image
            DatevImportForm.this.fileUploadField.clearInput();
            // return form
            target.add(DatevImportForm.this);
        }
    });
}
Also used : FileList(org.wicketstuff.html5.fileapi.FileList) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Bytes(org.apache.wicket.util.lang.Bytes) Button(org.apache.wicket.markup.html.form.Button) FileFieldSizeCheckBehavior(org.wicketstuff.html5.fileapi.FileFieldSizeCheckBehavior) Model(org.apache.wicket.model.Model) FieldsetPanel(org.projectforge.web.wicket.flowlayout.FieldsetPanel) FileUploadPanel(org.projectforge.web.wicket.flowlayout.FileUploadPanel) DivPanel(org.projectforge.web.wicket.flowlayout.DivPanel) SingleButtonPanel(org.projectforge.web.wicket.components.SingleButtonPanel)

Example 2 with FileFieldSizeCheckBehavior

use of org.wicketstuff.html5.fileapi.FileFieldSizeCheckBehavior in project projectforge by micromata.

the class SetupImportForm method init.

@Override
@SuppressWarnings("serial")
protected void init() {
    FeedbackPanel feedbackPanel = createFeedbackPanel();
    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);
    this.setOutputMarkupId(true);
    // set max size
    Bytes maxSize = Bytes.valueOf(configurationService.getMaxFileSizeXmlDumpImport());
    this.setMaxSize(maxSize);
    this.setMultiPart(true);
    final GridBuilder gridBuilder = newGridBuilder(this, "flowform");
    gridBuilder.newFormHeading(getString("import"));
    {
        // Upload dump file
        final FieldsetPanel fs = gridBuilder.newFieldset(getString("administration.setup.dumpFile"));
        fileUploadField = new FileUploadField(FileUploadPanel.WICKET_ID);
        fs.add(new FileUploadPanel(fs.newChildId(), fileUploadField));
    }
    final RepeatingView actionButtons = new RepeatingView("buttons");
    add(actionButtons);
    {
        final Button importButton = new Button(SingleButtonPanel.WICKET_ID, new Model<String>("import")) {

            @Override
            public final void onSubmit() {
                csrfTokenHandler.onSubmit();
                parentPage.upload();
            }
        };
        final SingleButtonPanel importButtonPanel = new SingleButtonPanel(actionButtons.newChildId(), importButton, getString("import"), SingleButtonPanel.DEFAULT_SUBMIT);
        actionButtons.add(importButtonPanel);
    }
    this.fileUploadField.add(new FileFieldSizeCheckBehavior() {

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final FileList fileList) {
            if (fileList.getNumOfFiles() == 1) {
                if (false == (fileList.get(0).getName().endsWith(".xml.gz") || fileList.get(0).getName().endsWith(".xml")))
                    SetupImportForm.this.addError("common.uploadpanel.filewrongtype", ".xml; .xml.gz");
            }
            // return form to remove errors
            target.add(feedbackPanel);
        }

        @Override
        protected void addErrorMsg(AjaxRequestTarget target, FileList fileList) {
            SetupImportForm.this.addError("common.uploadpanel.filetolarge", NumberHelper.formatBytes(maxSize.bytes()));
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final FileList fileList) {
            // clear input field to avoid uploading the image
            SetupImportForm.this.fileUploadField.clearInput();
            // return form
            target.add(SetupImportForm.this);
        }
    });
}
Also used : FileList(org.wicketstuff.html5.fileapi.FileList) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) GridBuilder(org.projectforge.web.wicket.bootstrap.GridBuilder) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Bytes(org.apache.wicket.util.lang.Bytes) FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) Button(org.apache.wicket.markup.html.form.Button) FileFieldSizeCheckBehavior(org.wicketstuff.html5.fileapi.FileFieldSizeCheckBehavior) Model(org.apache.wicket.model.Model) FieldsetPanel(org.projectforge.web.wicket.flowlayout.FieldsetPanel) FileUploadPanel(org.projectforge.web.wicket.flowlayout.FileUploadPanel) SingleButtonPanel(org.projectforge.web.wicket.components.SingleButtonPanel)

Aggregations

AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 Button (org.apache.wicket.markup.html.form.Button)2 FileUploadField (org.apache.wicket.markup.html.form.upload.FileUploadField)2 Model (org.apache.wicket.model.Model)2 Bytes (org.apache.wicket.util.lang.Bytes)2 SingleButtonPanel (org.projectforge.web.wicket.components.SingleButtonPanel)2 FieldsetPanel (org.projectforge.web.wicket.flowlayout.FieldsetPanel)2 FileUploadPanel (org.projectforge.web.wicket.flowlayout.FileUploadPanel)2 FileFieldSizeCheckBehavior (org.wicketstuff.html5.fileapi.FileFieldSizeCheckBehavior)2 FileList (org.wicketstuff.html5.fileapi.FileList)2 FeedbackPanel (org.apache.wicket.markup.html.panel.FeedbackPanel)1 RepeatingView (org.apache.wicket.markup.repeater.RepeatingView)1 GridBuilder (org.projectforge.web.wicket.bootstrap.GridBuilder)1 DivPanel (org.projectforge.web.wicket.flowlayout.DivPanel)1