message/amd/src/notification_processor.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. * Represents the notification processor (e.g. email, popup, jabber)
  17. *
  18. * @module core_message/notification_processor
  19. * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. define(['jquery'], function($) {
  23. const SELECTORS = {
  24. STATE_INPUTS: '.preference-state input.notification_enabled'
  25. };
  26. /**
  27. * Constructor for the notification processor.
  28. *
  29. * @class
  30. * @param {object} element jQuery object root element of the processor
  31. */
  32. const NotificationProcessor = function(element) {
  33. this.root = $(element);
  34. };
  35. /**
  36. * Get the processor name.
  37. *
  38. * @method getName
  39. * @return {string}
  40. */
  41. NotificationProcessor.prototype.getName = function() {
  42. return this.root.attr('data-processor-name');
  43. };
  44. /**
  45. * Check if the processor is enabled when the user is logged in.
  46. *
  47. * @method isLoggedInEnabled
  48. * @return {bool}
  49. */
  50. NotificationProcessor.prototype.isEnabled = function() {
  51. const enabled = this.root.find(SELECTORS.STATE_INPUTS);
  52. return enabled.prop('checked');
  53. };
  54. return NotificationProcessor;
  55. });