Search in sources :

Example 1 with OptionListOption

use of fi.otavanopisto.muikku.plugins.dnm.parser.content.OptionListOption in project muikku by otavanopisto.

the class FieldTranslator method translateOptionList.

public SelectFieldMeta translateOptionList(String name, String listType, List<OptionListOption> options) {
    List<SelectFieldOptionMeta> translatedOptions = new ArrayList<>();
    for (OptionListOption option : options) {
        translatedOptions.add(new SelectFieldOptionMeta(option.getName(), option.getPoints() != null && option.getPoints() > 0, option.getText()));
    }
    // Fix for bug #499; generate unique values for empty option names
    for (SelectFieldOptionMeta translatedOption : translatedOptions) {
        if (StringUtils.isEmpty(translatedOption.getName())) {
            translatedOption.setName(generateUniqueName(translatedOptions));
        }
    }
    // Nexus:  dropdown | list | radio | radio_horz
    // Muikku: dropdown | list | radio-vertical | radio-horizontal
    String newListType = listType;
    if ("radio".equals(listType)) {
        newListType = "radio-vertical";
    } else if ("radio_horz".equals(listType)) {
        newListType = "radio-horizontal";
    }
    return new SelectFieldMeta(name, newListType, translatedOptions, null);
}
Also used : SelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldMeta) MultiSelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta) ArrayList(java.util.ArrayList) OptionListOption(fi.otavanopisto.muikku.plugins.dnm.parser.content.OptionListOption) MultiSelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta) SelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta)

Aggregations

OptionListOption (fi.otavanopisto.muikku.plugins.dnm.parser.content.OptionListOption)1 MultiSelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta)1 MultiSelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta)1 SelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldMeta)1 SelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta)1 ArrayList (java.util.ArrayList)1