Search in sources :

Example 1 with GlobalCommand

use of org.zkoss.bind.annotation.GlobalCommand in project collect by openforis.

the class CodeListsVM method jobFailed.

@GlobalCommand
public void jobFailed(@BindingParam("job") Job job) {
    closeJobStatusPopUp();
    if (job instanceof CodeListBatchImportJob && job.getCurrentTask() != null) {
        CodeListImportTask lastTask = (CodeListImportTask) ((CodeListBatchImportJob) job).getCurrentTask();
        dataImportErrorPopUp = ReferenceDataImportErrorPopUpVM.showPopUp(lastTask.getErrors(), Labels.getLabel("survey.code_list.import_data.error_popup.title", new String[] { lastTask.getEntryName() }));
    } else {
        String errorMessageKey = job.getErrorMessage();
        String errorMessage = StringUtils.defaultIfBlank(Labels.getLabel(errorMessageKey), errorMessageKey);
        MessageUtil.showError("global.job_status.failed.message", errorMessage);
    }
    clearJob(job);
}
Also used : CodeListImportTask(org.openforis.collect.io.metadata.codelist.CodeListImportTask) CodeListBatchImportJob(org.openforis.collect.io.metadata.codelist.CodeListBatchImportJob) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 2 with GlobalCommand

use of org.zkoss.bind.annotation.GlobalCommand in project collect by openforis.

the class CodeListsVM method closeCodeListImportPopUp.

@GlobalCommand
public void closeCodeListImportPopUp() {
    closePopUp(codeListImportPopUp);
    codeListImportPopUp = null;
    if (editedItem != null) {
        boolean hasMultipleLevels = editedItem.getHierarchy().size() > 1;
        Type type = hasMultipleLevels ? Type.HIERARCHICAL : Type.FLAT;
        CodeListFormObject fo = (CodeListFormObject) formObject;
        fo.setType(type.name());
        selectedItemsPerLevel = new ArrayList<CodeListItem>();
        initItemsPerLevel();
        notifyChange("formObject", "listLevels", "selectedItemsPerLevel");
    }
}
Also used : Type(org.openforis.collect.designer.form.CodeListFormObject.Type) ContextType(org.zkoss.bind.annotation.ContextType) CodeListFormObject(org.openforis.collect.designer.form.CodeListFormObject) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 3 with GlobalCommand

use of org.zkoss.bind.annotation.GlobalCommand in project collect by openforis.

the class CodeListsVM method closeCodeListItemPopUp.

@GlobalCommand
public void closeCodeListItemPopUp(@BindingParam("undoChanges") boolean undoChanges, @BindingParam("imageModified") boolean imageModified, @BindingParam("imageFileWrapper") FileWrapper imageFileWrapper) {
    if (codeListItemPopUp == null) {
        // handling code list from node editor form?
        return;
    }
    closePopUp(codeListItemPopUp);
    codeListItemPopUp = null;
    if (undoChanges) {
        dispatchCurrentFormValidatedCommand(true);
    } else {
        if (newChildItem) {
            addChildItemToCodeList();
        } else {
            dispatchSurveySaveCommand();
            if (editedChildItem instanceof PersistedCodeListItem) {
                codeListManager.save((PersistedCodeListItem) editedChildItem);
            }
            BindUtils.postNotifyChange(null, null, editedChildItem, "*");
        }
        if (imageModified) {
            PersistedCodeListItem persistedItem;
            if (editedChildItem instanceof PersistedCodeListItem) {
                persistedItem = (PersistedCodeListItem) editedChildItem;
            } else {
                CodeList codeList = editedChildItem.getCodeList();
                codeListManager.persistCodeListItems(codeList);
                reloadSelectedItems();
                initItemsPerLevel();
                persistedItem = codeListManager.loadItem(codeList, editedChildItem.getId());
            }
            if (imageFileWrapper == null) {
                codeListManager.deleteImageContent(persistedItem);
            } else {
                codeListManager.saveImageContent(persistedItem, imageFileWrapper);
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 4 with GlobalCommand

use of org.zkoss.bind.annotation.GlobalCommand in project collect by openforis.

the class SurveyEditVM method openCodeListsManagerPopUp.

@GlobalCommand
public void openCodeListsManagerPopUp(@BindingParam(EDITING_ATTRIBUTE_PARAM) Boolean editingAttribute, @BindingParam(SELECTED_CODE_LIST_PARAM) CodeList selectedCodeList) {
    if (codeListsPopUp == null) {
        dispatchCurrentFormValidatedCommand(true);
        Map<String, Object> args = new HashMap<String, Object>();
        args.put(EDITING_ATTRIBUTE_PARAM, editingAttribute);
        CodeList selectedCodeListInPopUp = selectedCodeList == survey.getSamplingDesignCodeList() ? null : selectedCodeList;
        args.put(SELECTED_CODE_LIST_PARAM, selectedCodeListInPopUp);
        codeListsPopUp = openPopUp(Resources.Component.CODE_LISTS_POPUP.getLocation(), true, args);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) HashMap(java.util.HashMap) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 5 with GlobalCommand

use of org.zkoss.bind.annotation.GlobalCommand in project collect by openforis.

the class SurveyEditVM method jobCompleted.

@GlobalCommand
public void jobCompleted(@BindingParam("job") Job job) {
    closeJobStatusPopUp();
    if (job instanceof SchemaSummaryCSVExportJob) {
        File file = ((SchemaSummaryCSVExportJob) job).getOutputFile();
        String surveyName = survey.getName();
        String dateStr = Dates.formatLocalDateTime(new Date());
        String fileName = String.format(SCHEMA_SUMMARY_FILE_NAME_PATTERN, surveyName, dateStr, "csv");
        String contentType = URLConnection.guessContentTypeFromName(fileName);
        try {
            FileInputStream is = new FileInputStream(file);
            Filedownload.save(is, contentType, fileName);
        } catch (FileNotFoundException e) {
            log.error(e);
            MessageUtil.showError("survey.schema.export_summary.error", e.getMessage());
        }
    }
}
Also used : SchemaSummaryCSVExportJob(org.openforis.collect.io.metadata.SchemaSummaryCSVExportJob) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) Date(java.util.Date) FileInputStream(java.io.FileInputStream) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Aggregations

GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)13 CodeList (org.openforis.idm.metamodel.CodeList)3 File (java.io.File)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)2 Component (org.zkoss.zk.ui.Component)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 CodeAttributeDefinitionFormObject (org.openforis.collect.designer.form.CodeAttributeDefinitionFormObject)1 CodeListFormObject (org.openforis.collect.designer.form.CodeListFormObject)1 Type (org.openforis.collect.designer.form.CodeListFormObject.Type)1 DataBackupError (org.openforis.collect.io.data.DataBackupError)1 SchemaSummaryCSVExportJob (org.openforis.collect.io.metadata.SchemaSummaryCSVExportJob)1 CodeListBatchImportJob (org.openforis.collect.io.metadata.codelist.CodeListBatchImportJob)1 CodeListImportTask (org.openforis.collect.io.metadata.codelist.CodeListImportTask)1 SurveySummary (org.openforis.collect.model.SurveySummary)1 SurveyStoreException (org.openforis.collect.persistence.SurveyStoreException)1