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);
}
});
}
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);
}
});
}
Aggregations