mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 23:42:11 +02:00
MDL-81766 core_course: fix modchooser section number
This commit is contained in:
parent
eb4c43b387
commit
a908c0f8af
2
course/amd/build/activitychooser.min.js
vendored
2
course/amd/build/activitychooser.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -52,12 +52,11 @@ let initialized = false;
|
||||
* @method init
|
||||
* @param {Number} courseId Course ID to use later on in fetchModules()
|
||||
* @param {Object} chooserConfig Any PHP config settings that we may need to reference
|
||||
* @param {Number} sectionNum Section number to use later on in fetchModules()
|
||||
*/
|
||||
export const init = (courseId, chooserConfig, sectionNum) => {
|
||||
export const init = (courseId, chooserConfig) => {
|
||||
const pendingPromise = new Pending();
|
||||
|
||||
registerListenerEvents(courseId, chooserConfig, sectionNum);
|
||||
registerListenerEvents(courseId, chooserConfig);
|
||||
|
||||
pendingPromise.resolve();
|
||||
};
|
||||
@ -68,9 +67,8 @@ export const init = (courseId, chooserConfig, sectionNum) => {
|
||||
* @method registerListenerEvents
|
||||
* @param {Number} courseId
|
||||
* @param {Object} chooserConfig Any PHP config settings that we may need to reference
|
||||
* @param {Number} sectionNum Section number to use later on in fetchModules()
|
||||
*/
|
||||
const registerListenerEvents = (courseId, chooserConfig, sectionNum) => {
|
||||
const registerListenerEvents = (courseId, chooserConfig) => {
|
||||
|
||||
// Ensure we only add our listeners once.
|
||||
if (initialized) {
|
||||
@ -84,26 +82,30 @@ const registerListenerEvents = (courseId, chooserConfig, sectionNum) => {
|
||||
];
|
||||
|
||||
const fetchModuleData = (() => {
|
||||
let innerPromise = null;
|
||||
let innerPromises = new Map();
|
||||
|
||||
return () => {
|
||||
if (!innerPromise) {
|
||||
innerPromise = new Promise((resolve) => {
|
||||
resolve(Repository.activityModules(courseId, sectionNum));
|
||||
});
|
||||
return (sectionNum) => {
|
||||
if (innerPromises.has(sectionNum)) {
|
||||
return innerPromises.get(sectionNum);
|
||||
}
|
||||
|
||||
return innerPromise;
|
||||
innerPromises.set(
|
||||
sectionNum,
|
||||
new Promise((resolve) => {
|
||||
resolve(Repository.activityModules(courseId, sectionNum));
|
||||
})
|
||||
);
|
||||
return innerPromises.get(sectionNum);
|
||||
};
|
||||
})();
|
||||
|
||||
const fetchFooterData = (() => {
|
||||
let footerInnerPromise = null;
|
||||
|
||||
return (sectionnum) => {
|
||||
return (sectionNum) => {
|
||||
if (!footerInnerPromise) {
|
||||
footerInnerPromise = new Promise((resolve) => {
|
||||
resolve(Repository.fetchFooterData(courseId, sectionnum));
|
||||
resolve(Repository.fetchFooterData(courseId, sectionNum));
|
||||
});
|
||||
}
|
||||
|
||||
@ -157,7 +159,7 @@ const registerListenerEvents = (courseId, chooserConfig, sectionNum) => {
|
||||
|
||||
// Now we have a modal we should start fetching data.
|
||||
// If an error occurs while fetching the data, display the error within the modal.
|
||||
const data = await fetchModuleData().catch(async(e) => {
|
||||
const data = await fetchModuleData(sectionnum).catch(async(e) => {
|
||||
const errorTemplateData = {
|
||||
'errormessage': e.message
|
||||
};
|
||||
|
@ -141,10 +141,9 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
* Build the HTML for the module chooser javascript popup.
|
||||
*
|
||||
* @param int $courseid The course id to fetch modules for.
|
||||
* @param int|null $sectionnum The section number to fetch modules for.
|
||||
* @return string
|
||||
*/
|
||||
public function course_activitychooser($courseid, ?int $sectionnum = null) {
|
||||
public function course_activitychooser($courseid) {
|
||||
|
||||
if (!$this->page->requires->should_create_one_time_item_now('core_course_modchooser')) {
|
||||
return '';
|
||||
@ -154,7 +153,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$chooserconfig = (object) [
|
||||
'tabmode' => get_config('core', 'activitychoosertabmode'),
|
||||
];
|
||||
$this->page->requires->js_call_amd('core_course/activitychooser', 'init', [$courseid, $chooserconfig, $sectionnum]);
|
||||
$this->page->requires->js_call_amd('core_course/activitychooser', 'init', [$courseid, $chooserconfig]);
|
||||
|
||||
return '';
|
||||
}
|
||||
@ -232,7 +231,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$ajaxcontrol = $this->render_from_template('course/activitychooserbutton', $data);
|
||||
|
||||
// Load the JS for the modal.
|
||||
$this->course_activitychooser($course->id, $section);
|
||||
$this->course_activitychooser($course->id);
|
||||
|
||||
return $ajaxcontrol;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user