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 { + $('