moodle/message/amd/build/notification_preference.min.js.map

1 line
8.8 KiB
Plaintext

{"version":3,"sources":["../src/notification_preference.js"],"names":["define","$","Ajax","Notification","NotificationProcessor","SELECTORS","PROCESSOR","STATE_INPUTS","NotificationPreference","element","userId","root","prototype","getPreferenceKey","attr","getLoggedInPreferenceKey","getLoggedOffPreferenceKey","getProcessors","find","map","index","startLoading","addClass","prop","stopLoading","removeClass","isLoading","hasClass","save","Deferred","resolve","loggedInValue","loggedOffValue","each","processor","isLoggedInEnabled","getName","isLoggedOffEnabled","args","userid","preferences","type","value","call","methodname","fail","exception","always","bind"],"mappings":"AAyBAA,OAAM,wCAAC,CAAC,QAAD,CAAW,WAAX,CAAwB,mBAAxB,CAA6C,qCAA7C,CAAD,CACE,SAASC,CAAT,CAAYC,CAAZ,CAAkBC,CAAlB,CAAgCC,CAAhC,CAAuD,IAEvDC,CAAAA,CAAS,CAAG,CACZC,SAAS,CAAE,uBADC,CAEZC,YAAY,CAAE,oBAFF,CAF2C,CAavDC,CAAsB,CAAG,SAASC,CAAT,CAAkBC,CAAlB,CAA0B,CACnD,KAAKC,IAAL,CAAYV,CAAC,CAACQ,CAAD,CAAb,CACA,KAAKC,MAAL,CAAcA,CACjB,CAhB0D,CAwB3DF,CAAsB,CAACI,SAAvB,CAAiCC,gBAAjC,CAAoD,UAAW,CAC3D,MAAO,MAAKF,IAAL,CAAUG,IAAV,CAAe,qBAAf,CACV,CAFD,CAUAN,CAAsB,CAACI,SAAvB,CAAiCG,wBAAjC,CAA4D,UAAW,CACnE,MAAO,MAAKF,gBAAL,GAA0B,WACpC,CAFD,CAUAL,CAAsB,CAACI,SAAvB,CAAiCI,yBAAjC,CAA6D,UAAW,CACpE,MAAO,MAAKH,gBAAL,GAA0B,YACpC,CAFD,CAUAL,CAAsB,CAACI,SAAvB,CAAiCK,aAAjC,CAAiD,UAAW,CACxD,MAAO,MAAKN,IAAL,CAAUO,IAAV,CAAeb,CAAS,CAACC,SAAzB,EAAoCa,GAApC,CA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AoC,CAChC,GAAuB,EAAnB,GAAAL,CAAJ,CAA2B,CACvBA,CAAc,CAAGE,CAAS,CAACE,OAAV,EACpB,CAFD,IAEO,CACHJ,CAAc,EAAI,IAAME,CAAS,CAACE,OAAV,EAC3B,CACJ,CACJ,CAhBD,EAkBA,GAAsB,EAAlB,GAAAL,CAAJ,CAA0B,CACtBA,CAAa,CAAG,MACnB,CAED,GAAuB,EAAnB,GAAAC,CAAJ,CAA2B,CACvBA,CAAc,CAAG,MACpB,CAlC8C,GAoC3CM,CAAAA,CAAI,CAAG,CACPC,MAAM,CAAE,KAAK7B,MADN,CAEP8B,WAAW,CAAE,CACT,CACIC,IAAI,CAAE,KAAK1B,wBAAL,EADV,CAEI2B,KAAK,CAAEX,CAFX,CADS,CAKT,CACIU,IAAI,CAAE,KAAKzB,yBAAL,EADV,CAEI0B,KAAK,CAAEV,CAFX,CALS,CAFN,CApCoC,CAuD/C,MAAO9B,CAAAA,CAAI,CAACyC,IAAL,CAAU,CALH,CACVC,UAAU,CAAE,mCADF,CAEVN,IAAI,CAAEA,CAFI,CAKG,CAAV,EAAqB,CAArB,EACFO,IADE,CACG1C,CAAY,CAAC2C,SADhB,EAEFC,MAFE,CAEK,UAAW,CACf,KAAKvB,WAAL,EACH,CAFO,CAENwB,IAFM,CAED,IAFC,CAFL,CAKV,CA5DD,CA8DA,MAAOxC,CAAAA,CACV,CAhKK,CAAN","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 preference for an individual notification type on the\n * message preference page.\n *\n * @module core_message/notification_preference\n * @class notification_preference\n * @package message\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', 'core/ajax', 'core/notification', 'core_message/notification_processor'],\n function($, Ajax, Notification, NotificationProcessor) {\n\n var SELECTORS = {\n PROCESSOR: '[data-processor-name]',\n STATE_INPUTS: '[data-state] input',\n };\n\n /**\n * Constructor for the Preference.\n *\n * @param {object} element jQuery object root element of the preference\n * @param {int} userId The current user id\n */\n var NotificationPreference = function(element, userId) {\n this.root = $(element);\n this.userId = userId;\n };\n\n /**\n * Get the unique prefix key that identifies this user preference.\n *\n * @method getPreferenceKey\n * @return {string}\n */\n NotificationPreference.prototype.getPreferenceKey = function() {\n return this.root.attr('data-preference-key');\n };\n\n /**\n * Get the unique key for the logged in preference.\n *\n * @method getLoggedInPreferenceKey\n * @return {string}\n */\n NotificationPreference.prototype.getLoggedInPreferenceKey = function() {\n return this.getPreferenceKey() + '_loggedin';\n };\n\n /**\n * Get the unique key for the logged off preference.\n *\n * @method getLoggedOffPreferenceKey\n * @return {string}\n */\n NotificationPreference.prototype.getLoggedOffPreferenceKey = function() {\n return this.getPreferenceKey() + '_loggedoff';\n };\n\n /**\n * Get the list of Processors available for this preference.\n *\n * @method getProcessors\n * @return {array}\n */\n NotificationPreference.prototype.getProcessors = function() {\n return this.root.find(SELECTORS.PROCESSOR).map(function(index, element) {\n return new NotificationProcessor($(element));\n });\n };\n\n /**\n * Flag the preference as loading.\n *\n * @method startLoading\n */\n NotificationPreference.prototype.startLoading = function() {\n this.root.addClass('loading');\n this.root.find(SELECTORS.STATE_INPUTS).prop('disabled', true);\n };\n\n /**\n * Remove the loading flag for this preference.\n *\n * @method stopLoading\n */\n NotificationPreference.prototype.stopLoading = function() {\n this.root.removeClass('loading');\n this.root.find(SELECTORS.STATE_INPUTS).prop('disabled', false);\n };\n\n /**\n * Check if the preference is loading.\n *\n * @method isLoading\n * @return {Boolean}\n */\n NotificationPreference.prototype.isLoading = function() {\n return this.root.hasClass('loading');\n };\n\n /**\n * Persist the current state of the processors for this preference.\n *\n * @method save\n * @return {object} jQuery promise\n */\n NotificationPreference.prototype.save = function() {\n if (this.isLoading()) {\n return $.Deferred().resolve();\n }\n\n this.startLoading();\n\n var loggedInValue = '';\n var loggedOffValue = '';\n\n this.getProcessors().each(function(index, processor) {\n if (processor.isLoggedInEnabled()) {\n if (loggedInValue === '') {\n loggedInValue = processor.getName();\n } else {\n loggedInValue += ',' + processor.getName();\n }\n }\n\n if (processor.isLoggedOffEnabled()) {\n if (loggedOffValue === '') {\n loggedOffValue = processor.getName();\n } else {\n loggedOffValue += ',' + processor.getName();\n }\n }\n });\n\n if (loggedInValue === '') {\n loggedInValue = 'none';\n }\n\n if (loggedOffValue === '') {\n loggedOffValue = 'none';\n }\n\n var args = {\n userid: this.userId,\n preferences: [\n {\n type: this.getLoggedInPreferenceKey(),\n value: loggedInValue,\n },\n {\n type: this.getLoggedOffPreferenceKey(),\n value: loggedOffValue,\n },\n ],\n };\n\n var request = {\n methodname: 'core_user_update_user_preferences',\n args: args,\n };\n\n return Ajax.call([request])[0]\n .fail(Notification.exception)\n .always(function() {\n this.stopLoading();\n }.bind(this));\n };\n\n return NotificationPreference;\n});\n"],"file":"notification_preference.min.js"}