1 |
efrain |
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 |
* MoodleNet mutations.
|
|
|
18 |
* An instance of this class will be used to add custom mutations to the course editor.
|
|
|
19 |
*
|
|
|
20 |
* @module core/moodlenet/mutations
|
|
|
21 |
* @copyright 2023 Huong Nguyen <huongnv13@gmail.com>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
* @since 4.3
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
import DefaultMutations from 'core_courseformat/local/courseeditor/mutations';
|
|
|
27 |
import {getCurrentCourseEditor} from 'core_courseformat/courseeditor';
|
|
|
28 |
import CourseActions from 'core_courseformat/local/content/actions';
|
|
|
29 |
import {subscribe} from 'core/pubsub';
|
|
|
30 |
import {handleModal} from 'core/moodlenet/send_resource';
|
|
|
31 |
import MoodleNetEvents from 'core/moodlenet/events';
|
|
|
32 |
|
|
|
33 |
class MoodleNetMutations extends DefaultMutations {
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Share to MoodleNet.
|
|
|
37 |
*
|
|
|
38 |
* @param {StateManager} stateManager the current state manager
|
|
|
39 |
* @param {array} cmIds Course module ids.
|
|
|
40 |
*/
|
|
|
41 |
shareToMoodleNet = async function(stateManager, cmIds) {
|
|
|
42 |
if (cmIds.length == 0) {
|
|
|
43 |
return;
|
|
|
44 |
}
|
|
|
45 |
this.cmLock(stateManager, cmIds, true);
|
|
|
46 |
handleModal('partial', cmIds);
|
|
|
47 |
this.cmLock(stateManager, cmIds, false);
|
|
|
48 |
subscribe(MoodleNetEvents.MOODLENET_SHARE_STARTED, () => {
|
|
|
49 |
// Only clear the selection if the user starts the sharing.
|
|
|
50 |
this.bulkReset(stateManager);
|
|
|
51 |
});
|
|
|
52 |
};
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* Initialize.
|
|
|
57 |
*/
|
|
|
58 |
export const init = () => {
|
|
|
59 |
const courseEditor = getCurrentCourseEditor();
|
|
|
60 |
courseEditor.addMutations(new MoodleNetMutations());
|
|
|
61 |
// Add direct mutation content actions.
|
|
|
62 |
CourseActions.addActions({
|
|
|
63 |
cmShareToMoodleNet: 'shareToMoodleNet'
|
|
|
64 |
});
|
|
|
65 |
};
|