Search in sources :

Example 6 with SelectFieldOptionMeta

use of fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta in project muikku by otavanopisto.

the class FieldElementsHandler method handleListSelectField.

private Node handleListSelectField(Document ownerDocument, SelectFieldMeta selectFieldMeta) {
    Element selectElement = ownerDocument.createElement("select");
    selectElement.setAttribute("name", selectFieldMeta.getName());
    for (SelectFieldOptionMeta option : selectFieldMeta.getOptions()) {
        Element optionElement = ownerDocument.createElement("option");
        optionElement.setAttribute("value", option.getName());
        optionElement.setTextContent(option.getText());
        selectElement.appendChild(optionElement);
    }
    return wrapWithObjectElement(ownerDocument, selectElement, selectFieldMeta);
}
Also used : Element(org.w3c.dom.Element) SelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta) MultiSelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta)

Example 7 with SelectFieldOptionMeta

use of fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta 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)

Example 8 with SelectFieldOptionMeta

use of fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta in project muikku by otavanopisto.

the class HtmlMaterialFieldChangeListener method onHtmlMaterialSelectFieldCreated.

// Select field
public void onHtmlMaterialSelectFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
    if (event.getField().getType().equals("application/vnd.muikku.field.select")) {
        ObjectMapper objectMapper = new ObjectMapper();
        SelectFieldMeta selectFieldMeta;
        try {
            selectFieldMeta = objectMapper.readValue(event.getField().getContent(), SelectFieldMeta.class);
        } catch (IOException e) {
            throw new MaterialFieldMetaParsingExeption("Could not parse select field meta", e);
        }
        QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), selectFieldMeta.getName());
        if (queryField != null) {
            throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
        }
        QuerySelectField querySelectField = querySelectFieldController.createQuerySelectField(event.getMaterial(), selectFieldMeta.getName());
        for (SelectFieldOptionMeta selectFieldOptionMeta : selectFieldMeta.getOptions()) {
            querySelectFieldController.createQuerySelectFieldOption(querySelectField, selectFieldOptionMeta.getName(), selectFieldOptionMeta.getText());
        }
    }
}
Also used : SelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldMeta) MultiSelectFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta) QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) IOException(java.io.IOException) QuerySelectField(fi.otavanopisto.muikku.plugins.material.model.QuerySelectField) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta) MultiSelectFieldOptionMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta)

Aggregations

SelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldOptionMeta)8 MultiSelectFieldOptionMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldOptionMeta)7 SelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.SelectFieldMeta)4 ArrayList (java.util.ArrayList)4 Element (org.w3c.dom.Element)4 MultiSelectFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.MultiSelectFieldMeta)3 QuerySelectField (fi.otavanopisto.muikku.plugins.material.model.QuerySelectField)3 IOException (java.io.IOException)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 QuerySelectFieldOption (fi.otavanopisto.muikku.plugins.material.model.QuerySelectFieldOption)2 OptionListOption (fi.otavanopisto.muikku.plugins.dnm.parser.content.OptionListOption)1 MaterialFieldMetaParsingExeption (fi.otavanopisto.muikku.plugins.material.MaterialFieldMetaParsingExeption)1 QueryFieldUpdateEvent (fi.otavanopisto.muikku.plugins.material.events.QueryFieldUpdateEvent)1 QueryField (fi.otavanopisto.muikku.plugins.material.model.QueryField)1 WorkspaceMaterialSelectFieldAnswer (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterialSelectFieldAnswer)1