AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"preferences_notifications_list_controller.min.js","sources":["../src/preferences_notifications_list_controller.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Controls the preferences for the list of notification types on the\n * message preference page\n *\n * @module core_message/preferences_notifications_list_c
ontroller\n * @copyright 2016 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery',\n 'core/ajax',\n 'core/notification',\n 'core/custom_interaction_events',\n 'core_message/notification_preference',\n 'core_message/notification_processor_settings',\n ],\n function(\n $,\n Ajax,\n Notification,\n CustomEvents,\n NotificationPreference,\n NotificationProcessorSettings,\n ) {\n\n var SELECTORS = {\n DISABLE_NOTIFICATIONS: '[data-region=\"disable-notification-container\"] [data-disable-notifications]',\n DISABLE_NOTIFICATIONS_CONTAINER: '[data-region=\"disable-notification-container\"]',\n PREFERENCE: '.preference-state',\n PREFERENCE_ROW: '[data-region=\"preference-row\"]',\n PREFERENCE_INPUT: '.preference-state input',\n PROCESSOR_SETTING: '[data-processor-setting]',\n };\n\n /*
*\n * Constructor for the PreferencesController.\n *\n * @class\n * @param {object} element jQuery object root element of the preference\n */\n var PreferencesController = function(element) {\n this.root = $(element);\n this.userId = this.root.attr('data-user-id');\n\n this.registerEventListeners();\n };\n\n /**\n * Check if the preferences are all disabled.\n *\n * @method isDisabled\n * @return {bool}\n */\n PreferencesController.prototype.isDisabled = function() {\n return this.root.hasClass('disabled');\n };\n\n /**\n * Disable all of the preferences.\n *\n * @method setDisabled\n */\n PreferencesController.prototype.setDisabled = function() {\n this.root.addClass('disabled');\n this.root.find(SELECTORS.PREFERENCE_INPUT).prop('disabled', true);\n };\n\n /**\n * Enable all of the preferences.\n *\n * @method setEnabled\n */\n PreferencesController.prototype.setEna
bled = function() {\n this.root.removeClass('disabled');\n this.root.find(SELECTORS.PREFERENCE_INPUT).prop('disabled', false);\n };\n\n /**\n * Update the disable all notifications user property in the DOM and\n * send a request to update on the server.\n *\n * @method toggleDisableAllStatus\n * @return {Promise}\n */\n PreferencesController.prototype.toggleDisableAllStatus = function() {\n var checkbox = $(SELECTORS.DISABLE_NOTIFICATIONS);\n var container = $(SELECTORS.DISABLE_NOTIFICATIONS_CONTAINER);\n var ischecked = checkbox.prop('checked');\n\n if (container.hasClass('loading')) {\n return $.Deferred().resolve();\n }\n\n container.addClass('loading');\n\n var request = {\n methodname: 'core_user_update_user_preferences',\n args: {\n userid: this.userId,\n emailstop: ischecked ? 1 : 0,\n }\n };\n\n return Ajax.call([reques
t])[0]\n .done(function() {\n if (ischecked) {\n this.setDisabled();\n } else {\n this.setEnabled();\n }\n }.bind(this))\n .always(function() {\n container.removeClass('loading');\n })\n .fail(Notification.exception);\n };\n\n /**\n * Set up all of the event listeners for the PreferencesController.\n *\n * @method registerEventListeners\n */\n PreferencesController.prototype.registerEventListeners = function() {\n var disabledNotificationsElement = $(SELECTORS.DISABLE_NOTIFICATIONS);\n\n CustomEvents.define(this.root, [\n CustomEvents.events.activate,\n ]);\n\n this.root.on('change', function(e) {\n if (!this.isDisabled()) {\n var preferenceElement = $(e.target).closest(SELECTORS.PREFERENCE);\n var preferenceRow = $(e.target).closest(SELECTORS.PREFERENCE_
ROW);\n var preference = new NotificationPreference(preferenceRow, this.userId);\n\n preferenceElement.addClass('loading');\n preference.save().always(function() {\n preferenceElement.removeClass('loading');\n });\n }\n }.bind(this));\n\n var eventFormPromise = NotificationProcessorSettings.create({});\n\n this.root.on(CustomEvents.events.activate, SELECTORS.PROCESSOR_SETTING, function(e, data) {\n var element = $(e.target).closest(SELECTORS.PROCESSOR_SETTING);\n\n data.originalEvent.preventDefault();\n\n eventFormPromise.then(function(modal) {\n // Configure modal with element settings.\n modal.setUserId($(element).attr('data-user-id'));\n modal.setName($(element).attr('data-name'));\n modal.setContextId($(element).attr('data-context-id'));\n modal.setElement(element);\n modal.
show();\n\n e.stopImmediatePropagation();\n return;\n }).catch(Notification.exception);\n });\n\n CustomEvents.define(disabledNotificationsElement, [\n CustomEvents.events.activate\n ]);\n\n disabledNotificationsElement.on(CustomEvents.events.activate, function() {\n this.toggleDisableAllStatus();\n }.bind(this));\n };\n\n return PreferencesController;\n});\n"],"names":["define","$","Ajax","Notification","CustomEvents","NotificationPreference","NotificationProcessorSettings","SELECTORS","PreferencesController","element","root","userId","this","attr","registerEventListeners","prototype","isDisabled","hasClass","setDisabled","addClass","find","prop","setEnabled","removeClass","toggleDisableAllStatus","checkbox","container","ischecked","Deferred","resolve","request","methodname","args","userid","emailstop","call","done","bind","always","fail","exception","disabledNotificationsElement","events","activate","on"
,"e","preferenceElement","target","closest","preferenceRow","preference","save","eventFormPromise","create","data","originalEvent","preventDefault","then","modal","setUserId","setName","setContextId","setElement","show","stopImmediatePropagation","catch"],"mappings":";;;;;;;;AAuBAA,gEAAO,CAAC,SACA,YACA,oBACA,iCACA,uCACA,iDAEA,SACEC,EACAC,KACAC,aACAC,aACAC,uBACAC,mCAGFC,gCACuB,8EADvBA,0CAEiC,iDAFjCA,qBAGY,oBAHZA,yBAIgB,iCAJhBA,2BAKkB,0BALlBA,4BAMmB,2BASnBC,sBAAwB,SAASC,cAC5BC,KAAOT,EAAEQ,cACTE,OAASC,KAAKF,KAAKG,KAAK,qBAExBC,iCASTN,sBAAsBO,UAAUC,WAAa,kBAClCJ,KAAKF,KAAKO,SAAS,aAQ9BT,sBAAsBO,UAAUG,YAAc,gBACrCR,KAAKS,SAAS,iBACdT,KAAKU,KAAKb,4BAA4B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