1 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 * Represents the notification processor (e.g. email, popup, jabber)
19 * @module core_message/notification_processor
20 * @class notification_processor
22 * @copyright 2016 Ryan Wyllie <ryan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 define(['jquery'], function($) {
27 STATE_NONE: '[data-state="none"]',
28 STATE_BOTH: '[data-state="both"]',
29 STATE_LOGGED_IN: '[data-state="loggedin"]',
30 STATE_LOGGED_OFF: '[data-state="loggedoff"]',
34 * Constructor for the notification processor.
36 * @param {object} element jQuery object root element of the processor
38 var NotificationProcessor = function(element) {
39 this.root = $(element);
43 * Get the processor name.
48 NotificationProcessor.prototype.getName = function() {
49 return this.root.attr('data-processor-name');
53 * Check if the processor is enabled when the user is logged in.
55 * @method isLoggedInEnabled
58 NotificationProcessor.prototype.isLoggedInEnabled = function() {
59 var none = this.root.find(SELECTORS.STATE_NONE).find('input');
61 if (none.prop('checked')) {
65 var both = this.root.find(SELECTORS.STATE_BOTH).find('input');
66 var loggedIn = this.root.find(SELECTORS.STATE_LOGGED_IN).find('input');
68 return loggedIn.prop('checked') || both.prop('checked');
72 * Check if the processor is enabled when the user is logged out.
74 * @method isLoggedOffEnabled
77 NotificationProcessor.prototype.isLoggedOffEnabled = function() {
78 var none = this.root.find(SELECTORS.STATE_NONE).find('input');
80 if (none.prop('checked')) {
84 var both = this.root.find(SELECTORS.STATE_BOTH).find('input');
85 var loggedOff = this.root.find(SELECTORS.STATE_LOGGED_OFF).find('input');
87 return loggedOff.prop('checked') || both.prop('checked');
90 return NotificationProcessor;