MDL-63303 message: fix bugs in message drawer part 4
[moodle.git] / message / amd / src / notification_processor.js
blob9d95c0d112b586ecfe2e76b5f444e4e80b5fcd91
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.
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/>.
16 /**
17  * Represents the notification processor (e.g. email, popup, jabber)
18  *
19  * @module     core_message/notification_processor
20  * @class      notification_processor
21  * @package    message
22  * @copyright  2016 Ryan Wyllie <ryan@moodle.com>
23  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24  */
25 define(['jquery'], function($) {
26     var SELECTORS = {
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"]',
31     };
33     /**
34      * Constructor for the notification processor.
35      *
36      * @param {object} element jQuery object root element of the processor
37      */
38     var NotificationProcessor = function(element) {
39         this.root = $(element);
40     };
42     /**
43      * Get the processor name.
44      *
45      * @method getName
46      * @return {string}
47      */
48     NotificationProcessor.prototype.getName = function() {
49         return this.root.attr('data-processor-name');
50     };
52     /**
53      * Check if the processor is enabled when the user is logged in.
54      *
55      * @method isLoggedInEnabled
56      * @return {bool}
57      */
58     NotificationProcessor.prototype.isLoggedInEnabled = function() {
59         var none = this.root.find(SELECTORS.STATE_NONE).find('input');
61         if (none.prop('checked')) {
62             return false;
63         }
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');
69     };
71     /**
72      * Check if the processor is enabled when the user is logged out.
73      *
74      * @method isLoggedOffEnabled
75      * @return {bool}
76      */
77     NotificationProcessor.prototype.isLoggedOffEnabled = function() {
78         var none = this.root.find(SELECTORS.STATE_NONE).find('input');
80         if (none.prop('checked')) {
81             return false;
82         }
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');
88     };
90     return NotificationProcessor;
91 });