Search in sources :

Example 46 with Form

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

the class AssessmentObjectComponentRenderer method renderExtendedTextBox.

/*
	  <xsl:template match="qti:extendedTextInteraction" mode="multibox">
	    <xsl:param name="responseInput" as="element(qw:responseInput)?"/>
	    <xsl:param name="checkJavaScript" as="xs:string?"/>
	    <xsl:param name="stringsCount" as="xs:integer"/>
	    <xsl:param name="allowCreate" select="false()" as="xs:boolean"/>
	    <xsl:variable name="interaction" select="." as="element(qti:extendedTextInteraction)"/>
	    <xsl:for-each select="1 to $stringsCount">
	      <xsl:variable name="i" select="." as="xs:integer"/>
	      <xsl:apply-templates select="$interaction" mode="singlebox">
	        <xsl:with-param name="responseInputString" select="$responseInput/qw:string[position()=$i]"/>
	        <xsl:with-param name="checkJavaScript" select="$checkJavaScript"/>
	        <xsl:with-param name="allowCreate" select="$allowCreate and $i=$stringsCount"/>
	      </xsl:apply-templates>
	      <br />
	    </xsl:for-each>
	  </xsl:template>
	  
	  <xsl:template match="qti:extendedTextInteraction" mode="singlebox">
	    <xsl:param name="responseInputString" as="xs:string?"/>
	    <xsl:param name="checkJavaScript" as="xs:string?"/>
	    <xsl:param name="allowCreate" select="false()" as="xs:boolean"/>
	    <xsl:variable name="is-bad-response" select="qw:is-bad-response(@responseIdentifier)" as="xs:boolean"/>
	    <xsl:variable name="is-invalid-response" select="qw:is-invalid-response(@responseIdentifier)" as="xs:boolean"/>
	    <textarea cols="72" rows="6" name="qtiworks_response_{@responseIdentifier}">
	      <xsl:if test="$isItemSessionEnded">
	        <xsl:attribute name="disabled">disabled</xsl:attribute>
	      </xsl:if>
	      <xsl:if test="$is-bad-response or $is-invalid-response">
	        <xsl:attribute name="class" select="'badResponse'"/>
	      </xsl:if>
	      <xsl:if test="@expectedLines">
	        <xsl:attribute name="rows" select="@expectedLines"/>
	      </xsl:if>
	      <xsl:if test="@expectedLines and @expectedLength">
	        <xsl:attribute name="cols" select="ceiling(@expectedLength div @expectedLines)"/>
	      </xsl:if>
	      <xsl:if test="$checkJavaScript">
	        <xsl:attribute name="onchange" select="$checkJavaScript"/>
	      </xsl:if>
	      <xsl:if test="$allowCreate">
	        <xsl:attribute name="onkeyup" select="'QtiWorksRendering.addNewTextBox(this)'"/>
	      </xsl:if>
	      <xsl:value-of select="$responseInputString"/>
	    </textarea>
	  </xsl:template>
	*/
protected void renderExtendedTextBox(AssessmentRenderer renderer, StringOutput sb, AssessmentObjectComponent component, AssessmentItem assessmentItem, ItemSessionState itemSessionState, ExtendedTextInteraction interaction, String responseInputString) {
    String responseUniqueId = component.getResponseUniqueIdentifier(itemSessionState, interaction);
    boolean ended = component.isItemSessionEnded(itemSessionState, renderer.isSolutionMode());
    int expectedLines = interaction.getExpectedLines() == null ? 6 : interaction.getExpectedLines().intValue();
    if (ended) {
        sb.append("<div id='oo_").append(responseUniqueId).append("' style='min-height:").append(expectedLines * 1.5).append("em;' class='form-control textarea_disabled o_disabled o_form_element_disabled");
    } else {
        sb.append("<textarea id='oo_").append(responseUniqueId).append("' name='qtiworks_response_").append(responseUniqueId).append("'");
        if (StringHelper.containsNonWhitespace(interaction.getPlaceholderText())) {
            sb.append(" placeholder=\"").append(StringHelper.escapeHtml(interaction.getPlaceholderText())).append("\"");
        }
        sb.append(" rows='").append(expectedLines).append("'");
        if (interaction.getExpectedLength() == null) {
            sb.append(" cols='72'");
        } else {
            int cols = interaction.getExpectedLength().intValue() / expectedLines;
            sb.append(" cols='").append(cols).append("'");
        }
        ResponseDeclaration responseDeclaration = getResponseDeclaration(assessmentItem, interaction.getResponseIdentifier());
        String checkJavascript = checkJavaScript(responseDeclaration, interaction.getPatternMask());
        if (StringHelper.containsNonWhitespace(checkJavascript)) {
            sb.append(" onchange=\"").append(checkJavascript).append("\"");
        }
        sb.append(" class='form-control");
    }
    if (isBadResponse(itemSessionState, interaction.getResponseIdentifier()) || isInvalidResponse(itemSessionState, interaction.getResponseIdentifier())) {
        sb.append(" badResponse");
    }
    sb.append("'>");
    if (renderer.isSolutionMode()) {
        String placeholder = interaction.getPlaceholderText();
        if (StringHelper.containsNonWhitespace(placeholder)) {
            sb.append(placeholder);
        }
    } else if (StringHelper.containsNonWhitespace(responseInputString)) {
        sb.append(responseInputString);
    }
    if (ended) {
        sb.append("</div>");
    } else {
        sb.append("</textarea>");
        FormJSHelper.appendFlexiFormDirty(sb, component.getQtiItem().getRootForm(), "oo_" + responseUniqueId);
        sb.append(FormJSHelper.getJSStartWithVarDeclaration("oo_" + responseUniqueId)).append("oo_").append(responseUniqueId).append(".on('keypress', function(event, target){if (13 == event.keyCode) {event.stopPropagation()} })").append(FormJSHelper.getJSEnd());
        Form form = component.getQtiItem().getRootForm();
        sb.append(FormJSHelper.getJSStart()).append("jQuery(function() {\n").append(" jQuery('#").append("oo_").append(responseUniqueId).append("').qtiAutosave({\n").append("  responseUniqueId:'").append(responseUniqueId).append("',\n").append("  formName:'").append(form.getFormName()).append("',\n").append("  dispIdField:'").append(form.getDispatchFieldId()).append("',\n").append("  dispId:'").append(component.getQtiItem().getFormDispatchId()).append("',\n").append("  eventIdField:'").append(form.getEventFieldId()).append("'\n").append(" }).tabOverride();\n").append("})\n").append(FormJSHelper.getJSEnd());
    }
}
Also used : Form(org.olat.core.gui.components.form.flexible.impl.Form) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration) AssessmentRenderFunctions.getResponseDeclaration(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.getResponseDeclaration)

Example 47 with Form

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

the class AssessmentTestComponentRenderer method renderNavigationAssessmentItem.

private void renderNavigationAssessmentItem(StringOutput sb, AssessmentTestComponent component, TestPlanNode itemNode, Translator translator) {
    String key = itemNode.getKey().toString();
    sb.append("<li class='o_assessmentitem'>");
    sb.append("<button type='button' onclick=\"");
    Form form = component.getQtiItem().getRootForm();
    String dispatchId = component.getQtiItem().getFormDispatchId();
    sb.append(FormJSHelper.getXHRFnCallFor(form, dispatchId, 1, true, true, new NameValuePair("cid", Event.selectItem.name()), new NameValuePair("item", key)));
    sb.append(";\" class='btn btn-default'><span class='questionTitle'>").append(StringHelper.escapeHtml(itemNode.getSectionPartTitle())).append("</span>");
    ItemSessionState itemSessionState = component.getItemSessionState(itemNode.getKey());
    if (itemSessionState.getEndTime() != null) {
        renderItemStatusMessage("ended", "assessment.item.status.finished", sb, translator);
    } else if (itemSessionState.getUnboundResponseIdentifiers().size() > 0 || itemSessionState.getInvalidResponseIdentifiers().size() > 0) {
        renderItemStatusMessage("invalid", "assessment.item.status.needsAttention", sb, translator);
    } else if (itemSessionState.isResponded() || itemSessionState.hasUncommittedResponseValues()) {
        renderItemStatusMessage("answered", "assessment.item.status.answered", sb, translator);
    } else if (itemSessionState.getEntryTime() != null) {
        renderItemStatusMessage("notAnswered", "assessment.item.status.notAnswered", sb, translator);
    } else {
        renderItemStatusMessage("notPresented", "assessment.item.status.notSeen", sb, translator);
    }
    sb.append("</button>");
    sb.append("</li>");
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) ItemSessionState(uk.ac.ed.ph.jqtiplus.state.ItemSessionState) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Example 48 with Form

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

the class AssessmentTestComponentRenderer method renderControl.

private void renderControl(StringOutput sb, AssessmentTestComponent component, String title, boolean primary, String cssClass, NameValuePair... pairs) {
    Form form = component.getQtiItem().getRootForm();
    String dispatchId = component.getQtiItem().getFormDispatchId();
    sb.append("<button type='button' onclick=\"");
    sb.append(FormJSHelper.getXHRFnCallFor(form, dispatchId, 1, true, true, pairs)).append(";\" class='btn ").append("btn-primary ", "btn-default ", primary).append(cssClass).append("'").append("><span>").append(title).append("</span></button>");
}
Also used : Form(org.olat.core.gui.components.form.flexible.impl.Form) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Example 49 with Form

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

the class AssessmentTestComponentRenderer method renderNavigation.

private void renderNavigation(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, URLBuilder ubu, Translator translator) {
    if (component.isRenderNavigation()) {
        sb.append("<div id='o_qti_menu' class='qtiworks o_assessmenttest o_testpartnavigation o_qti_menu_buttonstyle'>");
        // title
        boolean multiPartTest = component.hasMultipleTestParts();
        String title = multiPartTest ? translator.translate("assessment.test.nav.title.multiPartTestMenu") : translator.translate("assessment.test.nav.title.questionMenu");
        sb.append("<h3>").append(title).append("</h3>");
        // part, sections and item refs
        sb.append("<ul class='o_testpartnavigation list-unstyled'>");
        component.getCurrentTestPartNode().getChildren().forEach((node) -> renderNavigation(renderer, sb, component, node, ubu, translator));
        sb.append("</ul>");
        // test controls
        TestSessionController testSessionController = component.getTestSessionController();
        boolean allowedToEndTestPart = testSessionController.getTestSessionState().getCurrentTestPartKey() != null && testSessionController.mayEndCurrentTestPart();
        sb.append("<div class='o_button_group'>");
        sb.append("<button type='button' onclick=\"");
        if (allowedToEndTestPart) {
            Form form = component.getQtiItem().getRootForm();
            String dispatchId = component.getQtiItem().getFormDispatchId();
            sb.append(FormJSHelper.getXHRFnCallFor(form, dispatchId, 1, true, true, new NameValuePair("cid", Event.endTestPart.name())));
        } else {
            sb.append("javascript:");
        }
        String endTestTitle = multiPartTest ? translator.translate("assessment.test.end.testPart") : translator.translate("assessment.test.end.test");
        sb.append(";\" class='btn btn-default o_sel_end_testpart'").append(" disabled", !allowedToEndTestPart).append("><span>").append(endTestTitle).append("</span>");
        sb.append("</button>");
        sb.append("</div></div>");
    }
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) Form(org.olat.core.gui.components.form.flexible.impl.Form) TestSessionController(uk.ac.ed.ph.jqtiplus.running.TestSessionController) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Example 50 with Form

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

the class AssessmentTreeComponentRenderer method renderAssessmentItemLink.

/**
 * @param sb
 * @param component
 * @param itemNode
 * @return The event used or null
 */
private Event renderAssessmentItemLink(StringOutput sb, AssessmentTreeComponent component, TestPlanNode itemNode, Translator translator) {
    String key = itemNode.getKey().toString();
    Form form = component.getQtiItem().getRootForm();
    String dispatchId = component.getQtiItem().getFormDispatchId();
    TestSessionController testSessionController = component.getTestSessionController();
    TestSessionState testSessionState = testSessionController.getTestSessionState();
    TestPart testPart = testSessionController.getCurrentTestPart();
    TestPlanNodeKey currentTestPartKey = testSessionState.getCurrentTestPartKey();
    TestPartSessionState currentTestPartSessionState = testSessionState.getTestPartSessionStates().get(currentTestPartKey);
    Event event;
    if (testPart == null || testPart.getNavigationMode() == NavigationMode.NONLINEAR) {
        if (testSessionState.isEnded() || currentTestPartSessionState.isEnded()) {
            if (itemNode.getEffectiveItemSessionControl().isAllowReview() || itemNode.getEffectiveItemSessionControl().isShowFeedback()) {
                event = Event.reviewItem;
            } else {
                event = null;
            }
        } else {
            event = Event.selectItem;
        }
    } else {
        event = null;
    }
    if (event == null) {
        sb.append("<span class='o_assessmentitem_nav_disabled'>");
    } else {
        sb.append("<a href='javascript:;' onclick=\"").append(FormJSHelper.getXHRFnCallFor(form, dispatchId, 1, true, true, new NameValuePair("cid", event.name()), new NameValuePair("item", key))).append(";\" class='o_sel_assessmentitem'>");
    }
    String title;
    if (component.isShowTitles()) {
        title = StringHelper.escapeHtml(itemNode.getSectionPartTitle());
    } else {
        int num = component.getCandidateSessionContext().getNumber(itemNode);
        title = translator.translate("question.title", new String[] { Integer.toString(num) });
    }
    sb.append("<span class='questionTitle'>").append(title).append("</span>");
    if (event == null) {
        sb.append("</span>");
    } else {
        sb.append("</a>");
    }
    return event;
}
Also used : NameValuePair(org.olat.core.gui.components.form.flexible.impl.NameValuePair) TestSessionState(uk.ac.ed.ph.jqtiplus.state.TestSessionState) Form(org.olat.core.gui.components.form.flexible.impl.Form) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) TestSessionController(uk.ac.ed.ph.jqtiplus.running.TestSessionController) Event(org.olat.ims.qti21.ui.QTIWorksAssessmentTestEvent.Event) CandidateEvent(org.olat.ims.qti21.model.audit.CandidateEvent) TestPartSessionState(uk.ac.ed.ph.jqtiplus.state.TestPartSessionState) TestPlanNodeKey(uk.ac.ed.ph.jqtiplus.state.TestPlanNodeKey)

Aggregations

Form (org.olat.core.gui.components.form.flexible.impl.Form)64 NameValuePair (org.olat.core.gui.components.form.flexible.impl.NameValuePair)42 AssessmentRenderFunctions.contentAsString (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)10 Component (org.olat.core.gui.components.Component)4 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 TestSessionController (uk.ac.ed.ph.jqtiplus.running.TestSessionController)4 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 HashSet (java.util.HashSet)2 Matcher (java.util.regex.Matcher)2 SortKey (org.olat.core.commons.persistence.SortKey)2 TextBoxListElementComponent (org.olat.core.gui.components.form.flexible.impl.elements.TextBoxListElementComponent)2 TextBoxListElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.TextBoxListElementImpl)2 TextModeState (org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextElementImpl.TextModeState)2 FlexiTableElementImpl (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableElementImpl)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 AJAXFlags (org.olat.core.gui.control.winmgr.AJAXFlags)2