Search in sources :

Example 16 with Command

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

the class SurveyEditVM method languageCodeSelected.

@Command
@NotifyChange({ "currentLanguageCode" })
public void languageCodeSelected(@BindingParam("code") final String selectedLanguageCode) {
    final SessionStatus sessionStatus = getSessionStatus();
    checkCanLeaveForm(new CanLeaveFormConfirmHandler() {

        @Override
        public void onOk(boolean confirmed) {
            sessionStatus.setCurrentLanguageCode(selectedLanguageCode);
            BindUtils.postGlobalCommand(null, null, SurveyLanguageVM.CURRENT_LANGUAGE_CHANGED_COMMAND, null);
            currentLanguageCode = sessionStatus.getCurrentLanguageCode();
        }
    });
}
Also used : SessionStatus(org.openforis.collect.designer.session.SessionStatus) NotifyChange(org.zkoss.bind.annotation.NotifyChange) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 17 with Command

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

the class SurveyEditVM method exportCeCsvDataImportTemplate.

@Command
public void exportCeCsvDataImportTemplate() throws IOException {
    CSVDataExportJob job = jobManager.createJob(CSVDataExportJob.class);
    job.setOutputFile(File.createTempFile("ce-data-import-template-" + survey.getName(), ".csv"));
    RecordFilter recordFilter = new RecordFilter(survey);
    EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
    recordFilter.setRootEntityId(rootEntityDef.getId());
    CSVDataExportParameters parameters = new CSVDataExportParameters();
    parameters.setRecordFilter(recordFilter);
    parameters.setEntityId(rootEntityDef.getId());
    parameters.setAlwaysGenerateZipFile(false);
    parameters.setIncludeEnumeratedEntities(true);
    job.setParameters(parameters);
    jobManager.start(job, false);
    if (job.isCompleted()) {
        File outputFile = job.getOutputFile();
        String dateStr = Dates.formatLocalDateTime(new Date());
        String fileName = String.format(DATA_IMPORT_TEMPLATE_FILE_NAME_PATTERN, survey.getName(), dateStr, "csv");
        String contentType = URLConnection.guessContentTypeFromName(fileName);
        FileInputStream is = new FileInputStream(outputFile);
        Filedownload.save(is, contentType, fileName);
    } else {
        throw new RuntimeException("Error generating the CSV data export template: " + job.getErrorMessage(), job.getLastException());
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) File(java.io.File) RecordFilter(org.openforis.collect.model.RecordFilter) Date(java.util.Date) FileInputStream(java.io.FileInputStream) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 18 with Command

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

the class SurveyExportParametersVM method export.

@Command
public void export() {
    rdbExportJob = null;
    surveyBackupJob = null;
    String uri = surveySummary.getUri();
    final CollectSurvey loadedSurvey;
    if (surveySummary.isTemporary() && SurveyType.valueOf(formObject.getType()) == TEMPORARY) {
        loadedSurvey = surveyManager.loadSurvey(surveySummary.getId());
    } else {
        loadedSurvey = surveyManager.getByUri(uri);
    }
    switch(formObject.getOutputFormatEnum()) {
        case EARTH:
            validateSurvey(loadedSurvey, collectEarthSurveyValidator, new SuccessHandler() {

                public void onSuccess() {
                    exportCollectEarthSurvey(loadedSurvey, formObject);
                }
            }, true);
            return;
        case RDB:
            startRDBSurveyExportJob(loadedSurvey, formObject);
            break;
        case MOBILE:
            validateSurvey(loadedSurvey, surveyValidator, new SuccessHandler() {

                public void onSuccess() {
                    startCollectSurveyExportJob(loadedSurvey, formObject);
                }
            }, true);
            break;
        default:
            startCollectSurveyExportJob(loadedSurvey, formObject);
            break;
    }
}
Also used : SuccessHandler(org.openforis.collect.designer.util.SuccessHandler) CollectSurvey(org.openforis.collect.model.CollectSurvey) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 19 with Command

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

the class SurveyFileVM method fileUploaded.

@Command
public void fileUploaded(@ContextParam(ContextType.TRIGGER_EVENT) UploadEvent event, @ContextParam(ContextType.BINDER) Binder binder) {
    Media media = event.getMedia();
    String fileName = media.getName();
    File tempFile;
    if (media.isBinary()) {
        tempFile = OpenForisIOUtils.copyToTempFile(media.getStreamData(), FilenameUtils.getExtension(fileName));
    } else {
        tempFile = OpenForisIOUtils.copyToTempFile(media.getReaderData(), FilenameUtils.getExtension(fileName));
    }
    this.uploadedFile = tempFile;
    this.uploadedFileName = normalizeFilename(fileName);
    notifyChange(SurveyFileFormObject.UPLOADED_FILE_NAME_FIELD);
    updateForm(binder);
}
Also used : Media(org.zkoss.util.media.Media) SurveyFile(org.openforis.collect.model.SurveyFile) File(java.io.File) Command(org.zkoss.bind.annotation.Command)

Example 20 with Command

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

the class SurveyLanguageVM method applyChanges.

@Command
public void applyChanges() {
    final SessionStatus sessionStatus = getSessionStatus();
    final CollectSurvey survey = sessionStatus.getSurvey();
    final List<String> newLanguageCodes = getSelectedLanguageCodes();
    final List<String> removedLanguages = calculateRemovedLanguages();
    if (removedLanguages.isEmpty()) {
        performLanguageUpdate(survey, newLanguageCodes);
    } else {
        ConfirmParams confirmParams = new ConfirmParams(new MessageUtil.ConfirmHandler() {

            @Override
            public void onOk() {
                performLanguageUpdate(survey, newLanguageCodes);
            }
        }, "survey.language.remove.confirm");
        confirmParams.setOkLabelKey("global.remove_item");
        confirmParams.setMessageArgs(new String[] { StringUtils.join(removedLanguages, ", ") });
        MessageUtil.showConfirm(confirmParams);
    }
}
Also used : ConfirmParams(org.openforis.collect.designer.util.MessageUtil.ConfirmParams) MessageUtil(org.openforis.collect.designer.util.MessageUtil) SessionStatus(org.openforis.collect.designer.session.SessionStatus) CollectSurvey(org.openforis.collect.model.CollectSurvey) Command(org.zkoss.bind.annotation.Command)

Aggregations

Command (org.zkoss.bind.annotation.Command)62 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)44 NotifyChange (org.zkoss.bind.annotation.NotifyChange)26 File (java.io.File)12 CollectSurvey (org.openforis.collect.model.CollectSurvey)10 MessageUtil (org.openforis.collect.designer.util.MessageUtil)9 UITab (org.openforis.collect.metamodel.ui.UITab)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)6 FileInputStream (java.io.FileInputStream)5 ConfirmParams (org.openforis.collect.designer.util.MessageUtil.ConfirmParams)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)5 SurveyObject (org.openforis.idm.metamodel.SurveyObject)5 Media (org.zkoss.util.media.Media)5 Window (org.zkoss.zul.Window)5 UserCredential (es.bsc.compss.ui.auth.UserCredential)4 IOException (java.io.IOException)4 Date (java.util.Date)4 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 SessionStatus (org.openforis.collect.designer.session.SessionStatus)3 ConfirmHandler (org.openforis.collect.designer.util.MessageUtil.ConfirmHandler)3