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 |
* Global registry of core events that can be triggered/listened for.
|
|
|
18 |
*
|
|
|
19 |
* @module core/event
|
|
|
20 |
* @copyright 2015 Damyon Wiese <damyon@moodle.com>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
* @since 3.0
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
import {notifyEditorContentRestored} from 'core_editor/events';
|
|
|
26 |
import {notifyFilterContentUpdated} from 'core_filters/events';
|
|
|
27 |
import {notifyFormSubmittedByJavascript} from 'core_form/events';
|
|
|
28 |
|
|
|
29 |
// These are only imported for legacy.
|
|
|
30 |
import $ from 'jquery';
|
|
|
31 |
import Y from 'core/yui';
|
|
|
32 |
|
|
|
33 |
// These are AMD only events - no backwards compatibility for new things.
|
|
|
34 |
// Note: No new events should be created here.
|
|
|
35 |
const Events = {
|
|
|
36 |
FORM_FIELD_VALIDATION: "core_form-field-validation"
|
|
|
37 |
};
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Load the legacy YUI module which defines events in M.core.event and return it.
|
|
|
41 |
*
|
|
|
42 |
* @method getLegacyEvents
|
|
|
43 |
* @return {Promise}
|
|
|
44 |
* @deprecated
|
|
|
45 |
*/
|
|
|
46 |
const getLegacyEvents = () => {
|
|
|
47 |
const result = $.Deferred();
|
|
|
48 |
window.console.warn("The getLegacyEvents function has been deprecated. Please update your code to use native events.");
|
|
|
49 |
|
|
|
50 |
Y.use('event', 'moodle-core-event', function() {
|
|
|
51 |
result.resolve(window.M.core.event);
|
|
|
52 |
});
|
|
|
53 |
return result.promise();
|
|
|
54 |
};
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Get a curried function to warn that a function has been moved and renamed
|
|
|
58 |
*
|
|
|
59 |
* @param {String} oldFunctionName
|
|
|
60 |
* @param {String} newModule
|
|
|
61 |
* @param {String} newFunctionName
|
|
|
62 |
* @param {Function} newFunctionRef
|
|
|
63 |
* @returns {Function}
|
|
|
64 |
*/
|
|
|
65 |
const getRenamedLegacyFunction = (oldFunctionName, newModule, newFunctionName, newFunctionRef) => (...args) => {
|
|
|
66 |
window.console.warn(
|
|
|
67 |
`The core/event::${oldFunctionName}() function has been moved to ${newModule}::${newFunctionName}. ` +
|
|
|
68 |
`Please update your code to use the new module.`
|
|
|
69 |
);
|
|
|
70 |
|
|
|
71 |
return newFunctionRef(...args);
|
|
|
72 |
};
|
|
|
73 |
|
|
|
74 |
export default {
|
|
|
75 |
Events,
|
|
|
76 |
getLegacyEvents,
|
|
|
77 |
|
|
|
78 |
notifyEditorContentRestored: getRenamedLegacyFunction(
|
|
|
79 |
'notifyEditorContentRestored',
|
|
|
80 |
'core_editor/events',
|
|
|
81 |
'notifyEditorContentRestored',
|
|
|
82 |
notifyEditorContentRestored
|
|
|
83 |
),
|
|
|
84 |
|
|
|
85 |
notifyFilterContentUpdated: getRenamedLegacyFunction(
|
|
|
86 |
'notifyFilterContentUpdated',
|
|
|
87 |
'core_filters/events',
|
|
|
88 |
'notifyFilterContentUpdated',
|
|
|
89 |
notifyFilterContentUpdated
|
|
|
90 |
),
|
|
|
91 |
|
|
|
92 |
notifyFormSubmitAjax: getRenamedLegacyFunction(
|
|
|
93 |
'notifyFormSubmitAjax',
|
|
|
94 |
'core_form/events',
|
|
|
95 |
'notifyFormSubmittedByJavascript',
|
|
|
96 |
notifyFormSubmittedByJavascript
|
|
|
97 |
),
|
|
|
98 |
};
|