mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
Merge branch 'MDL-62382-master' of git://github.com/ryanwyllie/moodle
This commit is contained in:
commit
44d89dfa7a
@ -106,7 +106,8 @@ class quiz_add_random_form extends moodleform {
|
||||
// Add the javascript required to enhance this mform.
|
||||
$PAGE->requires->js_call_amd('mod_quiz/add_random_form', 'init', [
|
||||
$mform->getAttribute('id'),
|
||||
$contexts->lowest()->id
|
||||
$contexts->lowest()->id,
|
||||
$tops
|
||||
]);
|
||||
}
|
||||
|
||||
|
2
mod/quiz/amd/build/add_random_form.min.js
vendored
2
mod/quiz/amd/build/add_random_form.min.js
vendored
@ -1 +1 @@
|
||||
define(["jquery","mod_quiz/random_question_form_preview"],function(a,b){var c=2e3,d={PREVIEW_CONTAINER:'[data-region="random-question-preview-container"]',CATEGORY_FORM_ELEMENT:'[name="category"]',SUBCATEGORY_FORM_ELEMENT:'[name="includesubcategories"]',TAG_IDS_FORM_ELEMENT:'[name="fromtags[]"]'},e=function(a){var b=a.find(d.CATEGORY_FORM_ELEMENT).val(),c=b.split(",");return c[0]},f=function(a){return a.find(d.SUBCATEGORY_FORM_ELEMENT).is(":checked")},g=function(a){var b=a.find(d.TAG_IDS_FORM_ELEMENT).val();return b.map(function(a){var b=a.split(",");return b[0]})},h=function(a,c){var h=a.find(d.PREVIEW_CONTAINER);b.reload(h,e(a),f(a),g(a),c)},i=function(a){return a.closest(d.CATEGORY_FORM_ELEMENT).length>0||(a.closest(d.SUBCATEGORY_FORM_ELEMENT).length>0||a.closest(d.TAG_IDS_FORM_ELEMENT).length>0)},j=function(d,e){var f=null;d.on("change",function(g){i(a(g.target))&&(b.showLoadingIcon(d),f&&clearTimeout(f),f=setTimeout(function(){h(d,e)},c))})},k=function(b,c){var d=a("#"+b);h(d,c),j(d,c)};return{init:k}});
|
||||
define(["jquery","mod_quiz/random_question_form_preview"],function(a,b){var c=2e3,d={PREVIEW_CONTAINER:'[data-region="random-question-preview-container"]',CATEGORY_FORM_ELEMENT:'[name="category"]',SUBCATEGORY_FORM_ELEMENT:'[name="includesubcategories"]',TAG_IDS_FORM_ELEMENT:'[name="fromtags[]"]'},e=function(a){return a.find(d.CATEGORY_FORM_ELEMENT).val()},f=function(a){var b=e(a),c=b.split(",");return c[0]},g=function(a,b){var c=e(a);return b.indexOf(c)>-1},h=function(a,b){return!!g(a,b)||a.find(d.SUBCATEGORY_FORM_ELEMENT).is(":checked")},i=function(a){var b=a.find(d.TAG_IDS_FORM_ELEMENT).val();return b.map(function(a){var b=a.split(",");return b[0]})},j=function(a,c,e){var g=a.find(d.PREVIEW_CONTAINER);b.reload(g,f(a),h(a,e),i(a),c)},k=function(a){return a.closest(d.CATEGORY_FORM_ELEMENT).length>0||(a.closest(d.SUBCATEGORY_FORM_ELEMENT).length>0||a.closest(d.TAG_IDS_FORM_ELEMENT).length>0)},l=function(d,e,f){var g=null;d.on("change",function(h){k(a(h.target))&&(b.showLoadingIcon(d),g&&clearTimeout(g),g=setTimeout(function(){j(d,e,f)},c))})},m=function(b,c,d){var e=a("#"+b);j(e,c,d),l(e,c,d)};return{init:m}});
|
@ -41,6 +41,16 @@ define(
|
||||
TAG_IDS_FORM_ELEMENT: '[name="fromtags[]"]'
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the selected category value from the form.
|
||||
*
|
||||
* @param {jquery} form The form element.
|
||||
* @return {string} The category value.
|
||||
*/
|
||||
var getCategorySelectValue = function(form) {
|
||||
return form.find(SELECTORS.CATEGORY_FORM_ELEMENT).val();
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the category id from the form.
|
||||
*
|
||||
@ -50,22 +60,39 @@ define(
|
||||
var getCategoryId = function(form) {
|
||||
// The value string is the category id and category context id joined
|
||||
// by a comma.
|
||||
var valueString = form.find(SELECTORS.CATEGORY_FORM_ELEMENT).val();
|
||||
var valueString = getCategorySelectValue(form);
|
||||
// Split the two ids.
|
||||
var values = valueString.split(',');
|
||||
// Return just the category id.
|
||||
return values[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if a top level category is selected in the form.
|
||||
*
|
||||
* @param {jquery} form The form element.
|
||||
* @param {string[]} topCategories List of top category values (matching the select box values)
|
||||
* @return {bool}
|
||||
*/
|
||||
var isTopLevelCategorySelected = function(form, topCategories) {
|
||||
var selectedValue = getCategorySelectValue(form);
|
||||
return (topCategories.indexOf(selectedValue) > -1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if the form indicates we should include include subcategories in
|
||||
* the filter.
|
||||
*
|
||||
* @param {jquery} form The form element.
|
||||
* @param {string[]} topCategories List of top category values (matching the select box values)
|
||||
* @return {bool}
|
||||
*/
|
||||
var shouldIncludeSubcategories = function(form) {
|
||||
return form.find(SELECTORS.SUBCATEGORY_FORM_ELEMENT).is(':checked');
|
||||
var shouldIncludeSubcategories = function(form, topCategories) {
|
||||
if (isTopLevelCategorySelected(form, topCategories)) {
|
||||
return true;
|
||||
} else {
|
||||
return form.find(SELECTORS.SUBCATEGORY_FORM_ELEMENT).is(':checked');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -89,13 +116,14 @@ define(
|
||||
*
|
||||
* @param {jquery} form The form element.
|
||||
* @param {int} contextId The current context id.
|
||||
* @param {string[]} topCategories List of top category values (matching the select box values)
|
||||
*/
|
||||
var reloadQuestionPreview = function(form, contextId) {
|
||||
var reloadQuestionPreview = function(form, contextId, topCategories) {
|
||||
var previewContainer = form.find(SELECTORS.PREVIEW_CONTAINER);
|
||||
RandomQuestionFormPreview.reload(
|
||||
previewContainer,
|
||||
getCategoryId(form),
|
||||
shouldIncludeSubcategories(form),
|
||||
shouldIncludeSubcategories(form, topCategories),
|
||||
getTagIds(form),
|
||||
contextId
|
||||
);
|
||||
@ -136,8 +164,9 @@ define(
|
||||
*
|
||||
* @param {jquery} form The form element.
|
||||
* @param {int} contextId The current context id.
|
||||
* @param {string[]} topCategories List of top category values (matching the select box values)
|
||||
*/
|
||||
var addEventListeners = function(form, contextId) {
|
||||
var addEventListeners = function(form, contextId, topCategories) {
|
||||
var reloadTimerId = null;
|
||||
|
||||
form.on('change', function(e) {
|
||||
@ -160,7 +189,7 @@ define(
|
||||
// in case the user is still modifying the form. We don't want to
|
||||
// spam reload requests.
|
||||
reloadTimerId = setTimeout(function() {
|
||||
reloadQuestionPreview(form, contextId);
|
||||
reloadQuestionPreview(form, contextId, topCategories);
|
||||
}, RELOAD_DELAY);
|
||||
});
|
||||
};
|
||||
@ -171,12 +200,13 @@ define(
|
||||
*
|
||||
* @param {jquery} formId The form element id.
|
||||
* @param {int} contextId The current context id.
|
||||
* @param {string[]} topCategories List of top category values (matching the select box values)
|
||||
*/
|
||||
var init = function(formId, contextId) {
|
||||
var init = function(formId, contextId, topCategories) {
|
||||
var form = $('#' + formId);
|
||||
|
||||
reloadQuestionPreview(form, contextId);
|
||||
addEventListeners(form, contextId);
|
||||
reloadQuestionPreview(form, contextId, topCategories);
|
||||
addEventListeners(form, contextId, topCategories);
|
||||
};
|
||||
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user