MDL-74054 core_question: Re-apply filters when performing a qbank action
This changes the root element used by the fragment when applying filters, so that the whole of display_question_list() is reloaded. This ensures that the returnurl will be updated correctly on the question actions and bulk actions without manipulating then further in Javascript.
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -86,8 +86,6 @@ export const init = (
|
||||
filterCondition.sortData = JSON.parse(defaultSort);
|
||||
}
|
||||
|
||||
let filterQuery = '';
|
||||
|
||||
/**
|
||||
* Retrieve table data.
|
||||
*
|
||||
@@ -116,7 +114,6 @@ export const init = (
|
||||
cmid: cmid,
|
||||
filtercondition: JSON.stringify(filterCondition),
|
||||
extraparams: extraparams,
|
||||
filterquery: filterQuery,
|
||||
lastchanged: document.querySelector(SELECTORS.LASTCHANGED_FIELD)?.value ?? null
|
||||
};
|
||||
Fragment.loadFragment(component, callback, contextId, viewData)
|
||||
@@ -154,13 +151,6 @@ export const init = (
|
||||
const filterQuery = JSON.stringify(filters);
|
||||
url.searchParams.set('filter', filterQuery);
|
||||
history.pushState(filters, '', url);
|
||||
document.querySelectorAll(SELECTORS.BULK_ACTIONS).forEach(bulkAction => {
|
||||
const actionUrl = new URL(bulkAction.formAction);
|
||||
const returnUrl = new URL(actionUrl.searchParams.get('returnurl'));
|
||||
returnUrl.searchParams.set('filter', filterQuery);
|
||||
actionUrl.searchParams.set('returnurl', returnUrl);
|
||||
bulkAction.formAction = actionUrl;
|
||||
});
|
||||
const editSwitch = document.querySelector(SELECTORS.EDIT_SWITCH);
|
||||
if (editSwitch) {
|
||||
const editSwitchUrlInput = document.querySelector(SELECTORS.EDIT_SWITCH_URL);
|
||||
|
||||
@@ -1111,10 +1111,15 @@ class view {
|
||||
[$categoryid, $contextid] = category_condition::validate_category_param($this->pagevars['cat']);
|
||||
$catcontext = \context::instance_by_id($contextid);
|
||||
|
||||
$canadd = has_capability('moodle/question:add', $catcontext);
|
||||
|
||||
$category = category_condition::get_category_record($categoryid, $contextid);
|
||||
$this->create_new_question_form($category, $canadd);
|
||||
echo \html_writer::start_tag(
|
||||
'div',
|
||||
[
|
||||
'id' => 'questionscontainer',
|
||||
'data-component' => $this->component,
|
||||
'data-callback' => $this->callback,
|
||||
'data-contextid' => $this->get_most_specific_context()->id,
|
||||
]
|
||||
);
|
||||
|
||||
$this->build_query();
|
||||
$questionsrs = $this->load_page_questions();
|
||||
@@ -1134,7 +1139,7 @@ class view {
|
||||
echo \html_writer::input_hidden_params($this->baseurl);
|
||||
|
||||
echo \html_writer::start_tag('div',
|
||||
['class' => 'categoryquestionscontainer', 'id' => 'questionscontainer']);
|
||||
['class' => 'categoryquestionscontainer']);
|
||||
if ($totalquestions > 0) {
|
||||
// Bulk load any required statistics.
|
||||
$this->load_required_statistics($questions);
|
||||
@@ -1151,6 +1156,7 @@ class view {
|
||||
|
||||
echo \html_writer::end_tag('fieldset');
|
||||
echo \html_writer::end_tag('form');
|
||||
echo \html_writer::end_tag('div');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-3
@@ -138,8 +138,8 @@ function core_question_output_fragment_question_data(array $args): string {
|
||||
} else {
|
||||
$thispageurl->param('courseid', $params['courseid']);
|
||||
}
|
||||
if (!empty($args['filterquery'])) {
|
||||
$thispageurl->param('filter', $args['filterquery']);
|
||||
if (!empty($args['filtercondition'])) {
|
||||
$thispageurl->param('filter', $args['filtercondition']);
|
||||
}
|
||||
if (!empty($args['lastchanged'])) {
|
||||
$thispageurl->param('lastchanged', $args['lastchanged']);
|
||||
@@ -150,5 +150,8 @@ function core_question_output_fragment_question_data(array $args): string {
|
||||
}
|
||||
}
|
||||
$questionbank = new $viewclass($contexts, $thispageurl, $course, $cm, $params, $extraparams);
|
||||
return $questionbank->display_questions_table();
|
||||
$questionbank->add_standard_search_conditions();
|
||||
ob_start();
|
||||
$questionbank->display_question_list();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user