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 * Load the settings for a message processor.
19 * @module core_message/notification_processor_settings
20 * @class notification_processor_settings
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', 'core/ajax', 'core/notification', 'core/fragment', 'core/templates', 'core/str', 'tool_lp/dialogue'],
26 function($, Ajax, Notification, Fragment, Templates, Str, Dialogue) {
29 PROCESSOR: '[data-processor-name]',
30 PREFERENCE_ROW: '[data-region="preference-row"]',
34 * Constructor for the notification processor settings.
36 * @param {object} element jQuery object root element of the processor
38 var NotificationProcessorSettings = function(element) {
39 this.root = $(element);
40 this.name = this.root.attr('data-name');
41 this.userId = this.root.attr('data-user-id');
42 this.contextId = this.root.attr('data-context-id');
46 * Show the notification processor settings dialogue.
50 NotificationProcessorSettings.prototype.show = function() {
51 Fragment.loadFragment('message', 'processor_settings', this.contextId, {
55 .done(function(html, js) {
56 Str.get_string('processorsettings', 'message').done(function(string) {
57 var dialogue = new Dialogue(
61 Templates.runTemplateJS(js);
64 // Removed dialogue from the DOM after close.
69 $(document).on('mpp:formsubmitted', function() {
71 this.updateConfiguredStatus();
74 $(document).on('mpp:formcancelled', function() {
82 * Checks if the processor has been configured. If so then remove the unconfigured
83 * status from the interface.
85 * @method updateConfiguredStatus
86 * @return {Promise|boolean}
88 NotificationProcessorSettings.prototype.updateConfiguredStatus = function() {
89 var processorHeader = this.root.closest(SELECTORS.PROCESSOR);
91 if (!processorHeader.hasClass('unconfigured')) {
95 var processorName = processorHeader.attr('data-processor-name');
97 methodname: 'core_message_get_message_processor',
104 return Ajax.call([request])[0]
105 .fail(Notification.exception)
106 .done(function(result) {
107 // Check if the user has figured configuring the processor.
108 if (result.userconfigured) {
109 // If they have then we can enable the settings.
110 var notifications = $(SELECTORS.PREFERENCE_ROW + ' [data-processor-name="' + processorName + '"]');
111 processorHeader.removeClass('unconfigured');
112 notifications.removeClass('disabled');
117 return NotificationProcessorSettings;