Proyectos de Subversion Moodle

Rev

Rev 1 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

{"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 <http://www.gnu.org/licenses/>.\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 <pau@moodle.com>\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"}