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