Search in sources :

Example 1 with TextFieldMeta

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

the class FieldTranslator method translateTextField.

public TextFieldMeta translateTextField(String name, Integer columns, Boolean autogrow, List<RightAnswer> rightAnswers, String help, String hint) {
    List<TextFieldRightAnswer> translatedAnswers = new ArrayList<>();
    for (fi.otavanopisto.muikku.plugins.dnm.parser.content.RightAnswer rightAnswer : rightAnswers) {
        Boolean correct = rightAnswer.getPoints() != null && rightAnswer.getPoints() > 0;
        translatedAnswers.add(new TextFieldRightAnswer(rightAnswer.getText(), true, false, correct));
    }
    return new TextFieldMeta(name, columns, autogrow, translatedAnswers, hint);
}
Also used : RightAnswer(fi.otavanopisto.muikku.plugins.dnm.parser.content.RightAnswer) TextFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta) ArrayList(java.util.ArrayList) TextFieldRightAnswer(fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldRightAnswer)

Example 2 with TextFieldMeta

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

the class FieldElementsHandler method handleTextField.

@Override
public Node handleTextField(org.w3c.dom.Document ownerDocument, String paramName, Integer columns, Boolean autogrow, List<RightAnswer> rightAnswers, String help, String hint) {
    // TODO: This is just for show, real implementation depends on QueryMaterial implementation
    TextFieldMeta textFieldData = fieldTranslator.translateTextField(paramName, columns, autogrow, rightAnswers, help, hint);
    Element inputElement = ownerDocument.createElement("input");
    inputElement.setAttribute("type", "text");
    inputElement.setAttribute("name", paramName);
    inputElement.setAttribute("size", String.valueOf(columns));
    return wrapWithObjectElement(ownerDocument, inputElement, textFieldData);
}
Also used : TextFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta) Element(org.w3c.dom.Element)

Example 3 with TextFieldMeta

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

the class HtmlMaterialFieldChangeListener method onHtmlMaterialTextFieldCreated.

// Create
// Text field
public void onHtmlMaterialTextFieldCreated(@Observes HtmlMaterialFieldCreateEvent event) throws MaterialQueryIntegrityExeption, MaterialFieldMetaParsingExeption {
    if (event.getField().getType().equals("application/vnd.muikku.field.text")) {
        ObjectMapper objectMapper = new ObjectMapper();
        TextFieldMeta textFieldMeta;
        try {
            textFieldMeta = objectMapper.readValue(event.getField().getContent(), TextFieldMeta.class);
        } catch (IOException e) {
            throw new MaterialFieldMetaParsingExeption("Could not parse text field meta", e);
        }
        QueryField queryField = queryFieldController.findQueryFieldByMaterialAndName(event.getMaterial(), textFieldMeta.getName());
        if (queryField == null) {
            queryTextFieldController.createQueryTextField(event.getMaterial(), textFieldMeta.getName());
        } else {
            throw new MaterialQueryIntegrityExeption("Field with same name already exists in the database");
        }
    }
}
Also used : QueryField(fi.otavanopisto.muikku.plugins.material.model.QueryField) TextFieldMeta(fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

TextFieldMeta (fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldMeta)3 RightAnswer (fi.otavanopisto.muikku.plugins.dnm.parser.content.RightAnswer)1 TextFieldRightAnswer (fi.otavanopisto.muikku.plugins.material.fieldmeta.TextFieldRightAnswer)1 QueryField (fi.otavanopisto.muikku.plugins.material.model.QueryField)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 Element (org.w3c.dom.Element)1