MDL-78091 core_quiz: initial deprecation add_random_form and associates

The just removed mod_quiz\form\add_random_form was the only place in
core where the mod_quiz/add_random_form javascript was called, so we can
deprecate this now. This also enables us to deprecate the
mod_quiz/random_question_form_preview javascript and the
mod_quiz/random_question_form_preview_question_list template as they are
direct dependends.

Signed-off-by: Daniel Ziegenberg <[email protected]>
This commit is contained in:
Daniel Ziegenberg
2025-04-16 15:44:58 +02:00
parent e927dc51ad
commit 5b404a92ae
8 changed files with 26 additions and 2 deletions
@@ -0,0 +1,13 @@
issueNumber: MDL-78091
notes:
mod_quiz:
- message: >
Initial deprecation add_random_form and associates.
The just removed mod_quiz\form\add_random_form was the only place in
core where the mod_quiz/add_random_form javascript was called, so we can
deprecate this now. This also enables us to deprecate the
mod_quiz/random_question_form_preview javascript and the
mod_quiz/random_question_form_preview_question_list template as they are
direct dependends.
type: deprecated
+2
View File
@@ -4,6 +4,8 @@
* @module mod_quiz/add_random_form
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since 5.0 MDL-78091.
* @todo Final deprecation in Moodle 6.0. See MDL-84777.
*/
define("mod_quiz/add_random_form",["jquery","mod_quiz/random_question_form_preview"],(function($,RandomQuestionFormPreview){var SELECTORS_PREVIEW_CONTAINER='[data-region="random-question-preview-container"]',SELECTORS_CATEGORY_FORM_ELEMENT='[name="category"]',SELECTORS_SUBCATEGORY_FORM_ELEMENT='[name="includesubcategories"]',SELECTORS_TAG_IDS_FORM_ELEMENT='[name="fromtags[]"]',getCategorySelectValue=function(form){return form.find(SELECTORS_CATEGORY_FORM_ELEMENT).val()},shouldIncludeSubcategories=function(form,topCategories){return!!function(form,topCategories){var selectedValue=getCategorySelectValue(form);return topCategories.indexOf(selectedValue)>-1}(form,topCategories)||form.find(SELECTORS_SUBCATEGORY_FORM_ELEMENT).is(":checked")},reloadQuestionPreview=function(form,contextId,topCategories){var previewContainer=form.find(SELECTORS_PREVIEW_CONTAINER);RandomQuestionFormPreview.reload(previewContainer,function(form){return getCategorySelectValue(form).split(",")[0]}(form),shouldIncludeSubcategories(form,topCategories),function(form){return form.find(SELECTORS_TAG_IDS_FORM_ELEMENT).val().map((function(value){return value.split(",")[0]}))}(form),contextId)},addEventListeners=function(form,contextId,topCategories){var reloadTimerId=null;const tagsFilter=form.find(SELECTORS_TAG_IDS_FORM_ELEMENT);form.add(tagsFilter).on("change",(function(e){var element;((element=$(e.target)).closest(SELECTORS_CATEGORY_FORM_ELEMENT).length>0||element.closest(SELECTORS_SUBCATEGORY_FORM_ELEMENT).length>0||element.closest(SELECTORS_TAG_IDS_FORM_ELEMENT).length>0)&&(RandomQuestionFormPreview.showLoadingIcon(form),reloadTimerId&&clearTimeout(reloadTimerId),reloadTimerId=setTimeout((function(){reloadQuestionPreview(form,contextId,topCategories)}),2e3))}))};return{init:function(formId,contextId,topCategories,isTagsEnabled){if(1==isTagsEnabled){var form=$("#"+formId);reloadQuestionPreview(form,contextId,topCategories),addEventListeners(form,contextId,topCategories)}}}}));
File diff suppressed because one or more lines are too long
@@ -5,6 +5,8 @@
* @module mod_quiz/random_question_form_preview
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since 5.0 MDL-78091.
* @todo Final deprecation in Moodle 6.0. See MDL-84777.
*/
define("mod_quiz/random_question_form_preview",["jquery","core/ajax","core/str","core/notification","core/templates","core/paged_content_factory"],(function($,Ajax,Str,Notification,Templates,PagedContentFactory){var TEMPLATE_NAME="mod_quiz/random_question_form_preview_question_list",SELECTORS_LOADING_ICON_CONTAINER='[data-region="overlay-icon-container"]',SELECTORS_QUESTION_COUNT_CONTAINER='[data-region="question-count-container"]',SELECTORS_QUESTION_LIST_CONTAINER='[data-region="question-list-container"]',showLoadingIcon=function(root){root.find(SELECTORS_LOADING_ICON_CONTAINER).removeClass("hidden")},hideLoadingIcon=function(root){root.find(SELECTORS_LOADING_ICON_CONTAINER).addClass("hidden")},requestQuestions=function(categoryId,includeSubcategories,tagIds,contextId,limit,offset){var request={methodname:"core_question_get_random_question_summaries",args:{categoryid:categoryId,includesubcategories:includeSubcategories,tagids:tagIds,contextid:contextId,limit:limit,offset:offset}};return Ajax.call([request])[0]};return{reload:function(root,categoryId,includeSubcategories,tagIds,contextId){return showLoadingIcon(root),requestQuestions(categoryId,includeSubcategories,tagIds,contextId,5,0).then((function(response){var totalCount=response.totalcount;return function(root,questionCount){Str.get_string("questionsmatchingfilter","mod_quiz",questionCount).then((function(string){root.find(SELECTORS_QUESTION_COUNT_CONTAINER).html(string)})).fail(Notification.exception)}(root,totalCount),response})).then((function(response){var totalQuestionCount=response.totalcount,questions=response.questions;return questions.length?function(categoryId,includeSubcategories,tagIds,contextId,totalQuestionCount,firstPageQuestions){return PagedContentFactory.createFromAjax(totalQuestionCount,5,(function(pagesData){return pagesData.map((function(pageData){var limit=pageData.limit,offset=pageData.offset;return 0==offset?Templates.render(TEMPLATE_NAME,{questions:firstPageQuestions}):requestQuestions(categoryId,includeSubcategories,tagIds,contextId,limit,offset).then((function(response){var questions=response.questions;return Templates.render(TEMPLATE_NAME,{questions:questions})})).fail(Notification.exception)}))}))}(categoryId,includeSubcategories,tagIds,contextId,totalQuestionCount,questions):$.Deferred().resolve("","")})).then((function(html,js){var container=root.find(SELECTORS_QUESTION_LIST_CONTAINER);Templates.replaceNodeContents(container,html,js)})).always((function(){hideLoadingIcon(root)})).fail(Notification.exception)},showLoadingIcon:showLoadingIcon,hideLoadingIcon:hideLoadingIcon}}));
File diff suppressed because one or more lines are too long
+2
View File
@@ -19,6 +19,8 @@
* @module mod_quiz/add_random_form
* @copyright 2018 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since 5.0 MDL-78091.
* @todo Final deprecation in Moodle 6.0. See MDL-84777.
*/
define(
[
@@ -20,6 +20,8 @@
* @module mod_quiz/random_question_form_preview
* @copyright 2018 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since 5.0 MDL-78091.
* @todo Final deprecation in Moodle 6.0. See MDL-84777.
*/
define(
[
@@ -17,6 +17,9 @@
{{!
@template mod_quiz/random_question_form_preview_question_list
@deprecated since Moodle 5.0
@todo MDL-84777 Final deprecation on Moodle 6.0
A preview section for the list of questions that match the random
question criteria in the random question form.