Search in sources :

Example 1 with RichTextElement

use of org.olat.core.gui.components.form.flexible.elements.RichTextElement in project OpenOLAT by OpenOLAT.

the class KPrimEditorController method wrapAnswer.

private void wrapAnswer(UserRequest ureq, SimpleAssociableChoice choice) {
    List<FlowStatic> choiceFlow = choice.getFlowStatics();
    String choiceContent = itemBuilder.getHtmlHelper().flowStaticString(choiceFlow);
    String choiceId = "answer" + count++;
    RichTextElement choiceEl = uifactory.addRichTextElementForQTI21(choiceId, "form.imd.answer", choiceContent, 8, -1, itemContainer, answersCont, ureq.getUserSession(), getWindowControl());
    choiceEl.getEditorConfiguration().setSimplestTextModeAllowed(TextMode.oneLine);
    choiceEl.setUserObject(choice);
    choiceEl.setEnabled(!readOnly);
    choiceEl.setVisible(!readOnly);
    answersCont.add("choiceId", choiceEl);
    String choiceRoId = "answerro" + count++;
    FlowFormItem choiceReadOnlyEl = new FlowFormItem(choiceRoId, itemFile);
    choiceReadOnlyEl.setFlowStatics(choiceFlow);
    choiceReadOnlyEl.setMapperUri(mapperUri);
    answersCont.add(choiceRoId, choiceReadOnlyEl);
    FormLink upLink = uifactory.addFormLink("up-".concat(choiceId), "up", "", null, answersCont, Link.NONTRANSLATED);
    upLink.setIconLeftCSS("o_icon o_icon-lg o_icon_move_up");
    upLink.setEnabled(!restrictedEdit && !readOnly);
    answersCont.add(upLink);
    answersCont.add("up-".concat(choiceId), upLink);
    FormLink downLink = uifactory.addFormLink("down-".concat(choiceId), "down", "", null, answersCont, Link.NONTRANSLATED);
    downLink.setIconLeftCSS("o_icon o_icon-lg o_icon_move_down");
    downLink.setEnabled(!restrictedEdit && !readOnly);
    answersCont.add(downLink);
    answersCont.add("down-".concat(choiceId), downLink);
    choiceWrappers.add(new KprimWrapper(choice, choiceEl, choiceReadOnlyEl, upLink, downLink));
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) FlowStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.FlowStatic) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 2 with RichTextElement

use of org.olat.core.gui.components.form.flexible.elements.RichTextElement in project OpenOLAT by OpenOLAT.

the class SingleChoiceEditorController method wrapAnswer.

private void wrapAnswer(UserRequest ureq, SimpleChoice choice) {
    List<FlowStatic> choiceFlow = choice.getFlowStatics();
    String choiceContent = itemBuilder.getHtmlHelper().flowStaticString(choiceFlow);
    String choiceId = "answer" + count++;
    RichTextElement choiceEl = uifactory.addRichTextElementForQTI21(choiceId, "form.imd.answer", choiceContent, 8, -1, itemContainer, answersCont, ureq.getUserSession(), getWindowControl());
    choiceEl.setEnabled(!readOnly);
    choiceEl.setVisible(!readOnly);
    choiceEl.getEditorConfiguration().setSimplestTextModeAllowed(TextMode.oneLine);
    choiceEl.setUserObject(choice);
    answersCont.add("choiceId", choiceEl);
    String choiceRoId = "answerro" + count++;
    FlowFormItem choiceReadOnlyEl = new FlowFormItem(choiceRoId, itemFile);
    choiceReadOnlyEl.setFlowStatics(choiceFlow);
    choiceReadOnlyEl.setMapperUri(mapperUri);
    answersCont.add(choiceRoId, choiceReadOnlyEl);
    FormLink removeLink = uifactory.addFormLink("rm-".concat(choiceId), "rm", "", null, answersCont, Link.NONTRANSLATED);
    removeLink.setIconLeftCSS("o_icon o_icon-lg o_icon_delete");
    removeLink.setEnabled(!restrictedEdit && !readOnly);
    answersCont.add(removeLink);
    answersCont.add("rm-".concat(choiceId), removeLink);
    FormLink addLink = uifactory.addFormLink("add-".concat(choiceId), "add", "", null, answersCont, Link.NONTRANSLATED);
    addLink.setIconLeftCSS("o_icon o_icon-lg o_icon_add");
    addLink.setEnabled(!restrictedEdit && !readOnly);
    answersCont.add(addLink);
    answersCont.add("add-".concat(choiceId), addLink);
    FormLink upLink = uifactory.addFormLink("up-".concat(choiceId), "up", "", null, answersCont, Link.NONTRANSLATED);
    upLink.setIconLeftCSS("o_icon o_icon-lg o_icon_move_up");
    upLink.setEnabled(!restrictedEdit && !readOnly);
    answersCont.add(upLink);
    answersCont.add("up-".concat(choiceId), upLink);
    FormLink downLink = uifactory.addFormLink("down-".concat(choiceId), "down", "", null, answersCont, Link.NONTRANSLATED);
    downLink.setIconLeftCSS("o_icon o_icon-lg o_icon_move_down");
    downLink.setEnabled(!restrictedEdit && !readOnly);
    answersCont.add(downLink);
    answersCont.add("down-".concat(choiceId), downLink);
    choiceWrappers.add(new SimpleChoiceWrapper(choice, choiceEl, choiceReadOnlyEl, removeLink, addLink, upLink, downLink));
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) FlowStatic(uk.ac.ed.ph.jqtiplus.node.content.basic.FlowStatic) FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 3 with RichTextElement

use of org.olat.core.gui.components.form.flexible.elements.RichTextElement in project OpenOLAT by OpenOLAT.

the class AssessmentSectionOptionsEditorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    section.setTitle(titleEl.getValue());
    // rubrics
    List<RubricBlock> rubricBlocks = new ArrayList<>();
    for (RichTextElement rubricEl : rubricEls) {
        String rubric = rubricEl.getRawValue();
        if (htmlBuilder.containsSomething(rubric)) {
            RubricBlock rubricBlock = (RubricBlock) rubricEl.getUserObject();
            if (rubricBlock == null) {
                rubricBlock = new RubricBlock(section);
                rubricBlock.setViews(Collections.singletonList(View.CANDIDATE));
            }
            rubricBlock.getBlocks().clear();
            htmlBuilder.appendHtml(rubricBlock, rubric);
            rubricBlocks.add(rubricBlock);
        }
    }
    section.getRubricBlocks().clear();
    section.getRubricBlocks().addAll(rubricBlocks);
    // shuffle
    boolean shuffle = (shuffleEl.isOneSelected() && shuffleEl.isSelected(0));
    if (shuffle) {
        if (section.getOrdering() == null) {
            section.setOrdering(new Ordering(section));
        }
        section.getOrdering().setShuffle(shuffle);
    } else {
        section.setOrdering(null);
    }
    // number of selected questions
    Integer randomSelection = null;
    if (StringHelper.containsNonWhitespace(randomSelectedEl.getSelectedKey())) {
        randomSelection = new Integer(randomSelectedEl.getSelectedKey());
    }
    if (randomSelection == null || randomSelection.intValue() < 1) {
        section.setSelection(null);
    } else {
        if (section.getSelection() == null) {
            section.setSelection(new Selection(section));
        }
        section.getSelection().setSelect(randomSelection);
    }
    fireEvent(ureq, new AssessmentSectionEvent(AssessmentSectionEvent.ASSESSMENT_SECTION_CHANGED, section));
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) Selection(uk.ac.ed.ph.jqtiplus.node.test.Selection) ArrayList(java.util.ArrayList) Ordering(uk.ac.ed.ph.jqtiplus.node.test.Ordering) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock) AssessmentSectionEvent(org.olat.ims.qti21.ui.editor.events.AssessmentSectionEvent)

Example 4 with RichTextElement

use of org.olat.core.gui.components.form.flexible.elements.RichTextElement in project OpenOLAT by OpenOLAT.

the class AssessmentSectionOptionsEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_assessment_section_options");
    setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_section");
    if (!editable) {
        setFormWarning("warning.alien.assessment.test");
    }
    String title = section.getTitle();
    titleEl = uifactory.addTextElement("title", "form.metadata.title", 255, title, formLayout);
    titleEl.setEnabled(editable);
    titleEl.setMandatory(true);
    String relativePath = rootDirectory.toPath().relativize(testFile.toPath().getParent()).toString();
    VFSContainer itemContainer = (VFSContainer) rootContainer.resolve(relativePath);
    if (section.getRubricBlocks().isEmpty()) {
        RichTextElement rubricEl = uifactory.addRichTextElementForQTI21("rubric" + counter++, "form.imd.rubric", "", 12, -1, itemContainer, formLayout, ureq.getUserSession(), getWindowControl());
        rubricEl.getEditorConfiguration().setFileBrowserUploadRelPath("media");
        rubricEl.setEnabled(editable);
        rubricEls.add(rubricEl);
    } else {
        for (RubricBlock rubricBlock : section.getRubricBlocks()) {
            String rubric = htmlBuilder.blocksString(rubricBlock.getBlocks());
            RichTextElement rubricEl = uifactory.addRichTextElementForQTI21("rubric" + counter++, "form.imd.rubric", rubric, 12, -1, itemContainer, formLayout, ureq.getUserSession(), getWindowControl());
            rubricEl.getEditorConfiguration().setFileBrowserUploadRelPath("media");
            rubricEl.setEnabled(editable);
            rubricEl.setUserObject(rubricBlock);
            rubricEls.add(rubricEl);
        }
    }
    // shuffle
    String[] yesnoValues = new String[] { translate("yes"), translate("no") };
    shuffleEl = uifactory.addRadiosHorizontal("shuffle", "form.section.shuffle", formLayout, yesnoKeys, yesnoValues);
    if (section.getOrdering() != null && section.getOrdering().getShuffle()) {
        shuffleEl.select("y", true);
    } else {
        shuffleEl.select("n", true);
    }
    shuffleEl.setEnabled(!restrictedEdit && editable);
    int numOfItems = getNumOfQuestions(section);
    String[] theKeys = new String[numOfItems + 1];
    String[] theValues = new String[numOfItems + 1];
    theKeys[0] = "0";
    theValues[0] = translate("form.section.selection_all");
    for (int i = 0; i < numOfItems; i++) {
        theKeys[i + 1] = Integer.toString(i + 1);
        theValues[i + 1] = Integer.toString(i + 1);
    }
    randomSelectedEl = uifactory.addDropdownSingleselect("form.section.selection_pre", formLayout, theKeys, theValues, null);
    randomSelectedEl.setHelpText(translate("form.section.selection_pre.hover"));
    randomSelectedEl.setEnabled(!restrictedEdit && editable);
    int currentNum = section.getSelection() != null ? section.getSelection().getSelect() : 0;
    if (currentNum <= numOfItems) {
        randomSelectedEl.select(theKeys[currentNum], true);
    } else if (currentNum > numOfItems) {
        randomSelectedEl.select(theKeys[numOfItems], true);
    } else {
        randomSelectedEl.select(theKeys[0], true);
    }
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("butons", getTranslator());
    formLayout.add(buttonsCont);
    FormSubmit submit = uifactory.addFormSubmitButton("save", "save", buttonsCont);
    submit.setEnabled(editable);
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) FormSubmit(org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit) VFSContainer(org.olat.core.util.vfs.VFSContainer) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock)

Example 5 with RichTextElement

use of org.olat.core.gui.components.form.flexible.elements.RichTextElement in project OpenOLAT by OpenOLAT.

the class FeedbackFormController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormTitle("fieldset.legend.feedback");
    setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_feedback");
    FormLayoutContainer switchLayout = FormLayoutContainer.createDefaultFormLayout("switchLayout", getTranslator());
    overallFeedbackLayout = FormLayoutContainer.createDefaultFormLayout("overallFeedbackLayout", getTranslator());
    responseLevelHintsLayout = FormLayoutContainer.createCustomFormLayout("responseLevelHintsLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/response_level_feedback.html");
    // add the layouts to the custom layout
    formLayout.add(switchLayout);
    formLayout.add(overallFeedbackLayout);
    formLayout.add(responseLevelHintsLayout);
    String[] yesNoKeys, yesNoValues;
    yesNoKeys = new String[] { YES, NO };
    yesNoValues = new String[] { translate(YES), translate(NO) };
    feedbackSwitch = uifactory.addRadiosHorizontal("feedbackswitch", switchLayout, yesNoKeys, yesNoValues);
    feedbackSwitch.addActionListener(FormEvent.ONCLICK);
    if (control.isFeedback()) {
        feedbackSwitch.select(yesNoKeys[0], true);
    } else {
        // defaults to 'not showing feedback'
        feedbackSwitch.select(yesNoKeys[1], true);
    }
    responseLevelHintsLayout.contextPut("mediaBaseUrl", mediaBaseUrl);
    masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
    masteryMat = masteryMat == null ? new Material() : masteryMat;
    failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
    failureMat = failureMat == null ? new Material() : failureMat;
    VFSContainer baseContainer = qtiPackage.getBaseDir();
    // Mastery Layout
    FormLayoutContainer masteryEditLayout = FormLayoutContainer.createCustomFormLayout("masteryEditLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/rich_text_and_edit_link.html");
    masteryEditLayout.setLabel("item_feedback_mastery", null);
    overallFeedbackLayout.add(masteryEditLayout);
    RichTextElement masteryFeedback = uifactory.addRichTextElementForStringData("richTextElement", "item_feedback_mastery", masteryMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, masteryEditLayout, ureq.getUserSession(), getWindowControl());
    masteryFeedback.getEditorConfiguration().setFigCaption(false);
    FormLink editLink = uifactory.addFormLink("editLink", masteryEditLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
    editLink.getComponent().setCustomDisplayText(" ");
    editLink.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg qti_edit_link");
    registerFeedbackElement(masteryMat, masteryFeedback, editLink);
    // One Failure Layout
    FormLayoutContainer failureEditLayout = FormLayoutContainer.createCustomFormLayout("failureEditLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/rich_text_and_edit_link.html");
    failureEditLayout.setLabel("item_feedback_fail", null);
    overallFeedbackLayout.add(failureEditLayout);
    RichTextElement failureFeedback = uifactory.addRichTextElementForStringData("richTextElement", "item_feedback_fail", failureMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, failureEditLayout, ureq.getUserSession(), getWindowControl());
    failureFeedback.getEditorConfiguration().setFigCaption(false);
    failureFeedback.setLabel("item_feedback_fail", null);
    FormLink failureLink = uifactory.addFormLink("editLink", failureEditLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
    failureLink.getComponent().setCustomDisplayText("");
    failureLink.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg");
    registerFeedbackElement(failureMat, failureFeedback, failureLink);
    // Feedback for each response when single or multiple choice question
    List<Material> responses = new ArrayList<Material>();
    boolean hasResponseLevelHints = false;
    if (item.getQuestion().getType() <= Question.TYPE_MC) {
        int i = 1;
        for (Object obj : item.getQuestion().getResponses()) {
            ChoiceResponse response = (ChoiceResponse) obj;
            // response-level feedback
            Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
            responseFeedbackMat = responseFeedbackMat == null ? new Material() : responseFeedbackMat;
            identities.put(responseFeedbackMat, response.getIdent());
            RichTextElement responseHintText = uifactory.addRichTextElementForStringData("feedback_" + i, null, responseFeedbackMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, responseLevelHintsLayout, ureq.getUserSession(), getWindowControl());
            responseHintText.getEditorConfiguration().setFigCaption(false);
            FormLink link = uifactory.addFormLink("link_" + i, responseLevelHintsLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
            link.getComponent().setCustomDisplayText(" ");
            link.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg");
            registerFeedbackElement(responseFeedbackMat, responseHintText, link);
            // get response for displaying
            Material responseMat = response.getContent();
            responses.add(responseMat);
            i++;
        }
        // If 'i' is strictly greater than the initial value, there's at least one
        // response.
        hasResponseLevelHints = i > 1;
    }
    flc.contextPut("hasResponseLevelHints", hasResponseLevelHints);
    responseLevelHintsLayout.contextPut("responses", responses);
    showHideFeedbackFields();
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Material(org.olat.ims.qti.editor.beecom.objects.Material) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) ChoiceResponse(org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)

Aggregations

RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)30 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)14 RichTextElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl)12 FlowFormItem (org.olat.ims.qti21.ui.components.FlowFormItem)10 FlowStatic (uk.ac.ed.ph.jqtiplus.node.content.basic.FlowStatic)10 Theme (org.olat.core.gui.themes.Theme)8 ArrayList (java.util.ArrayList)4 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 RubricBlock (uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock)4 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 FormSubmit (org.olat.core.gui.components.form.flexible.impl.elements.FormSubmit)2 WindowBackOffice (org.olat.core.gui.control.WindowBackOffice)2 ChoiceResponse (org.olat.ims.qti.editor.beecom.objects.ChoiceResponse)2 Material (org.olat.ims.qti.editor.beecom.objects.Material)2 AssessmentSectionEvent (org.olat.ims.qti21.ui.editor.events.AssessmentSectionEvent)2 Ordering (uk.ac.ed.ph.jqtiplus.node.test.Ordering)2 Selection (uk.ac.ed.ph.jqtiplus.node.test.Selection)2