| 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 AMD only events - no backwards compatibility for new things.
 | 
        
           |  |  | 30 | // Note: No new events should be created here.
 | 
        
           |  |  | 31 | const Events = {
 | 
        
           |  |  | 32 |     FORM_FIELD_VALIDATION: "core_form-field-validation"
 | 
        
           |  |  | 33 | };
 | 
        
           |  |  | 34 |   | 
        
           |  |  | 35 | /**
 | 
        
           |  |  | 36 |  * Get a curried function to warn that a function has been moved and renamed
 | 
        
           |  |  | 37 |  *
 | 
        
           |  |  | 38 |  * @param   {String} oldFunctionName
 | 
        
           |  |  | 39 |  * @param   {String} newModule
 | 
        
           |  |  | 40 |  * @param   {String} newFunctionName
 | 
        
           |  |  | 41 |  * @param   {Function} newFunctionRef
 | 
        
           |  |  | 42 |  * @returns {Function}
 | 
        
           |  |  | 43 |  */
 | 
        
           |  |  | 44 | const getRenamedLegacyFunction = (oldFunctionName, newModule, newFunctionName, newFunctionRef) => (...args) => {
 | 
        
           |  |  | 45 |     window.console.warn(
 | 
        
           |  |  | 46 |         `The core/event::${oldFunctionName}() function has been moved to ${newModule}::${newFunctionName}. ` +
 | 
        
           |  |  | 47 |         `Please update your code to use the new module.`
 | 
        
           |  |  | 48 |     );
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 |     return newFunctionRef(...args);
 | 
        
           |  |  | 51 | };
 | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 | export default {
 | 
        
           |  |  | 54 |     Events,
 | 
        
           |  |  | 55 |     notifyEditorContentRestored: getRenamedLegacyFunction(
 | 
        
           |  |  | 56 |         'notifyEditorContentRestored',
 | 
        
           |  |  | 57 |         'core_editor/events',
 | 
        
           |  |  | 58 |         'notifyEditorContentRestored',
 | 
        
           |  |  | 59 |         notifyEditorContentRestored
 | 
        
           |  |  | 60 |     ),
 | 
        
           |  |  | 61 |   | 
        
           |  |  | 62 |     notifyFilterContentUpdated: getRenamedLegacyFunction(
 | 
        
           |  |  | 63 |         'notifyFilterContentUpdated',
 | 
        
           |  |  | 64 |         'core_filters/events',
 | 
        
           |  |  | 65 |         'notifyFilterContentUpdated',
 | 
        
           |  |  | 66 |         notifyFilterContentUpdated
 | 
        
           |  |  | 67 |     ),
 | 
        
           |  |  | 68 |   | 
        
           |  |  | 69 |     notifyFormSubmitAjax: getRenamedLegacyFunction(
 | 
        
           |  |  | 70 |         'notifyFormSubmitAjax',
 | 
        
           |  |  | 71 |         'core_form/events',
 | 
        
           |  |  | 72 |         'notifyFormSubmittedByJavascript',
 | 
        
           |  |  | 73 |         notifyFormSubmittedByJavascript
 | 
        
           |  |  | 74 |     ),
 | 
        
           |  |  | 75 | };
 |