Index: lams_central/web/includes/javascript/qb-question.js =================================================================== diff -u -re11f383d97ca45f4fc0d1c8a283b306439dff946 -r70a326811aab339193f6031102dfde367b21cc5c --- lams_central/web/includes/javascript/qb-question.js (.../qb-question.js) (revision e11f383d97ca45f4fc0d1c8a283b306439dff946) +++ lams_central/web/includes/javascript/qb-question.js (.../qb-question.js) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -10,14 +10,14 @@ $("#question-settings-link").on('click', function() { $('.question-tab:visible').fadeToggle("fast", function() { $( ".settings-tab" ).show(); - }); + }); $('.settings-tab:visible').fadeToggle("fast", function() { $( ".question-tab" ).show(); - }); + }); //toggle Settings button class $(this).toggleClass("btn-default btn-primary"); - }); + }); // trigger is-new-question-version check when changing certain data in a question $('#assessmentQuestionForm').on('input', 'input, select, textarea', function(){ @@ -28,21 +28,66 @@ $('body').on('input paste', '[contenteditable]', function(){ checkQuestionNewVersion(false); }); + + $('#collection-uid-select').change(function(){ + let collectionSelect = $(this), + newValue = collectionSelect.val(), + previouslySelectedOption = $('option[selected]', collectionSelect); + if (newValue == -1) { + // create a new collection on the fly + let newCollectionName = prompt(ADD_COLLECTION_LABEL), + newCollectionUid = -1; + if (newCollectionName) { + newCollectionName = newCollectionName.trim(); + let data = { + 'name' : newCollectionName + }; + data[csrfTokenName] = csrfTokenValue; + + $.ajax({ + 'url' : LAMS_URL + 'qb/collection/addCollection.do', + 'async' : false, + 'type' : 'post', + 'dataType' : 'text', + 'data' : data, + success : function (response){ + if (!isNaN(response)) { + newCollectionUid = +response; + } + }, + error : function (xhr) { + alert(xhr.responseText); + } + }); + } + + if (newCollectionUid == -1 || newCollectionUid == 0) { + // revert to previous selection + previouslySelectedOption.prop('selected', true); + } else { + $('').attr('value', newCollectionUid).attr('selected', 'selected') + .prop('selected', true).text(newCollectionName).insertBefore($('option[value="-1"]', collectionSelect)); + } + } else { + previouslySelectedOption.removeAttr('selected'); + $('option[value="' + newValue + '"]', collectionSelect).attr('selected', 'selected'); + } + }); }); // submits whole question form in order to check if it changed enough to produce a new question version function checkQuestionNewVersion(quick){ if (isNewQuestion) { return; } - + let currentTime = new Date().getTime(); // skip initial check of new version if (currentTime < newQuestionVersionCheckTime || (!quick && currentTime - newQuestionVersionCheckTime < newQuestionVersionCheckThrottle)) { return; } newQuestionVersionCheckTime = currentTime; - + let form = $('#assessmentQuestionForm'), validator = form.data('validator'); if (!validator) { @@ -54,11 +99,11 @@ } function isVersionCheck() { - return $('#assessmentQuestionForm').attr('action') == CHECK_QUESTION_NEW_VERSION_URL; + return $('#assessmentQuestionForm').attr('action') == CHECK_QUESTION_NEW_VERSION_URL; } // post-submit callback -function afterRatingSubmit(responseText, statusText) { +function afterRatingSubmit(responseText, statusText) { self.parent.refreshThickbox() self.parent.tb_remove(); } @@ -73,29 +118,29 @@ //form validation handler. It's called when the form contains an error. function formValidationInvalidHandler(form, validator) { - var errors = validator.numberOfInvalids(); - if (errors) { - var message = errors == 1 + var errors = validator.numberOfInvalids(); + if (errors) { + var message = errors == 1 ? VALIDATION_ERROR_LABEL - : VALIDATION_ERRORS_LABEL.replace("{errors_counter}", errors); - - $("div.error span").html(message); - $("div.error").show(); - - //show/hide settings tab, if it contains an error - var showSettingsTab = true; - $.each(validator.errorMap, function(key, value) { - showSettingsTab &= key == "maxMark" || key == "penaltyFactor"; - }); - if (showSettingsTab) { - $("#question-settings-link.btn-default").trigger( "click" ); - } else { - $("#question-settings-link.btn-primary").trigger( "click" ); - } - - } else { - $("div.error").hide(); - } + : VALIDATION_ERRORS_LABEL.replace("{errors_counter}", errors); + + $("div.error span").html(message); + $("div.error").show(); + + //show/hide settings tab, if it contains an error + var showSettingsTab = true; + $.each(validator.errorMap, function(key, value) { + showSettingsTab &= key == "maxMark" || key == "penaltyFactor"; + }); + if (showSettingsTab) { + $("#question-settings-link.btn-default").trigger( "click" ); + } else { + $("#question-settings-link.btn-primary").trigger( "click" ); + } + + } else { + $("div.error").hide(); + } } function formValidationErrorPlacement( error, element ) { // Add the `help-block` class to the error element @@ -123,4 +168,4 @@ function formValidationUnhighlight ( element, errorClass, validClass ) { $( element ).parent().addClass( "has-success" ).removeClass( "has-error" ); $( element ).not(".fake-validation-input").next( "span" ).addClass( "fa-check" ).removeClass( "fa-remove" ); -} +} \ No newline at end of file Index: lams_central/web/qb/authoring/addQuestionFooter.jsp =================================================================== diff -u -rc04504bfdd9685850e15792838241a748f13560e -r70a326811aab339193f6031102dfde367b21cc5c --- lams_central/web/qb/authoring/addQuestionFooter.jsp (.../addQuestionFooter.jsp) (revision c04504bfdd9685850e15792838241a748f13560e) +++ lams_central/web/qb/authoring/addQuestionFooter.jsp (.../addQuestionFooter.jsp) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -25,6 +25,10 @@ + + + + Index: lams_central/web/qb/authoring/addQuestionHeader.jsp =================================================================== diff -u -rdab57abcc025fa02ac2cc688421251f51c8942cf -r70a326811aab339193f6031102dfde367b21cc5c --- lams_central/web/qb/authoring/addQuestionHeader.jsp (.../addQuestionHeader.jsp) (revision dab57abcc025fa02ac2cc688421251f51c8942cf) +++ lams_central/web/qb/authoring/addQuestionHeader.jsp (.../addQuestionHeader.jsp) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -1,8 +1,11 @@ <%@ include file="/common/taglibs.jsp"%> +<%@ page import="org.lamsfoundation.lams.util.Configuration" %> +<%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys" %> +<%=Configuration.get(ConfigurationKeys.QB_COLLECTIONS_CREATE_ALLOW)%> - + @@ -14,25 +17,29 @@ Index: lams_central/web/qb/authoring/addessay.jsp =================================================================== diff -u -r62136ef7274ade99c326404298d51c77085cffcb -r70a326811aab339193f6031102dfde367b21cc5c --- lams_central/web/qb/authoring/addessay.jsp (.../addessay.jsp) (revision 62136ef7274ade99c326404298d51c77085cffcb) +++ lams_central/web/qb/authoring/addessay.jsp (.../addessay.jsp) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -1,153 +1,161 @@ <%@ include file="/common/taglibs.jsp"%> +<%@ page import="org.lamsfoundation.lams.util.Configuration" %> +<%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys" %> +<%=Configuration.get(ConfigurationKeys.QB_COLLECTIONS_CREATE_ALLOW)%> - - - - - + + + + + - - - - - - - - - - + + + + + + + + + - - - + + + + - + - - + + @@ -161,120 +169,120 @@ - + - - + + - - - + + + - + - + - + - + - + - - - + + + - - - " alt=""> - - - - - + + + " alt=""> + + + + + - + - - - - - - - - Python - JavaScript - Java - Scala - Kotlin - C - Objective C - C++ - C# - - + + + + + + + + Python + JavaScript + Java + Scala + Kotlin + C + Objective C + C++ + C# + + - + - + - + - + checked="checked"/> - - - - - - - + checked="checked"/> + + + + + + + - + - + checked="checked"/> - - - - - - - + checked="checked"/> + + + + + + + - + - + - + - + - - - + + + <%@ include file="addQuestionFooter.jsp"%> - - + + \ No newline at end of file Index: lams_central/web/qb/authoring/addtruefalse.jsp =================================================================== diff -u -rc04504bfdd9685850e15792838241a748f13560e -r70a326811aab339193f6031102dfde367b21cc5c --- lams_central/web/qb/authoring/addtruefalse.jsp (.../addtruefalse.jsp) (revision c04504bfdd9685850e15792838241a748f13560e) +++ lams_central/web/qb/authoring/addtruefalse.jsp (.../addtruefalse.jsp) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -1,11 +1,14 @@ <%@ include file="/common/taglibs.jsp"%> +<%@ page import="org.lamsfoundation.lams.util.Configuration" %> +<%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys" %> +<%=Configuration.get(ConfigurationKeys.QB_COLLECTIONS_CREATE_ALLOW)%> - + - + @@ -20,63 +23,67 @@ const SAVE_QUESTION_URL = "/lams/qb/edit/saveOrUpdateQuestion.do"; const VALIDATION_ERROR_LABEL = ""; const VALIDATION_ERRORS_LABEL = "{errors_counter}"; - - var isNewQuestion = ${isNewQuestion}; + const ADD_COLLECTION_LABEL = ''; + const LAMS_URL = ''; + + var isNewQuestion = ${isNewQuestion}, + csrfTokenName = '', + csrfTokenValue = ''; - - - + + + - + + method="post" autocomplete="off"> @@ -109,94 +116,94 @@ - + - - + + - - - + + + - + - + - + - + - + - + - + - - + + - - - + + + - - - " alt=""> - - - - - + + + " alt=""> + + + + + - + - - - " alt=""> - - - - - + + + " alt=""> + + + + + - + - + - + - - + + - + - - + + - + - + - + <%@ include file="addQuestionFooter.jsp"%> - - + + \ No newline at end of file Index: lams_central/web/questions/questionChoice.jsp =================================================================== diff -u -r3bc02e2e2858938ef1fce59766cb6e682de8107d -r70a326811aab339193f6031102dfde367b21cc5c --- lams_central/web/questions/questionChoice.jsp (.../questionChoice.jsp) (revision 3bc02e2e2858938ef1fce59766cb6e682de8107d) +++ lams_central/web/questions/questionChoice.jsp (.../questionChoice.jsp) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -184,9 +184,6 @@ previouslySelectedOption.removeAttr('selected'); $('option[value="' + newValue + '"]', collectionSelect).attr('selected', 'selected'); } - - - }); }); @@ -218,7 +215,6 @@ - @@ -229,6 +225,7 @@ + Index: lams_tool_laqa/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -rdecee05de5d7a90fe2aef3af04f588494262685b -r70a326811aab339193f6031102dfde367b21cc5c --- lams_tool_laqa/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision decee05de5d7a90fe2aef3af04f588494262685b) +++ lams_tool_laqa/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -230,3 +230,5 @@ label.answer.required = Require answer? label.prevent.learner.autosave.mutliple.tabs = You seem to have two LAMS tabs open for this exam. Please close one of them. Otherwise, answers will not be recorder properly and affect your score. label.no.added.questions = No questions have been added. Please add at least one question. +label.questions.choice.collection.new.option = +label.questions.choice.collection.new.prompt = Enter a name for the new collection: \ No newline at end of file Index: lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/controller/AuthoringController.java =================================================================== diff -u -rc34b16da7fe48d6ed5ad039f0a61f66a12b215a0 -r70a326811aab339193f6031102dfde367b21cc5c --- lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/controller/AuthoringController.java (.../AuthoringController.java) (revision c34b16da7fe48d6ed5ad039f0a61f66a12b215a0) +++ lams_tool_laqa/src/java/org/lamsfoundation/lams/tool/qa/web/controller/AuthoringController.java (.../AuthoringController.java) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -23,24 +23,8 @@ package org.lamsfoundation.lams.tool.qa.web.controller; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.UUID; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.log4j.Logger; @@ -69,14 +53,16 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.sql.Timestamp; +import java.util.*; /** * Q&A Tool's authoring methods. Additionally, there is one more method that initializes authoring and it's located in @@ -483,6 +469,7 @@ form.setContentFolderID(questionContentFolderID); form.setQuestionId(qbService.generateNextQuestionId()); // generate a new question ID right away, so another user won't "take it" + request.setAttribute("isNewQuestion", true); QbUtils.fillFormWithUserCollections(qbService, form, null); return "authoring/newQuestionBox"; } @@ -515,7 +502,7 @@ form.setContentFolderID(qbQuestion.getContentFolderId()); form.setSessionMapID(sessionMapID); QbUtils.fillFormWithUserCollections(qbService, QaAppConstants.MY_SIGNATURE, form, qbQuestion.getUid()); - + request.setAttribute("isNewQuestion", false); request.setAttribute(AttributeNames.PARAM_CONTENT_FOLDER_ID, contentFolderID); return "authoring/newQuestionBox"; } @@ -673,4 +660,4 @@ request.setAttribute(QaAppConstants.ATTR_SESSION_MAP_ID, sessionMapID); return (SessionMap) request.getSession().getAttribute(sessionMapID); } -} +} \ No newline at end of file Index: lams_tool_laqa/web/authoring/newQuestionBox.jsp =================================================================== diff -u -r7ca2115adff4164bb6f5b3b878c68a205cc98634 -r70a326811aab339193f6031102dfde367b21cc5c --- lams_tool_laqa/web/authoring/newQuestionBox.jsp (.../newQuestionBox.jsp) (revision 7ca2115adff4164bb6f5b3b878c68a205cc98634) +++ lams_tool_laqa/web/authoring/newQuestionBox.jsp (.../newQuestionBox.jsp) (revision 70a326811aab339193f6031102dfde367b21cc5c) @@ -1,5 +1,8 @@ <%@ include file="/common/taglibs.jsp"%> +<%@ page import="org.lamsfoundation.lams.util.Configuration" %> +<%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys" %> +<%=Configuration.get(ConfigurationKeys.QB_COLLECTIONS_CREATE_ALLOW)%> @@ -11,21 +14,27 @@ - + @@ -39,83 +48,83 @@ form.attr('action', action + '&newVersion=true'); } form.submit(); - } - + } + $(document).ready(function(){ - - $("#newQuestionForm").validate({ - ignore : 'div.cke_editable', - rules: { - title: "required", - minWordsLimit: { - digits: true - } - }, - messages: { - title: "" - }, - invalidHandler: function(form, validator) { - var errors = validator.numberOfInvalids(); - if (errors) { - var message = errors == 1 - ? "" - : "" + errors + ""; - - $("div.error span").html(message); - $("div.error").show(); - } else { - $("div.error").hide(); - } - }, - debug: false, - submitHandler: function(form) { - $("#description").val(CKEDITOR.instances.description.getData()); - $("#feedback").val(CKEDITOR.instances.feedback.getData()); - $("#new-collection-uid").val($("#collection-uid-select option:selected").val()); - - var items = { - target: parent.jQuery('#itemArea'), - success: function (responseText, statusText) { - self.parent.refreshThickbox() - self.parent.tb_remove(); - } - }; - - $('#newQuestionForm').ajaxSubmit(items); - }, - invalidHandler: formValidationInvalidHandler, + + $("#newQuestionForm").validate({ + ignore : 'div.cke_editable', + rules: { + title: "required", + minWordsLimit: { + digits: true + } + }, + messages: { + title: "" + }, + invalidHandler: function(form, validator) { + var errors = validator.numberOfInvalids(); + if (errors) { + var message = errors == 1 + ? "" + : "" + errors + ""; + + $("div.error span").html(message); + $("div.error").show(); + } else { + $("div.error").hide(); + } + }, + debug: false, + submitHandler: function(form) { + $("#description").val(CKEDITOR.instances.description.getData()); + $("#feedback").val(CKEDITOR.instances.feedback.getData()); + $("#new-collection-uid").val($("#collection-uid-select option:selected").val()); + + var items = { + target: parent.jQuery('#itemArea'), + success: function (responseText, statusText) { + self.parent.refreshThickbox() + self.parent.tb_remove(); + } + }; + + $('#newQuestionForm').ajaxSubmit(items); + }, + invalidHandler: formValidationInvalidHandler, errorElement: "em", errorPlacement: formValidationErrorPlacement, highlight: formValidationHighlight, unhighlight: formValidationUnhighlight - }); + }); - //spinner - var minimumWordsSpinner = $( "#min-words-limit" ).spinner({ + //spinner + var minimumWordsSpinner = $( "#min-words-limit" ).spinner({ min: 0, disabled: ($( "#min-words-limit" ).val() == 0) - }); - - //spinner - $("#min-words-limit-checkbox").click(function() { - if ( minimumWordsSpinner.spinner( "option", "disabled" ) ) { - minimumWordsSpinner.spinner( "enable" ); - } else { - minimumWordsSpinner.spinner( "disable" ); - } - }); - }); - + }); + + //spinner + $("#min-words-limit-checkbox").click(function() { + if ( minimumWordsSpinner.spinner( "option", "disabled" ) ) { + minimumWordsSpinner.spinner( "enable" ); + } else { + minimumWordsSpinner.spinner( "disable" ); + } + }); + }); + - - - - - + + + + - - + + + @@ -124,96 +133,100 @@ - + - + - + - + - + - + - + - + checked="checked"/> - + checked="checked"/> + - - - - - - + + + + + + - + - + - + - - -