Search in sources :

Example 6 with TextInputWrapper

use of org.olat.modules.forms.ui.model.TextInputWrapper in project OpenOLAT by OpenOLAT.

the class EvaluationFormController method forgeTextInput.

private EvaluationFormElementWrapper forgeTextInput(TextInput element) {
    String initialValue = "";
    EvaluationFormResponse response = identifierToResponses.get(element.getId());
    if (response != null && StringHelper.containsNonWhitespace(response.getStringuifiedResponse())) {
        initialValue = response.getStringuifiedResponse();
    }
    int rows = 12;
    if (element.getRows() > 0) {
        rows = element.getRows();
    }
    TextElement textEl = uifactory.addTextAreaElement("textinput_" + (count++), null, Integer.MAX_VALUE, rows, 72, false, initialValue, flc);
    textEl.setEnabled(!readOnly);
    FormLink saveButton = uifactory.addFormLink("save_" + (count++), "save", null, flc, Link.BUTTON);
    saveButton.setVisible(!readOnly);
    TextInputWrapper textInputWrapper = new TextInputWrapper(element, textEl, saveButton);
    saveButton.setUserObject(textInputWrapper);
    textEl.setUserObject(textInputWrapper);
    EvaluationFormElementWrapper wrapper = new EvaluationFormElementWrapper(element);
    wrapper.setTextInputWrapper(textInputWrapper);
    return wrapper;
}
Also used : TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) TextInputWrapper(org.olat.modules.forms.ui.model.TextInputWrapper) EvaluationFormElementWrapper(org.olat.modules.forms.ui.model.EvaluationFormElementWrapper) EvaluationFormResponse(org.olat.modules.forms.EvaluationFormResponse) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 7 with TextInputWrapper

use of org.olat.modules.forms.ui.model.TextInputWrapper in project OpenOLAT by OpenOLAT.

the class EvaluationFormController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (saveAsDoneButton == source) {
        doConfirmDone(ureq);
    } else if (source instanceof SingleSelection) {
        SingleSelection radioEl = (SingleSelection) source;
        Object uobject = radioEl.getUserObject();
        if (uobject instanceof SliderWrapper) {
            String selectedKey = radioEl.getSelectedKey();
            SliderWrapper sliderWrapper = (SliderWrapper) uobject;
            saveNumericalResponse(new BigDecimal(selectedKey), selectedKey, sliderWrapper.getId());
        }
    } else if (source instanceof SliderElement) {
        SliderElement slider = (SliderElement) source;
        Object uobject = slider.getUserObject();
        if (uobject instanceof SliderWrapper) {
            double value = slider.getValue();
            SliderWrapper sliderWrapper = (SliderWrapper) uobject;
            saveNumericalResponse(BigDecimal.valueOf(value), Double.toString(value), sliderWrapper.getId());
        }
    } else if (source instanceof FormLink) {
        FormLink link = (FormLink) source;
        Object uobject = link.getUserObject();
        if (uobject instanceof TextInputWrapper) {
            TextInputWrapper wrapper = (TextInputWrapper) uobject;
            String value = wrapper.getTextEl().getValue();
            saveNumericalResponse(null, value, wrapper.getId());
        }
    } else if (source instanceof FileElement) {
        FileElement fileElement = (FileElement) source;
        Object uobject = fileElement.getUserObject();
        if (uobject instanceof FileUploadWrapper) {
            FileUploadWrapper wrapper = (FileUploadWrapper) uobject;
            if (event instanceof FileElementEvent) {
                if (FileElementEvent.DELETE.equals(event.getCommand())) {
                    saveFileResponse(null, null, wrapper.getId());
                    fileElement.setInitialFile(null);
                    if (fileElement.getUploadFile() != null) {
                        fileElement.reset();
                    }
                    flc.setDirty(true);
                }
            } else if (fileElement.isUploadSuccess()) {
                File file = fileElement.getUploadFile();
                String filename = fileElement.getUploadFileName();
                saveFileResponse(file, filename, wrapper.getId());
            }
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : TextInputWrapper(org.olat.modules.forms.ui.model.TextInputWrapper) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) FileUploadWrapper(org.olat.modules.forms.ui.model.FileUploadWrapper) FileElementEvent(org.olat.core.gui.components.form.flexible.impl.elements.FileElementEvent) BigDecimal(java.math.BigDecimal) SliderWrapper(org.olat.modules.forms.ui.model.SliderWrapper) SliderElement(org.olat.core.gui.components.form.flexible.elements.SliderElement) FileElement(org.olat.core.gui.components.form.flexible.elements.FileElement) File(java.io.File)

Example 8 with TextInputWrapper

use of org.olat.modules.forms.ui.model.TextInputWrapper in project OpenOLAT by OpenOLAT.

the class EvaluationFormController method doConfirmDone.

private void doConfirmDone(UserRequest ureq) {
    for (EvaluationFormElementWrapper elementWrapper : elementWrapperList) {
        if (elementWrapper.isTextInput()) {
            TextInputWrapper wrapper = elementWrapper.getTextInputWrapper();
            String value = wrapper.getTextEl().getValue();
            saveNumericalResponse(null, value, wrapper.getId());
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<p>").append(translate("confirm.done")).append("</p>");
    List<ValidationMessage> messages = new ArrayList<>();
    validate(ureq, messages);
    if (messages.size() > 0) {
        for (ValidationMessage message : messages) {
            sb.append("<p class='o_warning'>").append(message.getMessage()).append("</p>");
        }
    }
    confirmDoneCtrl = activateYesNoDialog(ureq, null, sb.toString(), confirmDoneCtrl);
}
Also used : ValidationMessage(org.olat.modules.portfolio.ui.editor.ValidationMessage) TextInputWrapper(org.olat.modules.forms.ui.model.TextInputWrapper) EvaluationFormElementWrapper(org.olat.modules.forms.ui.model.EvaluationFormElementWrapper) ArrayList(java.util.ArrayList)

Example 9 with TextInputWrapper

use of org.olat.modules.forms.ui.model.TextInputWrapper in project openolat by klemens.

the class EvaluationFormController method doConfirmDone.

private void doConfirmDone(UserRequest ureq) {
    for (EvaluationFormElementWrapper elementWrapper : elementWrapperList) {
        if (elementWrapper.isTextInput()) {
            TextInputWrapper wrapper = elementWrapper.getTextInputWrapper();
            String value = wrapper.getTextEl().getValue();
            saveNumericalResponse(null, value, wrapper.getId());
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<p>").append(translate("confirm.done")).append("</p>");
    List<ValidationMessage> messages = new ArrayList<>();
    validate(ureq, messages);
    if (messages.size() > 0) {
        for (ValidationMessage message : messages) {
            sb.append("<p class='o_warning'>").append(message.getMessage()).append("</p>");
        }
    }
    confirmDoneCtrl = activateYesNoDialog(ureq, null, sb.toString(), confirmDoneCtrl);
}
Also used : ValidationMessage(org.olat.modules.portfolio.ui.editor.ValidationMessage) TextInputWrapper(org.olat.modules.forms.ui.model.TextInputWrapper) EvaluationFormElementWrapper(org.olat.modules.forms.ui.model.EvaluationFormElementWrapper) ArrayList(java.util.ArrayList)

Example 10 with TextInputWrapper

use of org.olat.modules.forms.ui.model.TextInputWrapper in project openolat by klemens.

the class EvaluationFormController method validate.

@Override
public boolean validate(UserRequest ureq, List<ValidationMessage> messages) {
    boolean allFiled = true;
    for (EvaluationFormElementWrapper elementWrapper : elementWrapperList) {
        if (elementWrapper.isTextInput()) {
            TextInputWrapper wrapper = elementWrapper.getTextInputWrapper();
            if (wrapper != null && !hasResponse(wrapper.getId())) {
                allFiled &= false;
            }
        } else if (elementWrapper.isFileUpload()) {
            FileUploadWrapper wrapper = elementWrapper.getFileUploadWrapper();
            if (wrapper != null && !hasResponse(wrapper.getId())) {
                allFiled &= false;
            }
        } else if (elementWrapper.getSliders() != null && elementWrapper.getSliders().size() > 0) {
            for (SliderWrapper slider : elementWrapper.getSliders()) {
                if (slider != null && !hasResponse(slider.getId())) {
                    allFiled &= false;
                }
            }
        }
    }
    if (!allFiled) {
        String msg = translate("warning.form.not.completed");
        messages.add(new ValidationMessage(Level.warning, msg));
    }
    return validateFormLogic(ureq);
}
Also used : SliderWrapper(org.olat.modules.forms.ui.model.SliderWrapper) ValidationMessage(org.olat.modules.portfolio.ui.editor.ValidationMessage) TextInputWrapper(org.olat.modules.forms.ui.model.TextInputWrapper) EvaluationFormElementWrapper(org.olat.modules.forms.ui.model.EvaluationFormElementWrapper) FileUploadWrapper(org.olat.modules.forms.ui.model.FileUploadWrapper)

Aggregations

TextInputWrapper (org.olat.modules.forms.ui.model.TextInputWrapper)10 EvaluationFormElementWrapper (org.olat.modules.forms.ui.model.EvaluationFormElementWrapper)8 ArrayList (java.util.ArrayList)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 EvaluationFormResponse (org.olat.modules.forms.EvaluationFormResponse)4 FileUploadWrapper (org.olat.modules.forms.ui.model.FileUploadWrapper)4 SliderWrapper (org.olat.modules.forms.ui.model.SliderWrapper)4 ValidationMessage (org.olat.modules.portfolio.ui.editor.ValidationMessage)4 File (java.io.File)2 BigDecimal (java.math.BigDecimal)2 FileElement (org.olat.core.gui.components.form.flexible.elements.FileElement)2 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 SliderElement (org.olat.core.gui.components.form.flexible.elements.SliderElement)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FileElementEvent (org.olat.core.gui.components.form.flexible.impl.elements.FileElementEvent)2 Identity (org.olat.core.id.Identity)2