1441 |
ariadna |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* This file contains the JS code to support mod_subsection in versions of the app previous to 4.5.
|
|
|
18 |
*
|
|
|
19 |
* @copyright 2024 Dani Palou <dani@moodle.com>
|
|
|
20 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
21 |
*/
|
|
|
22 |
|
|
|
23 |
const context = this;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Open a subsection.
|
|
|
27 |
*/
|
|
|
28 |
const openSubsection = async(module, courseId, siteId) => {
|
|
|
29 |
const customData = context.CoreTextUtilsProvider.parseJSON(module.customdata);
|
|
|
30 |
const pageParams = {
|
|
|
31 |
sectionId: customData.sectionid,
|
|
|
32 |
};
|
|
|
33 |
|
|
|
34 |
if (
|
|
|
35 |
(!siteId || siteId === context.CoreSitesProvider.getCurrentSiteId()) &&
|
|
|
36 |
context.CoreCourseProvider.currentViewIsCourse(courseId)
|
|
|
37 |
) {
|
|
|
38 |
context.CoreCourseProvider.selectCourseTab('', pageParams);
|
|
|
39 |
} else {
|
|
|
40 |
await context.CoreCourseHelperProvider.getAndOpenCourse(courseId, pageParams, siteId);
|
|
|
41 |
}
|
|
|
42 |
};
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Handler to support mod_subsection in a course.
|
|
|
46 |
*/
|
|
|
47 |
class SubsectionModuleHandler {
|
|
|
48 |
|
|
|
49 |
constructor() {
|
|
|
50 |
this.name = 'PluginModSubsection';
|
|
|
51 |
this.modName = 'subsection';
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
isEnabled() {
|
|
|
55 |
return true;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
getData(module) {
|
|
|
59 |
return {
|
|
|
60 |
icon: context.CoreCourseProvider.getModuleIconSrc(module.modname, module.modicon),
|
|
|
61 |
title: module.name,
|
|
|
62 |
action: async(event, module, courseId) => {
|
|
|
63 |
try {
|
|
|
64 |
await openSubsection(module, courseId);
|
|
|
65 |
} catch (error) {
|
|
|
66 |
context.CoreDomUtilsProvider.showErrorModalDefault(error, 'Error opening subsection.');
|
|
|
67 |
}
|
|
|
68 |
},
|
|
|
69 |
};
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Handler to support links to mod_subsection.
|
|
|
75 |
*/
|
|
|
76 |
class SubsectionLinkHandler extends this.CoreContentLinksHandlerBase {
|
|
|
77 |
|
|
|
78 |
constructor() {
|
|
|
79 |
super();
|
|
|
80 |
|
|
|
81 |
this.name = 'PluginModSubsection';
|
|
|
82 |
this.priority = 0;
|
|
|
83 |
this.featureName = 'CoreCourseModuleDelegate_AddonModSubsection';
|
|
|
84 |
this.pattern = new RegExp('/mod/subsection/view.php.*([&?]id=\\d+)');
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
getActions(siteIds, url, params, courseId) {
|
|
|
88 |
return [{
|
|
|
89 |
action: async(siteId) => {
|
|
|
90 |
const modal = await context.CoreDomUtilsProvider.showModalLoading();
|
|
|
91 |
const moduleId = Number(params.id);
|
|
|
92 |
|
|
|
93 |
try {
|
|
|
94 |
// Get the module.
|
|
|
95 |
const module = await context.CoreCourseProvider.getModule(moduleId, courseId, undefined, true, false, siteId);
|
|
|
96 |
|
|
|
97 |
await openSubsection(module, module.course, siteId);
|
|
|
98 |
} catch (error) {
|
|
|
99 |
context.CoreDomUtilsProvider.showErrorModalDefault(error, 'Error opening link.');
|
|
|
100 |
} finally {
|
|
|
101 |
modal.dismiss();
|
|
|
102 |
}
|
|
|
103 |
},
|
|
|
104 |
}];
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
this.CoreCourseModuleDelegate.registerHandler(new SubsectionModuleHandler());
|
|
|
110 |
this.CoreContentLinksDelegate.registerHandler(new SubsectionLinkHandler());
|