Search in sources :

Example 1 with TemplateType

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);
}
Also used : LabelledItem(org.openforis.collect.designer.model.LabelledItem) ListModelList(org.zkoss.zul.ListModelList) ArrayList(java.util.ArrayList) TemplateType(org.openforis.collect.web.controller.SurveyController.SurveyCreationParameters.TemplateType)

Example 2 with TemplateType

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());
}
Also used : LabelledItem(org.openforis.collect.designer.model.LabelledItem) TemplateType(org.openforis.collect.web.controller.SurveyController.SurveyCreationParameters.TemplateType) CollectSurvey(org.openforis.collect.model.CollectSurvey) UserGroup(org.openforis.collect.model.UserGroup) Command(org.zkoss.bind.annotation.Command)

Aggregations

LabelledItem (org.openforis.collect.designer.model.LabelledItem)2 TemplateType (org.openforis.collect.web.controller.SurveyController.SurveyCreationParameters.TemplateType)2 ArrayList (java.util.ArrayList)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 UserGroup (org.openforis.collect.model.UserGroup)1 Command (org.zkoss.bind.annotation.Command)1 ListModelList (org.zkoss.zul.ListModelList)1