AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"notification_preference.min.js","sources":["../src/notification_preference.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 preference for an individual notification type on the\n * message preference page.\n *\n * @module core_message/notification_preference\n * @copyright 2016 Ryan Wyllie <ryan@mood
le.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 const SELECTORS = {\n PROCESSOR: '[data-processor-name]',\n STATE_INPUTS: '[data-state] input',\n };\n\n /**\n * Constructor for the Preference.\n *\n * @class\n * @param {object} element jQuery object root element of the preference\n * @param {int} userId The current user id\n */\n const 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 enabled preference.\n *\n * @method getEnabledPreferenceKey\n * @return {string}\n */\n NotificationPreference.prototype.getEnabledPreferenceKey = function() {\n return this.getPreferenceKey() + '_enabled';\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 stopL
oading\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 let enabledValue = '';\n\n this.getProcessors().each(function(index, processor) {\n if (processor.isEnabled()) {\n if (enabledValue === '') {\n enabledValue = processor.getN
ame();\n } else {\n enabledValue += ',' + processor.getName();\n }\n }\n });\n\n if (enabledValue === '') {\n enabledValue = 'none';\n }\n\n const args = {\n userid: this.userId,\n preferences: [\n {\n type: this.getEnabledPreferenceKey(),\n value: enabledValue,\n }\n ],\n };\n\n const 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"],"names":["define","$","Ajax","Notification","NotificationProcessor","SELECTORS","NotificationPreference","element","userId","root","prototype","getPreferenceKey","this","at
tr","getEnabledPreferenceKey","getProcessors","find","map","index","startLoading","addClass","prop","stopLoading","removeClass","isLoading","hasClass","save","Deferred","resolve","enabledValue","each","processor","isEnabled","getName","request","methodname","args","userid","preferences","type","value","call","fail","exception","always","bind"],"mappings":";;;;;;;;AAuBAA,8CAAO,CAAC,SAAU,YAAa,oBAAqB,wCAC5C,SAASC,EAAGC,KAAMC,aAAcC,6BAE9BC,oBACS,wBADTA,uBAEY,qBAUZC,uBAAyB,SAASC,QAASC,aACxCC,KAAOR,EAAEM,cACTC,OAASA,eASlBF,uBAAuBI,UAAUC,iBAAmB,kBACzCC,KAAKH,KAAKI,KAAK,wBAS1BP,uBAAuBI,UAAUI,wBAA0B,kBAChDF,KAAKD,mBAAqB,YASrCL,uBAAuBI,UAAUK,cAAgB,kBACtCH,KAAKH,KAAKO,KAAKX,qBAAqBY,KAAI,SAASC,MAAOX,gBACpD,IAAIH,sBAAsBH,EAAEM,cAS3CD,uBAAuBI,UAAUS,aAAe,gBACvCV,KAAKW,SAAS,gBACdX,KAAKO,KAAKX,wBAAwBgB,KAAK,YAAY,IAQ5Df,uBAAuBI,UAAUY,YAAc,gBACtCb,KAAKc,YAAY,gBACjBd,KAAKO,KAAKX,wBAAwBgB,KAAK,YAAY,IAS5Df,uBAAuBI,UAAUc,UAAY,kBAClCZ,KAAKH,KAAKgB,SAAS,YAS9BnB,uBAAuBI,UAAUgB,KAAO,cAChCd,KAAKY,mBACEvB,EAAE0B,WAAWC,eAGnBT,mBAEDU,aAAe
,QAEdd,gBAAgBe,MAAK,SAASZ,MAAOa,WAClCA,UAAUC,cACW,KAAjBH,aACAA,aAAeE,UAAUE,UAEzBJ,cAAgB,IAAME,UAAUE,cAKvB,KAAjBJ,eACAA,aAAe,cAabK,QAAU,CACZC,WAAY,oCACZC,KAZS,CACTC,OAAQzB,KAAKJ,OACb8B,YAAa,CACT,CACIC,KAAM3B,KAAKE,0BACX0B,MAAOX,wBAUZ3B,KAAKuC,KAAK,CAACP,UAAU,GACvBQ,KAAKvC,aAAawC,WAClBC,OAAO,gBACCtB,eACPuB,KAAKjC,QAGRN"}