mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
1 line
6.0 KiB
Plaintext
1 line
6.0 KiB
Plaintext
{"version":3,"file":"addblockmodal.min.js","sources":["../src/addblockmodal.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 * Show an add block modal instead of doing it on a separate page.\n *\n * @module core/addblockmodal\n * @deprecated since Moodle 4.2 - please use core_block/add_modal instead.\n * @copyright 2016 Damyon Wiese <damyon@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ModalFactory from 'core/modal_factory';\nimport Templates from 'core/templates';\nimport {get_string as getString} from 'core/str';\nimport Ajax from 'core/ajax';\n\nconst SELECTORS = {\n ADD_BLOCK: '[data-key=\"addblock\"]'\n};\n\n// Ensure we only add our listeners once.\nlet listenerEventsRegistered = false;\n\n/**\n * Register related event listeners.\n *\n * @method registerListenerEvents\n * @param {String} pageType The type of the page\n * @param {String} pageLayout The layout of the page\n * @param {String|null} addBlockUrl The add block URL\n * @param {String} subPage The subpage identifier\n */\nconst registerListenerEvents = (pageType, pageLayout, addBlockUrl, subPage) => {\n document.addEventListener('click', e => {\n\n const addBlock = e.target.closest(SELECTORS.ADD_BLOCK);\n if (addBlock) {\n e.preventDefault();\n\n let addBlockModal = null;\n let addBlockModalUrl = addBlockUrl ?? addBlock.dataset.url;\n\n buildAddBlockModal()\n .then(modal => {\n addBlockModal = modal;\n const modalBody = renderBlocks(addBlockModalUrl, pageType, pageLayout, subPage);\n modal.setBody(modalBody);\n modal.show();\n\n return modalBody;\n })\n .catch(() => {\n addBlockModal.destroy();\n });\n }\n });\n};\n\n/**\n * Method that creates the 'add block' modal.\n *\n * @method buildAddBlockModal\n * @returns {Promise} The modal promise (modal's body will be rendered later).\n */\nconst buildAddBlockModal = () => {\n return ModalFactory.create({\n type: ModalFactory.types.CANCEL,\n title: getString('addblock')\n });\n};\n\n/**\n * Method that renders the list of available blocks.\n *\n * @method renderBlocks\n * @param {String} addBlockUrl The add block URL\n * @param {String} pageType The type of the page\n * @param {String} pageLayout The layout of the page\n * @param {String} subPage The subpage identifier\n * @return {Promise}\n */\nconst renderBlocks = async(addBlockUrl, pageType, pageLayout, subPage) => {\n // Fetch all addable blocks in the given page.\n const blocks = await getAddableBlocks(pageType, pageLayout, subPage);\n\n return Templates.render('core/add_block_body', {\n blocks: blocks,\n url: addBlockUrl\n });\n};\n\n/**\n * Method that fetches all addable blocks in a given page.\n *\n * @method getAddableBlocks\n * @param {String} pageType The type of the page\n * @param {String} pageLayout The layout of the page\n * @param {String} subPage The subpage identifier\n * @return {Promise}\n */\nconst getAddableBlocks = async(pageType, pageLayout, subPage) => {\n const request = {\n methodname: 'core_block_fetch_addable_blocks',\n args: {\n pagecontextid: M.cfg.contextid,\n pagetype: pageType,\n pagelayout: pageLayout,\n subpage: subPage,\n },\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Set up the actions.\n *\n * @method init\n * @param {String} pageType The type of the page\n * @param {String} pageLayout The layout of the page\n * @param {String|null} addBlockUrl The add block URL\n * @param {String} subPage The subpage identifier\n */\nexport const init = (pageType, pageLayout, addBlockUrl = null, subPage = '') => {\n if (!listenerEventsRegistered) {\n registerListenerEvents(pageType, pageLayout, addBlockUrl, subPage);\n listenerEventsRegistered = true;\n }\n};\n"],"names":["SELECTORS","listenerEventsRegistered","registerListenerEvents","pageType","pageLayout","addBlockUrl","subPage","document","addEventListener","e","addBlock","target","closest","preventDefault","addBlockModal","addBlockModalUrl","dataset","url","buildAddBlockModal","then","modal","modalBody","renderBlocks","setBody","show","catch","destroy","ModalFactory","create","type","types","CANCEL","title","async","blocks","getAddableBlocks","Templates","render","request","methodname","args","pagecontextid","M","cfg","contextid","pagetype","pagelayout","subpage","Ajax","call"],"mappings":";;;;;;;;gOA6BMA,oBACS,4BAIXC,0BAA2B,QAWzBC,uBAAyB,CAACC,SAAUC,WAAYC,YAAaC,WAC/DC,SAASC,iBAAiB,SAASC,UAEzBC,SAAWD,EAAEE,OAAOC,QAAQZ,wBAC9BU,SAAU,CACVD,EAAEI,qBAEEC,cAAgB,KAChBC,iBAAmBV,MAAAA,YAAAA,YAAeK,SAASM,QAAQC,IAEvDC,qBACKC,MAAKC,QACFN,cAAgBM,YACVC,UAAYC,aAAaP,iBAAkBZ,SAAUC,WAAYE,gBACvEc,MAAMG,QAAQF,WACdD,MAAMI,OAECH,aAEVI,OAAM,KACHX,cAAcY,kBAY5BR,mBAAqB,IAChBS,uBAAaC,OAAO,CACvBC,KAAMF,uBAAaG,MAAMC,OACzBC,OAAO,mBAAU,cAcnBV,aAAeW,MAAM5B,YAAaF,SAAUC,WAAYE,iBAEpD4B,aAAeC,iBAAiBhC,SAAUC,WAAYE,gBAErD8B,mBAAUC,OAAO,sBAAuB,CAC3CH,OAAQA,OACRjB,IAAKZ,eAaP8B,iBAAmBF,MAAM9B,SAAUC,WAAYE,iBAC3CgC,QAAU,CACZC,WAAY,kCACZC,KAAM,CACFC,cAAeC,EAAEC,IAAIC,UACrBC,SAAU1C,SACV2C,WAAY1C,WACZ2C,QAASzC,iBAIV0C,cAAKC,KAAK,CAACX,UAAU,kBAYZ,SAACnC,SAAUC,gBAAYC,mEAAc,KAAMC,+DAAU,GAChEL,2BACDC,uBAAuBC,SAAUC,WAAYC,YAAaC,SAC1DL,0BAA2B"} |