Search in sources :

Example 6 with LabelledItem

use of org.openforis.collect.designer.model.LabelledItem in project collect by openforis.

the class NewSurveyParametersPopUpVM method initLanguageModel.

private void initLanguageModel() {
    List<LabelledItem> languages = new ArrayList<LabelledItem>();
    List<String> codes = Languages.getCodes(Standard.ISO_639_1);
    for (String code : codes) {
        LabelledItem item = new LabelledItem(code, Labels.getLabel(code));
        languages.add(item);
    }
    Collections.sort(languages, new LabelComparator());
    languageModel = new BindingListModelListModel<LabelledItem>(new ListModelList<LabelledItem>(languages));
    LabelledItem defaultLanguage = LabelledItem.getByCode(languages, Locale.ENGLISH.getLanguage());
    form.put(LANGUAGE_FIELD_NAME, defaultLanguage);
}
Also used : LabelledItem(org.openforis.collect.designer.model.LabelledItem) ListModelList(org.zkoss.zul.ListModelList) ArrayList(java.util.ArrayList) LabelComparator(org.openforis.collect.designer.model.LabelledItem.LabelComparator)

Example 7 with LabelledItem

use of org.openforis.collect.designer.model.LabelledItem 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)

Example 8 with LabelledItem

use of org.openforis.collect.designer.model.LabelledItem in project collect by openforis.

the class SurveyLanguageVM method getSurveyAssignedLanguages.

protected List<LabelledItem> getSurveyAssignedLanguages() {
    List<LabelledItem> result = new ArrayList<LabelledItem>();
    List<String> assignedLanguageCodes = getSurveyAssignedLanguageCodes();
    for (String code : assignedLanguageCodes) {
        for (LabelledItem item : languages) {
            if (item.getCode().equals(code)) {
                result.add(item);
            }
        }
    }
    return result;
}
Also used : LabelledItem(org.openforis.collect.designer.model.LabelledItem) ArrayList(java.util.ArrayList)

Aggregations

LabelledItem (org.openforis.collect.designer.model.LabelledItem)8 ArrayList (java.util.ArrayList)5 LabelComparator (org.openforis.collect.designer.model.LabelledItem.LabelComparator)3 UserGroup (org.openforis.collect.model.UserGroup)3 ListModelList (org.zkoss.zul.ListModelList)3 TemplateType (org.openforis.collect.web.controller.SurveyController.SurveyCreationParameters.TemplateType)2 AbstractSurveyRestoreJob (org.openforis.collect.io.AbstractSurveyRestoreJob)1 XMLSurveyRestoreJob (org.openforis.collect.io.XMLSurveyRestoreJob)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 User (org.openforis.collect.model.User)1 Command (org.zkoss.bind.annotation.Command)1 DependsOn (org.zkoss.bind.annotation.DependsOn)1 Init (org.zkoss.bind.annotation.Init)1