MDL-84146 question: Improve handling of JS parameters

This commit is contained in:
Mark Johnson
2025-02-03 14:06:59 +07:00
committed by Huong Nguyen
parent 4bf0e1efc4
commit 47fb1d93af
5 changed files with 21 additions and 11 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+4 -5
View File
@@ -39,8 +39,8 @@ import Fragment from 'core/fragment';
* @param {string} callback Name of the callback for the fragment API (e.g question_data)
* @param {string} view The class name of the question bank view class used for this page.
* @param {Number} cmid If we are in an activitiy, the course module ID.
* @param {string} pagevars JSON-encoded parameters from passed from the view, including filters and jointype.
* @param {string} extraparams JSON-encoded additional parameters specific to this view class, used for re-rendering the view.
* @param {Object} pagevars JSON-encoded parameters from passed from the view, including filters and jointype.
* @param {Object} extraparams JSON-encoded additional parameters specific to this view class, used for re-rendering the view.
*/
export const init = (
filterRegionId,
@@ -53,7 +53,7 @@ export const init = (
view,
cmid,
pagevars,
extraparams
extraparams,
) => {
const SELECTORS = {
@@ -71,7 +71,7 @@ export const init = (
const filterSet = document.querySelector(`#${filterRegionId}`);
const viewData = {
extraparams,
extraparams: JSON.stringify(extraparams),
cmid,
view,
cat: defaultcategoryid,
@@ -212,7 +212,6 @@ export const init = (
});
// Run apply filter at page load.
pagevars = JSON.parse(pagevars);
let initialFilters;
let jointype = null;
if (pagevars.filter) {
@@ -133,7 +133,7 @@ class question_bank_filter_ui extends datafilter {
'contextid' => $this->context->id,
'component' => $this->component,
'callback' => $this->callback,
'view' => str_replace('\\', '\\\\', $this->view),
'view' => $this->view,
'cmid' => $this->cmid ?? 0,
'pagevars' => json_encode($this->pagevars),
'extraparams' => json_encode($this->extraparams),
@@ -28,7 +28,7 @@
"contextid": "3",
"component": "core_quiz",
"callback": "get_question_data",
"view": "\\\\core\\\\question\\\\local\\\\bank\\\\view",
"view": "\\core\\question\\local\\bank\\view",
"cmid": "4",
"pagevars": "[]",
"extraparams": "[]"
@@ -39,7 +39,18 @@
{{#js}}
require(['core_question/filter'], function(Filter) {
Filter.init('core-filter-{{uniqid}}', {{courseid}}, {{categoryid}}, {{perpage}}, {{contextid}},
'{{component}}', '{{callback}}', '{{view}}', {{cmid}}, '{{{pagevars}}}', '{{{extraparams}}}');
Filter.init(
{{#quote}}core-filter-{{uniqid}}{{/quote}},
{{courseid}},
{{categoryid}},
{{perpage}},
{{contextid}},
{{#quote}}{{component}}{{/quote}},
{{#quote}}{{callback}}{{/quote}},
{{#quote}}{{view}}{{/quote}},
{{cmid}},
{{{pagevars}}},
{{{extraparams}}},
);
});
{{/js}}