use of org.openforis.collect.web.controller.SurveyController.SurveyCreationParameters.TemplateType in project collect by openforis.
the class NewSurveyParametersPopUpVM method initTemplatesModel.
private void initTemplatesModel() {
List<LabelledItem> templates = new ArrayList<LabelledItem>();
for (TemplateType templateType : TemplateType.values()) {
String name = templateType.name();
templates.add(new LabelledItem(name, Labels.getLabel("survey.template.type." + name.toLowerCase(Locale.ENGLISH))));
}
templateModel = new BindingListModelListModel<LabelledItem>(new ListModelList<LabelledItem>(templates));
templateModel.setMultiple(false);
LabelledItem defaultTemplate = LabelledItem.getByCode(templates, TemplateType.BLANK.name());
form.put(TEMPLATE_FIELD_NAME, defaultTemplate);
}
use of org.openforis.collect.web.controller.SurveyController.SurveyCreationParameters.TemplateType in project collect by openforis.
the class NewSurveyParametersPopUpVM method ok.
@Command
public void ok() throws IdmlParseException, SurveyValidationException, SurveyStoreException {
String name = (String) form.get(SURVEY_NAME_FIELD);
String langCode = ((LabelledItem) form.get(LANGUAGE_FIELD_NAME)).getCode();
String templateCode = ((LabelledItem) form.get(TEMPLATE_FIELD_NAME)).getCode();
TemplateType templateType = TemplateType.valueOf(templateCode);
String userGroupName = ((LabelledItem) form.get(USER_GROUP_FIELD_NAME)).getCode();
CollectSurvey survey;
switch(templateType) {
case BLANK:
survey = createEmptySurvey(name, langCode);
break;
default:
survey = createNewSurveyFromTemplate(name, langCode, templateType);
}
UserGroup userGroup = userGroupManager.findByName(userGroupName);
survey.setUserGroupId(userGroup.getId());
surveyManager.save(survey);
SurveyEditVM.redirectToSurveyEditPage(survey.getId());
}
Aggregations