lib/amd/src/event.js

  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. * Global registry of core events that can be triggered/listened for.
  17. *
  18. * @module core/event
  19. * @copyright 2015 Damyon Wiese <damyon@moodle.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. * @since 3.0
  22. */
  23. import {notifyEditorContentRestored} from 'core_editor/events';
  24. import {notifyFilterContentUpdated} from 'core_filters/events';
  25. import {notifyFormSubmittedByJavascript} from 'core_form/events';
  26. // These are AMD only events - no backwards compatibility for new things.
  27. // Note: No new events should be created here.
  28. const Events = {
  29. FORM_FIELD_VALIDATION: "core_form-field-validation"
  30. };
  31. /**
  32. * Get a curried function to warn that a function has been moved and renamed
  33. *
  34. * @param {String} oldFunctionName
  35. * @param {String} newModule
  36. * @param {String} newFunctionName
  37. * @param {Function} newFunctionRef
  38. * @returns {Function}
  39. */
  40. const getRenamedLegacyFunction = (oldFunctionName, newModule, newFunctionName, newFunctionRef) => (...args) => {
  41. window.console.warn(
  42. `The core/event::${oldFunctionName}() function has been moved to ${newModule}::${newFunctionName}. ` +
  43. `Please update your code to use the new module.`
  44. );
  45. return newFunctionRef(...args);
  46. };
  47. export default {
  48. Events,
  49. notifyEditorContentRestored: getRenamedLegacyFunction(
  50. 'notifyEditorContentRestored',
  51. 'core_editor/events',
  52. 'notifyEditorContentRestored',
  53. notifyEditorContentRestored
  54. ),
  55. notifyFilterContentUpdated: getRenamedLegacyFunction(
  56. 'notifyFilterContentUpdated',
  57. 'core_filters/events',
  58. 'notifyFilterContentUpdated',
  59. notifyFilterContentUpdated
  60. ),
  61. notifyFormSubmitAjax: getRenamedLegacyFunction(
  62. 'notifyFormSubmitAjax',
  63. 'core_form/events',
  64. 'notifyFormSubmittedByJavascript',
  65. notifyFormSubmittedByJavascript
  66. ),
  67. };