Search in sources :

Example 21 with NameValuePair

use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project OpenOLAT by OpenOLAT.

the class AssessmentTestComponentRenderer method renderTestItem.

private void renderTestItem(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, TestPlanNodeKey itemRefKey, URLBuilder ubu, Translator translator, RenderingRequest options) {
    final TestSessionController testSessionController = component.getTestSessionController();
    final TestSessionState testSessionState = testSessionController.getTestSessionState();
    String key = itemRefKey.toString();
    /* We finally do the transform on the _item_ (NB!) */
    sb.append("<div class='qtiworks o_assessmentitem o_assessmenttest'>");
    // test part feedback 'during'
    // test feedback 'during'
    TestPlanNode itemRefNode = testSessionState.getTestPlan().getNode(itemRefKey);
    final EffectiveItemSessionControl effectiveItemSessionControl = itemRefNode.getEffectiveItemSessionControl();
    final boolean allowComments = effectiveItemSessionControl.isAllowComment() && component.isPersonalNotes();
    renderer.setCandidateCommentAllowed(allowComments);
    // write section rubric
    renderSectionRubrics(renderer, sb, component, itemRefNode, ubu, translator);
    // test part -> section -> item
    renderTestItemBody(renderer, sb, component, itemRefNode, ubu, translator, options);
    // controls
    sb.append("<div class='o_button_group o_assessmentitem_controls'>");
    // submit button
    final ItemSessionState itemSessionState = component.getItemSessionState(itemRefNode.getKey());
    if (component.isItemSessionOpen(itemSessionState, options.isSolutionMode())) {
        Component submit = component.getQtiItem().getSubmitButton().getComponent();
        submit.getHTMLRendererSingleton().render(renderer.getRenderer(), sb, submit, ubu, translator, new RenderResult(), null);
    }
    // advanceTestItemAllowed /* && testSessionState.getCurrentItemKey() != null && testSessionController.mayAdvanceItemLinear() */
    if (options.isAdvanceTestItemAllowed()) {
        // TODO need to find if there is a next question
        String title = translator.translate("assessment.test.nextQuestion");
        renderControl(sb, component, title, false, "o_sel_next_question", new NameValuePair("cid", Event.finishItem.name()));
    }
    // nextItem
    if (options.isNextItemAllowed() && testSessionController.hasFollowingNonLinearItem()) {
        String title = translator.translate("assessment.test.nextQuestion");
        renderControl(sb, component, title, false, "o_sel_next_question", new NameValuePair("cid", Event.nextItem.name()));
    }
    // testPartNavigationAllowed"
    if (options.isTestPartNavigationAllowed() && component.isRenderNavigation()) {
        String title = translator.translate("assessment.test.questionMenu");
        renderControl(sb, component, title, false, "o_sel_question_menu", new NameValuePair("cid", Event.testPartNavigation.name()));
    }
    // endTestPartAllowed
    if (options.isEndTestPartAllowed()) {
        String title = component.hasMultipleTestParts() ? translator.translate("assessment.test.end.testPart") : translator.translate("assessment.test.end.test");
        renderControl(sb, component, title, false, "o_sel_end_testpart", new NameValuePair("cid", Event.endTestPart.name()));
    }
    // reviewMode
    if (options.isReviewMode()) {
        String title = translator.translate("assessment.test.backToTestFeedback");
        renderControl(sb, component, title, false, "o_sel_back_test_feedback", new NameValuePair("cid", Event.reviewTestPart.name()));
    }
    // <xsl:variable name="provideItemSolutionButton" as="xs:boolean" select="$reviewMode and $showSolution and not($solutionMode)"/>
    if (options.isReviewMode() && effectiveItemSessionControl.isShowSolution() && !options.isSolutionMode()) {
        String title = translator.translate("assessment.solution.show");
        renderControl(sb, component, title, false, "o_sel_show_solution", new NameValuePair("cid", Event.itemSolution.name()), new NameValuePair("item", key));
    }
    if (options.isReviewMode() && options.isSolutionMode()) {
        String title = translator.translate("assessment.solution.hide");
        renderControl(sb, component, title, false, "o_sel_solution_hide", new NameValuePair("cid", Event.reviewItem.name()), new NameValuePair("item", key));
    }
    // end controls
    sb.append("</div>");
    // end assessmentItem
    sb.append("</div>");
}
Also used : TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) RenderResult(org.olat.core.gui.render.RenderResult) TestSessionController(uk.ac.ed.ph.jqtiplus.running.TestSessionController) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) Component(org.olat.core.gui.components.Component) EffectiveItemSessionControl(uk.ac.ed.ph.jqtiplus.state.EffectiveItemSessionControl)

Example 22 with NameValuePair

use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project OpenOLAT by OpenOLAT.

the class AssessmentTestComponentRenderer method renderSectionRubrics.

private void renderSectionRubrics(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, TestPlanNode itemRefNode, URLBuilder ubu, Translator translator) {
    boolean writeRubrics = false;
    boolean writeTitles = false;
    List<AssessmentSection> sectionParentLine = new ArrayList<>();
    for (TestPlanNode parentNode = itemRefNode.getParent(); parentNode.getParent() != null; parentNode = parentNode.getParent()) {
        AssessmentSection selectedSection = component.getAssessmentSection(parentNode.getIdentifier());
        if (selectedSection != null && selectedSection.getVisible()) {
            sectionParentLine.add(selectedSection);
            if (selectedSection.getRubricBlocks().size() > 0) {
                for (RubricBlock rubric : selectedSection.getRubricBlocks()) {
                    if (rubric.getBlocks().size() > 0) {
                        writeRubrics = true;
                    }
                }
            }
            if (StringHelper.containsNonWhitespace(selectedSection.getTitle())) {
                writeTitles = true;
            }
        }
    }
    if (writeRubrics) {
        boolean show = true;
        for (int i = sectionParentLine.size(); i-- > 0; ) {
            AssessmentSection selectedSection = sectionParentLine.get(i);
            if (component.getCandidateSessionContext().isRubricHidden(selectedSection.getIdentifier())) {
                show = false;
            }
        }
        String key = sectionParentLine.get(0).getIdentifier().toString();
        Form form = component.getQtiItem().getRootForm();
        String dispatchId = component.getQtiItem().getFormDispatchId();
        sb.append("<a href='javascript:;' onclick=\"").append(FormJSHelper.getXHRNFFnCallFor(form, dispatchId, 1, new NameValuePair("cid", Event.rubric.name()), new NameValuePair("section", key))).append("; return false;\" class='o_toogle_rubrics translated'><i class='o_icon o_icon-fw ");
        if (show) {
            sb.append("o_icon_close_togglebox'> </i> <span>").append(translator.translate("hide.rubric"));
        } else {
            sb.append("o_icon_open_togglebox'> </i> <span>").append(translator.translate("show.rubric"));
        }
        sb.append("</span></a>");
        sb.append("<div class='o_info o_assessmentsection_rubrics clearfix");
        if (show) {
            sb.append(" o_show");
        } else {
            sb.append(" o_hide");
        }
        sb.append("'>");
        // write the titles first
        if (writeTitles) {
            sb.append("<h4>");
            for (int i = 0; i < sectionParentLine.size(); i++) {
                if (i == 1) {
                    sb.append("<small>");
                } else if (i > 1) {
                    sb.append(" / ");
                }
                sb.append(sectionParentLine.get(i).getTitle());
            }
            if (sectionParentLine.size() > 1) {
                sb.append("</small>");
            }
            sb.append("</h4>");
        }
        for (int i = sectionParentLine.size(); i-- > 0; ) {
            AssessmentSection selectedSection = sectionParentLine.get(i);
            for (RubricBlock rubricBlock : selectedSection.getRubricBlocks()) {
                // @view (candidate)
                sb.append("<div class='rubric'>");
                rubricBlock.getBlocks().forEach(block -> renderBlock(renderer, sb, component, null, null, block, ubu, translator));
                sb.append("</div>");
            }
        }
        sb.append("<a href='javascript:;' onclick=\"").append(FormJSHelper.getXHRNFFnCallFor(form, dispatchId, 1, new NameValuePair("cid", Event.rubric.name()), new NameValuePair("section", key))).append("; return false;\" class='o_toogle_rubrics o_hide'><span>").append(translator.translate("hide.rubric.short")).append("</span></a>");
        // script to show/hide the rubrics with the translated linked
        sb.append("<script type=\"text/javascript\">\n").append("/* <![CDATA[ */ \n").append("jQuery(function() {\n").append(" jQuery('.o_toogle_rubrics').on('click', function() {\n").append("   jQuery('.o_assessmentsection_rubrics').each(function(index, el) {\n").append("     var current = jQuery(el).attr('class');\n").append("     if(current.indexOf('o_hide') >= 0) {\n").append("       jQuery(el).removeClass('o_hide').addClass('o_show');\n").append("       jQuery('a.o_toogle_rubrics.translated i').removeClass('o_icon_open_togglebox').addClass('o_icon_close_togglebox');\n").append("       jQuery('a.o_toogle_rubrics.translated span').html('").append(translator.translate("hide.rubric")).append("');").append("     } else {\n").append("   	  jQuery(el).removeClass('o_show').addClass('o_hide');\n").append("       jQuery('a.o_toogle_rubrics.translated i').removeClass('o_icon_close_togglebox').addClass('o_icon_open_togglebox');\n").append("       jQuery('a.o_toogle_rubrics.translated span').html('").append(translator.translate("show.rubric")).append("');").append("     }\n").append("   });").append(" });").append("});\n /* ]]> */").append("</script>").append("</div>");
    }
}
Also used : TestPlanNode(uk.ac.ed.ph.jqtiplus.state.TestPlanNode) NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) ArrayList(java.util.ArrayList) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) RubricBlock(uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock)

Example 23 with NameValuePair

use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.

the class URLBuilder method openXHRNoResponseEvent.

public StringOutput openXHRNoResponseEvent(StringOutput sb, String urlEnding, NameValuePair... commands) {
    sb.append("o_XHRNFEvent('").append(uriPrefix);
    encodeParams(sb, AJAXFlags.MODE_TOBGIFRAME);
    sb.append("/");
    if (StringHelper.containsNonWhitespace(urlEnding)) {
        sb.append(urlEnding);
    }
    sb.append("'");
    commandParameters(sb, commands);
    // no response marker
    commandParameters(sb, new NameValuePair(Window.NO_RESPONSE_PARAMETER_MARKER, Window.NO_RESPONSE_VALUE_MARKER));
    return sb;
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair)

Example 24 with NameValuePair

use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.

the class MultipleSelectionRenderer method getAjaxOnlyJs.

private StringBuilder getAjaxOnlyJs(MultipleSelectionElement stF, MultipleSelectionComponent stC, String key) {
    StringBuilder sb = new StringBuilder();
    if (stF.isAjaxOnly()) {
        sb.append("if ($check) {");
        sb.append(FormJSHelper.getXHRFnCallFor(stF.getRootForm(), stC.getFormDispatchId(), 1, false, false, false, new NameValuePair("achkbox", key), new NameValuePair("checked", "true"))).append(";");
        sb.append("} else {");
        sb.append(FormJSHelper.getXHRFnCallFor(stF.getRootForm(), stC.getFormDispatchId(), 1, false, false, false, new NameValuePair("achkbox", key), new NameValuePair("checked", "false"))).append(";");
        sb.append("}");
    }
    return sb;
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair)

Example 25 with NameValuePair

use of org.olat.core.gui.components.form.flexible.impl.NameValuePair in project openolat by klemens.

the class FileElementRenderer method render.

/* (non-Javadoc)
	 * @see org.olat.core.gui.components.ComponentRenderer#render(org.olat.core.gui.render.Renderer, org.olat.core.gui.render.StringOutput, org.olat.core.gui.components.Component, org.olat.core.gui.render.URLBuilder, org.olat.core.gui.translator.Translator, org.olat.core.gui.render.RenderResult, java.lang.String[])
	 */
@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    // Use translator with flexi form elements fallback
    Translator trans = Util.createPackageTranslator(FileElementRenderer.class, translator.getLocale(), translator);
    // 
    FileElementComponent fileComp = (FileElementComponent) source;
    FileElementImpl fileElem = fileComp.getFileElementImpl();
    String id = fileComp.getFormDispatchId();
    // Calculate current file name: either from already uploaded file or
    // from initial file or empty
    String fileName = fileElem.getUploadFileName();
    if (fileName == null) {
        // try fallback: default file
        File initialFile = fileElem.getInitialFile();
        if (initialFile != null) {
            fileName = initialFile.getName();
        } else {
            fileName = "";
        }
    }
    // Read-write view
    if (fileComp.isEnabled()) {
        ImageFormItem previewCmp = fileElem.getPreviewFormItem();
        if (previewCmp != null && previewCmp.isEnabled() && previewCmp.isVisible()) {
            sb.append("<div class='o_filepreview'>");
            renderer.render(previewCmp.getComponent(), sb, args);
            sb.append("</div>");
        }
        boolean showDeleteButton = fileElem.isDeleteEnabled() && (fileElem.getInitialFile() != null || fileElem.getUploadFile() != null);
        sb.append("<div class='o_fileinput'>");
        // See http://www.quirksmode.org/dom/inputfile.html
        if (fileElem.isButtonsEnabled()) {
            sb.append("<input type='file' name=\"");
            // name for form labeling
            sb.append(id);
            sb.append("\" id=\"");
            // id to make dirty button work
            sb.append(id);
            sb.append("\" class='form-control o_realchooser ").append(" o_chooser_with_delete", showDeleteButton).append("' ");
            // Add on* event handlers
            StringBuilder eventHandlers = FormJSHelper.getRawJSFor(fileElem.getRootForm(), id, fileElem.getAction());
            int onChangePos = eventHandlers.indexOf("onchange=");
            if (onChangePos != -1) {
                // add file upload change handler
                sb.append(eventHandlers.substring(0, onChangePos + 10)).append("b_handleFileUploadFormChange(this, this.form.fake_").append(id).append(", this.form.upload);").append(eventHandlers.substring(onChangePos + 10, eventHandlers.length()));
            } else {
                sb.append(eventHandlers).append(" onchange=\"b_handleFileUploadFormChange(this, this.form.fake_").append(id).append(", this.form.upload)\"");
            }
            // Add pseudo focus marker on fake file chooser button
            sb.append(" onfocus=\"this.form.fake_").append(id).append(".nextSibling.style.border = '1px dotted black';\"").append(" onblur=\"this.form.fake_").append(id).append(".nextSibling.style.border = '0';\"");
            // Add select text (hover)
            sb.append(" title=\"").append(StringEscapeUtils.escapeHtml(trans.translate("file.element.select"))).append("\" />");
        }
        // Add the visible but fake input field and a styled faked file chooser button
        sb.append("<div class='o_fakechooser input-group'>");
        sb.append("<input class='form-control' name='fake_").append(id).append("' value=\"").append(StringEscapeUtils.escapeHtml(fileName)).append("\" placeholder=\"").append(StringEscapeUtils.escapeHtml(trans.translate("file.element.select"))).append("\" />");
        sb.append("<span class='input-group-addon'><a href='javascript:;'><i class='o_icon o_icon_upload'> </i></a></span>");
        if (showDeleteButton) {
            sb.append("<a class='input-group-addon' href=\"javascript:").append(FormJSHelper.getXHRFnCallFor(fileElem.getRootForm(), fileComp.getFormDispatchId(), 1, false, false, new NameValuePair("delete", "delete"))).append(";\" onclick=\"\" ").append(" title=\"").append(StringEscapeUtils.escapeHtml(trans.translate("file.element.delete"))).append("\" ><i class='o_icon o_icon_delete'> </i></a>");
        }
        sb.append("</div></div>");
        // Add example text and  max upload size
        if (fileElem.getExampleText() != null) {
            sb.append("<div class='help-block'>").append(fileElem.getExampleText());
            if (fileElem.getMaxUploadSizeKB() != FileElement.UPLOAD_UNLIMITED) {
                String maxUpload = Formatter.formatBytes(fileElem.getMaxUploadSizeKB() * 1000);
                sb.append(" (").append(trans.translate("file.element.select.maxsize", new String[] { maxUpload })).append(")");
            }
            sb.append("</div>");
        } else if (fileElem.getMaxUploadSizeKB() != FileElement.UPLOAD_UNLIMITED) {
            String maxUpload = Formatter.formatBytes(fileElem.getMaxUploadSizeKB() * 1000);
            sb.append("<div class='help-block o_maxsize'>(").append(trans.translate("file.element.select.maxsize", new String[] { maxUpload })).append(")</div>");
        }
        // Add set dirty form on change
        FormJSHelper.appendFlexiFormDirty(sb, fileElem.getRootForm(), fileComp.getFormDispatchId());
    } else {
        // Read only view
        sb.append("<span id=\"").append(id).append("\" ").append(FormJSHelper.getRawJSFor(fileElem.getRootForm(), id, fileElem.getAction())).append(" >").append("<input type='text' disabled=\"disabled\" class=\"form-control o_disabled\" size=\"").append("\" value=\"").append(StringEscapeUtils.escapeHtml(fileName)).append("\" ").append("\" />").append("</span>");
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Translator(org.olat.core.gui.translator.Translator) ImageFormItem(org.olat.core.gui.components.image.ImageFormItem) File(java.io.File)

Aggregations

NameValuePair (org.olat.core.gui.components.form.flexible.impl.NameValuePair)80 Form (org.olat.core.gui.components.form.flexible.impl.Form)42 AssessmentRenderFunctions.contentAsString (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)12 Component (org.olat.core.gui.components.Component)8 TestSessionController (uk.ac.ed.ph.jqtiplus.running.TestSessionController)6 ItemSessionState (uk.ac.ed.ph.jqtiplus.state.ItemSessionState)6 FlexiTableFilter (org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter)4 FlexiTableSort (org.olat.core.gui.components.form.flexible.elements.FlexiTableSort)4 StringOutput (org.olat.core.gui.render.StringOutput)4 Translator (org.olat.core.gui.translator.Translator)4 VFSItem (org.olat.core.util.vfs.VFSItem)4 TestPart (uk.ac.ed.ph.jqtiplus.node.test.TestPart)4 EffectiveItemSessionControl (uk.ac.ed.ph.jqtiplus.state.EffectiveItemSessionControl)3 TestPlanNode (uk.ac.ed.ph.jqtiplus.state.TestPlanNode)3 TestSessionState (uk.ac.ed.ph.jqtiplus.state.TestSessionState)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Matcher (java.util.regex.Matcher)2 FolderLicenseHandler (org.olat.core.commons.modules.bc.FolderLicenseHandler)2