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

1 line
11 KiB
Plaintext

{"version":3,"file":"notification_processor_settings.min.js","sources":["../src/notification_processor_settings.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 * 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 */\n\n\nimport $ from 'jquery';\nimport * as Ajax from 'core/ajax';\nimport * as Str from 'core/str';\nimport * as Notification from 'core/notification';\nimport * as CustomEvents from 'core/custom_interaction_events';\nimport Modal from 'core/modal';\nimport * as Fragment from 'core/fragment';\n\nconst 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\nexport default class NotificationProcessorSettings extends Modal {\n static TYPE = 'core_message-notification_processor_settings';\n static TEMPLATE = 'core/modal_save_cancel';\n\n /**\n * Constructor for the Modal.\n *\n * @class\n * @param {object} root The root jQuery element for the modal.\n */\n constructor(root) {\n super(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 /**\n * Set the userid to the given value.\n *\n * @method setUserId\n * @param {int} id The notification userid\n */\n setUserId(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 getUserId() {\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 setElement(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 getElement() {\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 setName(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 getName() {\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 setContextId(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 getContextId() {\n return this.contextId;\n }\n\n /**\n * Get the form element from the modal.\n *\n * @method getForm\n * @return {object}\n */\n getForm() {\n return this.getBody().find('form');\n }\n\n /**\n * Disable the buttons in the footer.\n *\n * @method disableButtons\n */\n disableButtons() {\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 enableButtons() {\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 loadTitleContent() {\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 loadBodyContent() {\n this.disableButtons();\n\n const 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(() => {\n this.enableButtons();\n return;\n })\n .catch(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 loadAllContent() {\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 show() {\n this.loadAllContent();\n super.show(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 hide() {\n super.hide(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 updateConfiguredStatus() {\n const processorHeader = $(this.getElement()).closest(SELECTORS.PROCESSOR);\n\n if (!processorHeader.hasClass('unconfigured')) {\n return false;\n }\n\n const processorName = processorHeader.attr('data-processor-name');\n const 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 .then((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 const notifications = $(SELECTORS.PREFERENCE_ROW + ' [data-processor-name=\"' + processorName + '\"]');\n processorHeader.removeClass('unconfigured');\n notifications.removeClass('disabled');\n }\n return result;\n });\n }\n\n /**\n * Set up all of the event handling for the modal.\n *\n * @method registerEventListeners\n */\n registerEventListeners() {\n // Apply parent event listeners.\n super.registerEventListeners(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, (e, data) => {\n this.getForm().submit();\n data.originalEvent.preventDefault();\n });\n\n this.getModal().on('mpp:formsubmitted', (e) => {\n this.hide();\n this.updateConfiguredStatus();\n e.stopPropagation();\n });\n\n this.getModal().on(CustomEvents.events.activate, SELECTORS.CANCEL_BUTTON, (e, data) => {\n this.hide();\n data.originalEvent.preventDefault();\n e.stopPropagation();\n });\n }\n}\n\nNotificationProcessorSettings.registerModalType();\n"],"names":["SELECTORS","NotificationProcessorSettings","Modal","constructor","root","name","userId","contextId","element","saveButton","this","getFooter","find","cancelButton","setUserId","id","getUserId","setElement","getElement","setName","getName","setContextId","getContextId","getForm","getBody","disableButtons","prop","enableButtons","loadTitleContent","titlePromise","Str","get_string","setTitle","loadBodyContent","args","userid","type","bodyPromise","Fragment","loadFragment","setBody","then","catch","Notification","exception","loadAllContent","$","when","show","hide","updateConfiguredStatus","processorHeader","closest","hasClass","processorName","attr","request","methodname","Ajax","call","result","userconfigured","notifications","removeClass","registerEventListeners","getModal","on","CustomEvents","events","activate","e","data","submit","originalEvent","preventDefault","stopPropagation","registerModalType"],"mappings":"yyDAgCMA,sBACW,uBADXA,wBAEa,yBAFbA,oBAGS,wBAHTA,yBAIc,uCAGCC,sCAAsCC,eAUvDC,YAAYC,YACFA,WACDC,KAAO,UACPC,OAAS,UACTC,UAAY,UACZC,QAAU,UACVC,WAAaC,KAAKC,YAAYC,KAAKZ,4BACnCa,aAAeH,KAAKC,YAAYC,KAAKZ,yBAS9Cc,UAAUC,SACDT,OAASS,GASlBC,mBACWN,KAAKJ,OAShBW,WAAWT,cACFA,QAAUA,QASnBU,oBACWR,KAAKF,QAShBW,QAAQd,WACCA,KAAOA,KAShBe,iBACWV,KAAKL,KAQhBgB,aAAaN,SACJR,UAAYQ,GASrBO,sBACWZ,KAAKH,UAShBgB,iBACWb,KAAKc,UAAUZ,KAAK,QAQ/Ba,sBACShB,WAAWiB,KAAK,YAAY,QAC5Bb,aAAaa,KAAK,YAAY,GAQvCC,qBACSlB,WAAWiB,KAAK,YAAY,QAC5Bb,aAAaa,KAAK,YAAY,GAUvCE,+BACSC,aAAeC,IAAIC,WAAW,oBAAqB,gBACnDC,SAASt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