From 53ba66f180702cb17a06563e7673c688a493e334 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 14 Mar 2025 14:33:36 +0800 Subject: [PATCH] MDL-84877 core_message: Notification preferences should use a Toast --- .../build/default_notification_preferences.min.js | 4 ++-- .../default_notification_preferences.min.js.map | 2 +- message/amd/src/default_notification_preferences.js | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/message/amd/build/default_notification_preferences.min.js b/message/amd/build/default_notification_preferences.min.js index d9fe2032f73..2550fe3a676 100644 --- a/message/amd/build/default_notification_preferences.min.js +++ b/message/amd/build/default_notification_preferences.min.js @@ -1,4 +1,4 @@ -define("core_message/default_notification_preferences",["exports","core/ajax","core/notification"],(function(_exports,Ajax,_notification){var obj;function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Ajax=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj} +define("core_message/default_notification_preferences",["exports","core/ajax","core/notification","core/toast"],(function(_exports,Ajax,_notification,_toast){var obj;function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Ajax=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj} /** * Controls the default settings for the list of notification types on the * notifications admin page @@ -8,6 +8,6 @@ define("core_message/default_notification_preferences",["exports","core/ajax","c * @copyright 2021 Moodle * @author Pau Ferrer Ocaña * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */(Ajax),_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj};const selectors_provider=".defaultmessageoutputs .provider_enabled",selectors_lockSetting=".locked_message_setting",selectors_enabledSetting=".enabled_message_setting",selectors_allSettings=".locked_message_setting, .enabled_message_setting";var _default={init:()=>{(()=>{const toggleLockSetting=lockedElement=>{const isEnabled=lockedElement.checked||!1,enabledId=lockedElement.id.replace("_locked[","_enabled[");document.getElementById(enabledId).closest("div.form-check").classList.toggle("dimmed_text",isEnabled)},toggleEnableProviderSettings=providerEnabledElement=>{const isEnabled=providerEnabledElement.checked||!1;providerEnabledElement.closest("tr").querySelectorAll(selectors_allSettings).forEach((element=>{element.toggleAttribute("disabled",!isEnabled)}))},setDefaultNotification=(isEnabled,preference)=>{Ajax.call([{methodname:"core_message_set_default_notification",args:{preference:preference,state:isEnabled?1:0}}])[0].done((data=>{_notification.default.addNotification({message:data.successmessage,type:"success"})})).fail(_notification.default.exception)},container=document.querySelector(".preferences-container");container.querySelectorAll(selectors_provider).forEach((providerEnabledElement=>{providerEnabledElement.checked||toggleEnableProviderSettings(providerEnabledElement),providerEnabledElement.addEventListener("change",(e=>{toggleEnableProviderSettings(e.target),setDefaultNotification(e.target.checked,providerEnabledElement.parentElement.parentElement.dataset.preference)}))})),container.querySelectorAll(selectors_lockSetting).forEach((lockedElement=>{lockedElement.checked&&toggleLockSetting(lockedElement),lockedElement.addEventListener("change",(e=>{toggleLockSetting(e.target),setDefaultNotification(e.target.checked,lockedElement.parentElement.parentElement.dataset.preference)}))})),container.querySelectorAll(selectors_enabledSetting).forEach((enabledElement=>{enabledElement.addEventListener("change",(e=>{setDefaultNotification(e.target.checked,enabledElement.parentElement.parentElement.dataset.preference)}))}))})()}};return _exports.default=_default,_exports.default})); + */(Ajax),_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj};const selectors_provider=".defaultmessageoutputs .provider_enabled",selectors_lockSetting=".locked_message_setting",selectors_enabledSetting=".enabled_message_setting",selectors_allSettings=".locked_message_setting, .enabled_message_setting";var _default={init:()=>{(()=>{const toggleLockSetting=lockedElement=>{const isEnabled=lockedElement.checked||!1,enabledId=lockedElement.id.replace("_locked[","_enabled[");document.getElementById(enabledId).closest("div.form-check").classList.toggle("dimmed_text",isEnabled)},toggleEnableProviderSettings=providerEnabledElement=>{const isEnabled=providerEnabledElement.checked||!1;providerEnabledElement.closest("tr").querySelectorAll(selectors_allSettings).forEach((element=>{element.toggleAttribute("disabled",!isEnabled)}))},setDefaultNotification=(isEnabled,preference)=>{Ajax.call([{methodname:"core_message_set_default_notification",args:{preference:preference,state:isEnabled?1:0}}])[0].then((data=>(0,_toast.add)(data.successmessage))).catch(_notification.default.exception)},container=document.querySelector(".preferences-container");container.querySelectorAll(selectors_provider).forEach((providerEnabledElement=>{providerEnabledElement.checked||toggleEnableProviderSettings(providerEnabledElement),providerEnabledElement.addEventListener("change",(e=>{toggleEnableProviderSettings(e.target),setDefaultNotification(e.target.checked,providerEnabledElement.parentElement.parentElement.dataset.preference)}))})),container.querySelectorAll(selectors_lockSetting).forEach((lockedElement=>{lockedElement.checked&&toggleLockSetting(lockedElement),lockedElement.addEventListener("change",(e=>{toggleLockSetting(e.target),setDefaultNotification(e.target.checked,lockedElement.parentElement.parentElement.dataset.preference)}))})),container.querySelectorAll(selectors_enabledSetting).forEach((enabledElement=>{enabledElement.addEventListener("change",(e=>{setDefaultNotification(e.target.checked,enabledElement.parentElement.parentElement.dataset.preference)}))}))})()}};return _exports.default=_default,_exports.default})); //# sourceMappingURL=default_notification_preferences.min.js.map \ No newline at end of file diff --git a/message/amd/build/default_notification_preferences.min.js.map b/message/amd/build/default_notification_preferences.min.js.map index cba322c0cb4..91cccf78dcc 100644 --- a/message/amd/build/default_notification_preferences.min.js.map +++ b/message/amd/build/default_notification_preferences.min.js.map @@ -1 +1 @@ -{"version":3,"file":"default_notification_preferences.min.js","sources":["../src/default_notification_preferences.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 .\n\n/**\n * Controls the default settings for the list of notification types on the\n * notifications admin page\n *\n * @module core_message/default_notification_preferences\n * @class default_notification_preferences\n * @copyright 2021 Moodle\n * @author Pau Ferrer Ocaña \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as Ajax from 'core/ajax';\nimport Notification from 'core/notification';\n\nconst selectors = {\n provider: '.defaultmessageoutputs .provider_enabled',\n lockSetting: '.locked_message_setting',\n enabledSetting: '.enabled_message_setting',\n allSettings: '.locked_message_setting, .enabled_message_setting'\n};\n\n/**\n * Register event listeners for the default_notification_preferences page.\n */\nconst registerEventListeners = () => {\n\n /**\n * Update the dimmed status of the \"enabled\" toggle on the notification setting.\n *\n * @param {HTMLElement} lockedElement Element that receives the event.\n */\n const toggleLockSetting = (lockedElement) => {\n const isEnabled = lockedElement.checked || false;\n const enabledId = lockedElement.id.replace('_locked[', '_enabled[');\n\n const enabledElement = document.getElementById(enabledId).closest('div.form-check');\n enabledElement.classList.toggle('dimmed_text', isEnabled);\n };\n\n /**\n * Enable/Disable all settings of the provider.\n *\n * @param {HTMLElement} providerEnabledElement Element that receives the event.\n */\n const toggleEnableProviderSettings = (providerEnabledElement) => {\n const isEnabled = providerEnabledElement.checked || false;\n const parentRow = providerEnabledElement.closest('tr');\n\n const elements = parentRow.querySelectorAll(selectors.allSettings);\n elements.forEach((element) => {\n element.toggleAttribute('disabled', !isEnabled);\n });\n };\n\n /**\n * AJAX call to update the default notification element status on the server.\n *\n * @param {Boolean} isEnabled\n * @param {string} preference\n */\n const setDefaultNotification = (isEnabled, preference) => {\n // AJAX call to update the provider's enable status on the server.\n Ajax.call([{\n methodname: 'core_message_set_default_notification',\n args: {\n preference: preference,\n state: isEnabled ? 1 : 0\n }\n }])[0].done((data) => {\n // Display success notification.\n Notification.addNotification({\n message: data.successmessage,\n type: 'success'\n });\n })\n .fail(Notification.exception);\n };\n\n const container = document.querySelector('.preferences-container');\n\n container.querySelectorAll(selectors.provider).forEach((providerEnabledElement) => {\n // Set the initial statuses.\n if (!providerEnabledElement.checked) {\n toggleEnableProviderSettings(providerEnabledElement);\n }\n\n providerEnabledElement.addEventListener('change', (e) => {\n toggleEnableProviderSettings(e.target);\n\n setDefaultNotification(\n e.target.checked,\n providerEnabledElement.parentElement.parentElement.dataset.preference);\n });\n });\n\n container.querySelectorAll(selectors.lockSetting).forEach((lockedElement) => {\n // Set the initial statuses.\n if (lockedElement.checked) {\n toggleLockSetting(lockedElement);\n }\n\n lockedElement.addEventListener('change', (e) => {\n toggleLockSetting(e.target);\n\n setDefaultNotification(\n e.target.checked,\n lockedElement.parentElement.parentElement.dataset.preference);\n });\n });\n\n container.querySelectorAll(selectors.enabledSetting).forEach((enabledElement) => {\n enabledElement.addEventListener('change', (e) => {\n setDefaultNotification(\n e.target.checked,\n enabledElement.parentElement.parentElement.dataset.preference);\n });\n });\n};\n\n/**\n * Initialize the page.\n */\nconst init = () => {\n registerEventListeners();\n};\n\nexport default {\n init: init,\n};\n"],"names":["selectors","init","toggleLockSetting","lockedElement","isEnabled","checked","enabledId","id","replace","document","getElementById","closest","classList","toggle","toggleEnableProviderSettings","providerEnabledElement","querySelectorAll","forEach","element","toggleAttribute","setDefaultNotification","preference","Ajax","call","methodname","args","state","done","data","addNotification","message","successmessage","type","fail","Notification","exception","container","querySelector","addEventListener","e","target","parentElement","dataset","enabledElement","registerEventListeners"],"mappings":";;;;;;;;;;sFA4BMA,mBACQ,2CADRA,sBAEW,0BAFXA,yBAGc,2BAHdA,sBAIW,iEA4GF,CACXC,KALS,KAlGkB,YAOrBC,kBAAqBC,sBACjBC,UAAYD,cAAcE,UAAW,EACrCC,UAAYH,cAAcI,GAAGC,QAAQ,WAAY,aAEhCC,SAASC,eAAeJ,WAAWK,QAAQ,kBACnDC,UAAUC,OAAO,cAAeT,YAQ7CU,6BAAgCC,+BAC5BX,UAAYW,uBAAuBV,UAAW,EAClCU,uBAAuBJ,QAAQ,MAEtBK,iBAAiBhB,uBACnCiB,SAASC,UACdA,QAAQC,gBAAgB,YAAaf,eAUvCgB,uBAAyB,CAAChB,UAAWiB,cAEvCC,KAAKC,KAAK,CAAC,CACPC,WAAY,wCACZC,KAAM,CACFJ,WAAYA,WACZK,MAAOtB,UAAY,EAAI,MAE3B,GAAGuB,MAAMC,6BAEIC,gBAAgB,CACzBC,QAASF,KAAKG,eACdC,KAAM,eAGbC,KAAKC,sBAAaC,YAGjBC,UAAY3B,SAAS4B,cAAc,0BAEzCD,UAAUpB,iBAAiBhB,oBAAoBiB,SAASF,yBAE/CA,uBAAuBV,SACxBS,6BAA6BC,wBAGjCA,uBAAuBuB,iBAAiB,UAAWC,IAC/CzB,6BAA6ByB,EAAEC,QAE/BpB,uBACImB,EAAEC,OAAOnC,QACTU,uBAAuB0B,cAAcA,cAAcC,QAAQrB,kBAIvEe,UAAUpB,iBAAiBhB,uBAAuBiB,SAASd,gBAEnDA,cAAcE,SACdH,kBAAkBC,eAGtBA,cAAcmC,iBAAiB,UAAWC,IACtCrC,kBAAkBqC,EAAEC,QAEpBpB,uBACImB,EAAEC,OAAOnC,QACTF,cAAcsC,cAAcA,cAAcC,QAAQrB,kBAI9De,UAAUpB,iBAAiBhB,0BAA0BiB,SAAS0B,iBAC1DA,eAAeL,iBAAiB,UAAWC,IACvCnB,uBACImB,EAAEC,OAAOnC,QACTsC,eAAeF,cAAcA,cAAcC,QAAQrB,mBAS/DuB"} \ No newline at end of file +{"version":3,"file":"default_notification_preferences.min.js","sources":["../src/default_notification_preferences.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 .\n\n/**\n * Controls the default settings for the list of notification types on the\n * notifications admin page\n *\n * @module core_message/default_notification_preferences\n * @class default_notification_preferences\n * @copyright 2021 Moodle\n * @author Pau Ferrer Ocaña \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport * as Ajax from 'core/ajax';\nimport Notification from 'core/notification';\nimport {add as addToast} from 'core/toast';\n\nconst selectors = {\n provider: '.defaultmessageoutputs .provider_enabled',\n lockSetting: '.locked_message_setting',\n enabledSetting: '.enabled_message_setting',\n allSettings: '.locked_message_setting, .enabled_message_setting'\n};\n\n/**\n * Register event listeners for the default_notification_preferences page.\n */\nconst registerEventListeners = () => {\n\n /**\n * Update the dimmed status of the \"enabled\" toggle on the notification setting.\n *\n * @param {HTMLElement} lockedElement Element that receives the event.\n */\n const toggleLockSetting = (lockedElement) => {\n const isEnabled = lockedElement.checked || false;\n const enabledId = lockedElement.id.replace('_locked[', '_enabled[');\n\n const enabledElement = document.getElementById(enabledId).closest('div.form-check');\n enabledElement.classList.toggle('dimmed_text', isEnabled);\n };\n\n /**\n * Enable/Disable all settings of the provider.\n *\n * @param {HTMLElement} providerEnabledElement Element that receives the event.\n */\n const toggleEnableProviderSettings = (providerEnabledElement) => {\n const isEnabled = providerEnabledElement.checked || false;\n const parentRow = providerEnabledElement.closest('tr');\n\n const elements = parentRow.querySelectorAll(selectors.allSettings);\n elements.forEach((element) => {\n element.toggleAttribute('disabled', !isEnabled);\n });\n };\n\n /**\n * AJAX call to update the default notification element status on the server.\n *\n * @param {Boolean} isEnabled\n * @param {string} preference\n */\n const setDefaultNotification = (isEnabled, preference) => {\n // AJAX call to update the provider's enable status on the server.\n Ajax.call([{\n methodname: 'core_message_set_default_notification',\n args: {\n preference: preference,\n state: isEnabled ? 1 : 0\n }\n }])[0]\n .then((data) => addToast(data.successmessage))\n .catch(Notification.exception);\n };\n\n const container = document.querySelector('.preferences-container');\n\n container.querySelectorAll(selectors.provider).forEach((providerEnabledElement) => {\n // Set the initial statuses.\n if (!providerEnabledElement.checked) {\n toggleEnableProviderSettings(providerEnabledElement);\n }\n\n providerEnabledElement.addEventListener('change', (e) => {\n toggleEnableProviderSettings(e.target);\n\n setDefaultNotification(\n e.target.checked,\n providerEnabledElement.parentElement.parentElement.dataset.preference);\n });\n });\n\n container.querySelectorAll(selectors.lockSetting).forEach((lockedElement) => {\n // Set the initial statuses.\n if (lockedElement.checked) {\n toggleLockSetting(lockedElement);\n }\n\n lockedElement.addEventListener('change', (e) => {\n toggleLockSetting(e.target);\n\n setDefaultNotification(\n e.target.checked,\n lockedElement.parentElement.parentElement.dataset.preference);\n });\n });\n\n container.querySelectorAll(selectors.enabledSetting).forEach((enabledElement) => {\n enabledElement.addEventListener('change', (e) => {\n setDefaultNotification(\n e.target.checked,\n enabledElement.parentElement.parentElement.dataset.preference);\n });\n });\n};\n\n/**\n * Initialize the page.\n */\nconst init = () => {\n registerEventListeners();\n};\n\nexport default {\n init: init,\n};\n"],"names":["selectors","init","toggleLockSetting","lockedElement","isEnabled","checked","enabledId","id","replace","document","getElementById","closest","classList","toggle","toggleEnableProviderSettings","providerEnabledElement","querySelectorAll","forEach","element","toggleAttribute","setDefaultNotification","preference","Ajax","call","methodname","args","state","then","data","successmessage","catch","Notification","exception","container","querySelector","addEventListener","e","target","parentElement","dataset","enabledElement","registerEventListeners"],"mappings":";;;;;;;;;;sFA6BMA,mBACQ,2CADRA,sBAEW,0BAFXA,yBAGc,2BAHdA,sBAIW,iEAuGF,CACXC,KALS,KA7FkB,YAOrBC,kBAAqBC,sBACjBC,UAAYD,cAAcE,UAAW,EACrCC,UAAYH,cAAcI,GAAGC,QAAQ,WAAY,aAEhCC,SAASC,eAAeJ,WAAWK,QAAQ,kBACnDC,UAAUC,OAAO,cAAeT,YAQ7CU,6BAAgCC,+BAC5BX,UAAYW,uBAAuBV,UAAW,EAClCU,uBAAuBJ,QAAQ,MAEtBK,iBAAiBhB,uBACnCiB,SAASC,UACdA,QAAQC,gBAAgB,YAAaf,eAUvCgB,uBAAyB,CAAChB,UAAWiB,cAEvCC,KAAKC,KAAK,CAAC,CACPC,WAAY,wCACZC,KAAM,CACFJ,WAAYA,WACZK,MAAOtB,UAAY,EAAI,MAE3B,GACHuB,MAAMC,OAAS,cAASA,KAAKC,kBAC7BC,MAAMC,sBAAaC,YAGlBC,UAAYxB,SAASyB,cAAc,0BAEzCD,UAAUjB,iBAAiBhB,oBAAoBiB,SAASF,yBAE/CA,uBAAuBV,SACxBS,6BAA6BC,wBAGjCA,uBAAuBoB,iBAAiB,UAAWC,IAC/CtB,6BAA6BsB,EAAEC,QAE/BjB,uBACIgB,EAAEC,OAAOhC,QACTU,uBAAuBuB,cAAcA,cAAcC,QAAQlB,kBAIvEY,UAAUjB,iBAAiBhB,uBAAuBiB,SAASd,gBAEnDA,cAAcE,SACdH,kBAAkBC,eAGtBA,cAAcgC,iBAAiB,UAAWC,IACtClC,kBAAkBkC,EAAEC,QAEpBjB,uBACIgB,EAAEC,OAAOhC,QACTF,cAAcmC,cAAcA,cAAcC,QAAQlB,kBAI9DY,UAAUjB,iBAAiBhB,0BAA0BiB,SAASuB,iBAC1DA,eAAeL,iBAAiB,UAAWC,IACvChB,uBACIgB,EAAEC,OAAOhC,QACTmC,eAAeF,cAAcA,cAAcC,QAAQlB,mBAS/DoB"} \ No newline at end of file diff --git a/message/amd/src/default_notification_preferences.js b/message/amd/src/default_notification_preferences.js index af96d237e80..0f925431d13 100644 --- a/message/amd/src/default_notification_preferences.js +++ b/message/amd/src/default_notification_preferences.js @@ -25,6 +25,7 @@ */ import * as Ajax from 'core/ajax'; import Notification from 'core/notification'; +import {add as addToast} from 'core/toast'; const selectors = { provider: '.defaultmessageoutputs .provider_enabled', @@ -80,14 +81,9 @@ const registerEventListeners = () => { preference: preference, state: isEnabled ? 1 : 0 } - }])[0].done((data) => { - // Display success notification. - Notification.addNotification({ - message: data.successmessage, - type: 'success' - }); - }) - .fail(Notification.exception); + }])[0] + .then((data) => addToast(data.successmessage)) + .catch(Notification.exception); }; const container = document.querySelector('.preferences-container');