1{"version":3,"sources":["../src/notification_processor_settings.js"],"names":["define","$","Ajax","Str","Notification","CustomEvents","Modal","ModalRegistry","Fragment","registered","SELECTORS","SAVE_BUTTON","CANCEL_BUTTON","PROCESSOR","PREFERENCE_ROW","NotificationProcessorSettings","root","call","name","userId","contextId","element","saveButton","getFooter","find","cancelButton","TYPE","prototype","Object","create","constructor","setUserId","id","getUserId","setElement","getElement","setName","getName","setContextId","getContextId","getForm","getBody","disableButtons","prop","enableButtons","loadTitleContent","titlePromise","get_string","setTitle","loadBodyContent","args","userid","type","bodyPromise","loadFragment","setBody","then","bind","fail","exception","loadAllContent","when","show","hide","updateConfiguredStatus","processorHeader","closest","hasClass","processorName","attr","request","methodname","done","result","userconfigured","notifications","removeClass","registerEventListeners","getModal","on","events","activate","e","data","submit","originalEvent","preventDefault","stopPropagation","register"],"mappings":"AAsBAA,OAAM,gDAAC,CACC,QADD,CAEC,WAFD,CAGC,UAHD,CAIC,mBAJD,CAKC,gCALD,CAMC,YAND,CAOC,qBAPD,CAQC,eARD,CAAD,CAUE,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAMIC,CANJ,CAOIC,CAPJ,CAQIC,CARJ,CASE,IAEFC,CAAAA,CAAU,GAFR,CAGFC,CAAS,CAAG,CACZC,WAAW,CAAE,wBADD,CAEZC,aAAa,CAAE,0BAFH,CAGZC,SAAS,CAAE,uBAHC,CAIZC,cAAc,CAAE,kCAJJ,CAHV,CAgBFC,CAA6B,CAAG,SAASC,CAAT,CAAe,CAC/CV,CAAK,CAACW,IAAN,CAAW,IAAX,CAAiBD,CAAjB,EACA,KAAKE,IAAL,CAAY,IAAZ,CACA,KAAKC,MAAL,CAAc,IAAd,CACA,KAAKC,SAAL,CAAiB,IAAjB,CACA,KAAKC,OAAL,CAAe,IAAf,CACA,KAAKC,UAAL,CAAkB,KAAKC,SAAL,GAAiBC,IAAjB,CAAsBd,CAAS,CAACC,WAAhC,CAAlB,C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A5B,EACAD,CAAa,CAACC,WAAd,CAA0B,UAA1B,CACH,CACJ,CAVE,CAWV,CA3BD,CAkCA7D,CAA6B,CAACY,SAA9B,CAAwCkD,sBAAxC,CAAiE,UAAW,CAExEvE,CAAK,CAACqB,SAAN,CAAgBkD,sBAAhB,CAAuC5D,IAAvC,CAA4C,IAA5C,EAGA,KAAK6D,QAAL,GAAgBC,EAAhB,CAAmB1E,CAAY,CAAC2E,MAAb,CAAoBC,QAAvC,CAAiDvE,CAAS,CAACC,WAA3D,CAAwE,SAASuE,CAAT,CAAYC,CAAZ,CAAkB,CACtF,KAAK3C,OAAL,GAAe4C,MAAf,GACAD,CAAI,CAACE,aAAL,CAAmBC,cAAnB,EACH,CAHuE,CAGtE7B,IAHsE,CAGjE,IAHiE,CAAxE,EAKA,KAAKqB,QAAL,GAAgBC,EAAhB,CAAmB,mBAAnB,CAAwC,SAASG,CAAT,CAAY,CAChD,KAAKnB,IAAL,GACA,KAAKC,sBAAL,GACAkB,CAAC,CAACK,eAAF,EACH,CAJuC,CAItC9B,IAJsC,CAIjC,IAJiC,CAAxC,EAMA,KAAKqB,QAAL,GAAgBC,EAAhB,CAAmB1E,CAAY,CAAC2E,MAAb,CAAoBC,QAAvC,CAAiDvE,CAAS,CAACE,aAA3D,CAA0E,SAASsE,CAAT,CAAYC,CAAZ,CAAkB,CACxF,KAAKpB,IAAL,GACAoB,CAAI,CAACE,aAAL,CAAmBC,cAAnB,GACAJ,CAAC,CAACK,eAAF,EACH,CAJyE,CAIxE9B,IAJwE,CAInE,IAJmE,CAA1E,CAKH,CArBD,CA0BA,GAAI,CAAChD,CAAL,CAAiB,CACbF,CAAa,CAACiF,QAAd,CACwBzE,CAA6B,CAACW,IADtD,CAEwBX,CAFxB,CAGwB,wBAHxB,EAIAN,CAAU,GACb,CAED,MAAOM,CAAAA,CACV,CAtTK,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 * Load the settings for a message processor.\n *\n * @module core_message/notification_processor_settings\n * @copyright 2016 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([\n 'jquery',\n 'core/ajax',\n 'core/str',\n 'core/notification',\n 'core/custom_interaction_events',\n 'core/modal',\n 'core/modal_registry',\n 'core/fragment',\n ],\n function(\n $,\n Ajax,\n Str,\n Notification,\n CustomEvents,\n Modal,\n ModalRegistry,\n Fragment\n ) {\n\n var registered = false;\n var SELECTORS = {\n SAVE_BUTTON: '[data-action=\"save\"]',\n CANCEL_BUTTON: '[data-action=\"cancel\"]',\n PROCESSOR: '[data-processor-name]',\n PREFERENCE_ROW: '[data-region=\"preference-row\"]',\n };\n\n /**\n * Constructor for the Modal.\n *\n * @class\n * @param {object} root The root jQuery element for the modal.\n */\n var NotificationProcessorSettings = function(root) {\n Modal.call(this, root);\n this.name = null;\n this.userId = null;\n this.contextId = null;\n this.element = null;\n this.saveButton = this.getFooter().find(SELECTORS.SAVE_BUTTON);\n this.cancelButton = this.getFooter().find(SELECTORS.CANCEL_BUTTON);\n };\n\n NotificationProcessorSettings.TYPE = 'core_message-notification_processor_settings';\n NotificationProcessorSettings.prototype = Object.create(Modal.prototype);\n NotificationProcessorSettings.prototype.constructor = NotificationProcessorSettings;\n\n /**\n * Set the userid to the given value.\n *\n * @method setUserId\n * @param {int} id The notification userid\n */\n NotificationProcessorSettings.prototype.setUserId = function(id) {\n this.userId = id;\n };\n\n /**\n * Retrieve the current userid, if any.\n *\n * @method getUserId\n * @return {int|null} The notification userid\n */\n NotificationProcessorSettings.prototype.getUserId = function() {\n return this.userId;\n };\n\n /**\n * Set the object to the given value.\n *\n * @method setElement\n * @param {object} element The notification node element.\n */\n NotificationProcessorSettings.prototype.setElement = function(element) {\n this.element = element;\n };\n\n /**\n * Retrieve the current element, if any.\n *\n * @method getElement\n * @return {object|null} The notification node element.\n */\n NotificationProcessorSettings.prototype.getElement = function() {\n return this.element;\n };\n\n /**\n * Set the name to the given value.\n *\n * @method setName\n * @param {string} name The notification name.\n */\n NotificationProcessorSettings.prototype.setName = function(name) {\n this.name = name;\n };\n\n /**\n * Retrieve the current name, if any.\n *\n * @method getName\n * @return {string|null} The notification name.\n */\n NotificationProcessorSettings.prototype.getName = function() {\n return this.name;\n };\n /**\n * Set the context id to the given value.\n *\n * @method setContextId\n * @param {Number} id The notification context id\n */\n NotificationProcessorSettings.prototype.setContextId = function(id) {\n this.contextId = id;\n };\n\n /**\n * Retrieve the current context id, if any.\n *\n * @method getContextId\n * @return {Number|null} The notification context id\n */\n NotificationProcessorSettings.prototype.getContextId = function() {\n return this.contextId;\n };\n\n /**\n * Get the form element from the modal.\n *\n * @method getForm\n * @return {object}\n */\n NotificationProcessorSettings.prototype.getForm = function() {\n return this.getBody().find('form');\n };\n\n /**\n * Disable the buttons in the footer.\n *\n * @method disableButtons\n */\n NotificationProcessorSettings.prototype.disableButtons = function() {\n this.saveButton.prop('disabled', true);\n this.cancelButton.prop('disabled', true);\n };\n\n /**\n * Enable the buttons in the footer.\n *\n * @method enableButtons\n */\n NotificationProcessorSettings.prototype.enableButtons = function() {\n this.saveButton.prop('disabled', false);\n this.cancelButton.prop('disabled', false);\n };\n\n /**\n * Load the title for the modal to the appropriate value\n * depending on message outputs.\n *\n * @method loadTitleContent\n * @return {object} A promise resolved with the new title text.\n */\n NotificationProcessorSettings.prototype.loadTitleContent = function() {\n this.titlePromise = Str.get_string('processorsettings', 'message');\n this.setTitle(this.titlePromise);\n\n return this.titlePromise;\n };\n\n /**\n * Load the body for the modal to the appropriate value\n * depending on message outputs.\n *\n * @method loadBodyContent\n * @return {object} A promise resolved with the fragment html and js from\n */\n NotificationProcessorSettings.prototype.loadBodyContent = function() {\n this.disableButtons();\n\n var args = {\n userid: this.getUserId(),\n type: this.getName(),\n };\n\n this.bodyPromise = Fragment.loadFragment('message', 'processor_settings', this.getContextId(), args);\n this.setBody(this.bodyPromise);\n\n this.bodyPromise.then(function() {\n this.enableButtons();\n return;\n }.bind(this))\n .fail(Notification.exception);\n\n return this.bodyPromise;\n };\n\n /**\n * Load both the title and body content.\n *\n * @method loadAllContent\n * @return {object} promise\n */\n NotificationProcessorSettings.prototype.loadAllContent = function() {\n return $.when(this.loadTitleContent(), this.loadBodyContent());\n };\n\n /**\n * Load the modal content before showing it. This\n * is to allow us to re-use the same modal for creating and\n * editing different message outputs within the page.\n *\n * @method show\n */\n NotificationProcessorSettings.prototype.show = function() {\n this.loadAllContent();\n Modal.prototype.show.call(this);\n };\n\n /**\n * Clear the notification from the modal when it's closed so\n * that it is loaded fresh next time it's displayed.\n *\n * @method hide\n */\n NotificationProcessorSettings.prototype.hide = function() {\n Modal.prototype.hide.call(this);\n this.setContextId(null);\n this.setName(null);\n this.setUserId(null);\n };\n\n /**\n * Checks if the processor has been configured. If so then remove the unconfigured\n * status from the interface.\n *\n * @method updateConfiguredStatus\n * @return {Promise|boolean}\n */\n NotificationProcessorSettings.prototype.updateConfiguredStatus = function() {\n var processorHeader = $(this.getElement()).closest(SELECTORS.PROCESSOR);\n\n if (!processorHeader.hasClass('unconfigured')) {\n return false;\n }\n\n var processorName = processorHeader.attr('data-processor-name');\n var request = {\n methodname: 'core_message_get_message_processor',\n args: {\n name: processorName,\n userid: this.userId,\n },\n };\n\n return Ajax.call([request])[0]\n .fail(Notification.exception)\n .done(function(result) {\n // Check if the user has figured configuring the processor.\n if (result.userconfigured) {\n // If they have then we can enable the settings.\n var notifications = $(SELECTORS.PREFERENCE_ROW + ' [data-processor-name=\"' + processorName + '\"]');\n processorHeader.removeClass('unconfigured');\n notifications.removeClass('disabled');\n }\n });\n };\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n NotificationProcessorSettings.prototype.registerEventListeners = function() {\n // Apply parent event listeners.\n Modal.prototype.registerEventListeners.call(this);\n\n // When the user clicks the save button we trigger the form submission.\n this.getModal().on(CustomEvents.events.activate, SELECTORS.SAVE_BUTTON, function(e, data) {\n this.getForm().submit();\n data.originalEvent.preventDefault();\n }.bind(this));\n\n this.getModal().on('mpp:formsubmitted', function(e) {\n this.hide();\n this.updateConfiguredStatus();\n e.stopPropagation();\n }.bind(this));\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, function(e, data) {\n this.hide();\n data.originalEvent.preventDefault();\n e.stopPropagation();\n }.bind(this));\n };\n\n // Automatically register with the modal registry the first time this module is imported\n // so that you can create modals\n // of this type using the modal factory.\n if (!registered) {\n ModalRegistry.register(\n NotificationProcessorSettings.TYPE,\n NotificationProcessorSettings,\n 'core/modal_save_cancel');\n registered = true;\n }\n\n return NotificationProcessorSettings;\n});\n"],"file":"notification_processor_settings.min.js"}