diff --git a/lib/amd/build/dynamic_tabs.min.js b/lib/amd/build/dynamic_tabs.min.js index 72fd459f21b..89193e99da7 100644 --- a/lib/amd/build/dynamic_tabs.min.js +++ b/lib/amd/build/dynamic_tabs.min.js @@ -5,6 +5,6 @@ define("core/dynamic_tabs",["exports","jquery","core/templates","core/loadingico * @module core/dynamic_tabs * @copyright 2021 David Matamoros based on code from Marina Glancy * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_templates=_interopRequireDefault(_templates),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending);const SELECTORS={dynamicTabs:".dynamictabs",activeTab:".dynamictabs .nav-link.active",allActiveTabs:'.dynamictabs .nav-link[data-toggle="tab"]:not(.disabled)',tabContent:".dynamictabs .tab-pane [data-tab-content]",tabToggle:'a[data-toggle="tab"]',tabPane:".dynamictabs .tab-pane",forTabName:tabName=>'.dynamictabs [data-tab-content="'.concat(tabName,'"]'),forTabId:tabName=>'.dynamictabs [data-toggle="tab"][href="#'.concat(tabName,'"]')};_exports.init=()=>{const tabToggle=(0,_jquery.default)(SELECTORS.tabToggle);if(tabToggle.on("click",(event=>{(0,_changechecker.isAnyWatchedFormDirty)()&&(event.preventDefault(),event.stopPropagation(),(0,_str.get_strings)([{key:"changesmade",component:"moodle"},{key:"changesmadereallygoaway",component:"moodle"},{key:"confirm",component:"moodle"}]).then((_ref=>{let[strChangesMade,strChangesMadeReally,strConfirm]=_ref;return _notification.default.confirm(strChangesMade,strChangesMadeReally,strConfirm,null,(()=>{(0,_changechecker.resetAllFormDirtyStates)(),(0,_jquery.default)(event.target).trigger(event.type)}))})).catch(_notification.default.exception))})),tabToggle.on("show.bs.tab",(function(){const previousTabName=getActiveTabName();if(previousTabName){document.querySelector(SELECTORS.forTabName(previousTabName)).textContent=""}})).on("shown.bs.tab",(function(){const tab=(0,_jquery.default)((0,_jquery.default)(this).attr("href"));1===tab.length&&loadTab(tab.attr("id"))})),!openTabFromHash()){const tabs=document.querySelector(SELECTORS.allActiveTabs);if(tabs)openTab(tabs.getAttribute("aria-controls"));else{const tabPane=document.querySelector(SELECTORS.tabPane);tabPane&&(tabPane.classList.add("active","show"),loadTab(tabPane.getAttribute("id")))}}};const getActiveTabName=()=>{const element=document.querySelector(SELECTORS.activeTab);return(null==element?void 0:element.getAttribute("aria-controls"))||null},loadTab=tabName=>{var _ref2,_tabName;tabName=null!==(_ref2=null!==(_tabName=tabName)&&void 0!==_tabName?_tabName:getActiveTabName())&&void 0!==_ref2?_ref2:(()=>{const element=document.querySelector(SELECTORS.tabContent);return(null==element?void 0:element.dataset.tabContent)||null})();const tab=document.querySelector(SELECTORS.forTabName(tabName));if(!tab)return;const pendingPromise=new _pending.default("core/dynamic_tabs:loadTab:"+tabName);let tabjs="";(0,_loadingicon.addIconToContainer)(tab).then((()=>{let tabArgs={...tab.dataset};return delete tabArgs.tabClass,delete tabArgs.tabContent,(0,_dynamic_tabs.getContent)(tab.dataset.tabClass,JSON.stringify(tabArgs))})).then((data=>(tabjs=data.javascript,_templates.default.render(data.template,JSON.parse(data.content))))).then(((html,js)=>_templates.default.replaceNodeContents(tab,html,js+tabjs))).then((()=>(pendingPromise.resolve(),null))).catch(_notification.default.exception)},openTab=tabName=>{const tab=(tabName=>document.querySelector(SELECTORS.forTabId(tabName)))(tabName);return!!tab&&(loadTab(tabName),tab.classList.add("active"),(tabName=>document.getElementById(tabName))(tabName).classList.add("active","show"),!0)},openTabFromHash=()=>{const hash=document.location.hash;return!!hash.match(/^#\w+$/g)&&openTab(hash.replace(/^#/g,""))}})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_templates=_interopRequireDefault(_templates),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending);const SELECTORS={dynamicTabs:".dynamictabs",activeTab:".dynamictabs .nav-link.active",allActiveTabs:'.dynamictabs .nav-link[data-toggle="tab"]:not(.disabled)',tabContent:".dynamictabs .tab-pane [data-tab-content]",tabToggle:'a[data-toggle="tab"]',tabPane:".dynamictabs .tab-pane",forTabName:tabName=>'.dynamictabs [data-tab-content="'.concat(tabName,'"]'),forTabId:tabName=>'.dynamictabs [data-toggle="tab"][href="#'.concat(tabName,'"]')};_exports.init=()=>{const tabToggle=(0,_jquery.default)(SELECTORS.tabToggle);if(tabToggle.on("click",(event=>{(0,_changechecker.isAnyWatchedFormDirty)()&&(event.preventDefault(),event.stopPropagation(),(0,_str.get_strings)([{key:"changesmade",component:"moodle"},{key:"changesmadereallygoaway",component:"moodle"},{key:"confirm",component:"moodle"}]).then((_ref=>{let[strChangesMade,strChangesMadeReally,strConfirm]=_ref;return _notification.default.confirm(strChangesMade,strChangesMadeReally,strConfirm,null,(()=>{(0,_changechecker.resetAllFormDirtyStates)(),(0,_jquery.default)(event.target).trigger(event.type)}))})).catch(_notification.default.exception))})),tabToggle.on("show.bs.tab",(function(){const previousTabName=getActiveTabName();if(previousTabName){document.querySelector(SELECTORS.forTabName(previousTabName)).textContent=""}})).on("shown.bs.tab",(function(){const tab=(0,_jquery.default)((0,_jquery.default)(this).attr("href"));1===tab.length&&loadTab(tab.attr("id"))})),!openTabFromHash()){const tabs=document.querySelector(SELECTORS.allActiveTabs);if(tabs)openTab(tabs.getAttribute("aria-controls"));else{const tabPane=document.querySelector(SELECTORS.tabPane);tabPane&&(tabPane.classList.add("active","show"),loadTab(tabPane.getAttribute("id")))}}};const getActiveTabName=()=>{const element=document.querySelector(SELECTORS.activeTab);return(null==element?void 0:element.getAttribute("aria-controls"))||null},loadTab=tabName=>{var _ref2,_tabName;tabName=null!==(_ref2=null!==(_tabName=tabName)&&void 0!==_tabName?_tabName:getActiveTabName())&&void 0!==_ref2?_ref2:(()=>{const element=document.querySelector(SELECTORS.tabContent);return(null==element?void 0:element.dataset.tabContent)||null})();const tab=document.querySelector(SELECTORS.forTabName(tabName));if(!tab)return;const pendingPromise=new _pending.default("core/dynamic_tabs:loadTab:"+tabName);(0,_loadingicon.addIconToContainer)(tab).then((()=>{let tabArgs={...tab.dataset};return delete tabArgs.tabClass,delete tabArgs.tabContent,(0,_dynamic_tabs.getContent)(tab.dataset.tabClass,JSON.stringify(tabArgs))})).then((response=>Promise.all([_jquery.default.parseHTML(response.javascript,null,!0).map((node=>node.innerHTML)).join("\n"),_templates.default.renderForPromise(response.template,JSON.parse(response.content))]))).then((_ref3=>{let[responseJs,{html:html,js:js}]=_ref3;return _templates.default.replaceNodeContents(tab,html,js+responseJs)})).then((()=>pendingPromise.resolve())).catch(_notification.default.exception)},openTab=tabName=>{const tab=(tabName=>document.querySelector(SELECTORS.forTabId(tabName)))(tabName);return!!tab&&(loadTab(tabName),tab.classList.add("active"),(tabName=>document.getElementById(tabName))(tabName).classList.add("active","show"),!0)},openTabFromHash=()=>{const hash=document.location.hash;return!!hash.match(/^#\w+$/g)&&openTab(hash.replace(/^#/g,""))}})); //# sourceMappingURL=dynamic_tabs.min.js.map \ No newline at end of file diff --git a/lib/amd/build/dynamic_tabs.min.js.map b/lib/amd/build/dynamic_tabs.min.js.map index f8dfbc54c08..dbbc5952417 100644 --- a/lib/amd/build/dynamic_tabs.min.js.map +++ b/lib/amd/build/dynamic_tabs.min.js.map @@ -1 +1 @@ -{"version":3,"file":"dynamic_tabs.min.js","sources":["../src/dynamic_tabs.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 * Dynamic Tabs UI element with AJAX loading of tabs content\n *\n * @module core/dynamic_tabs\n * @copyright 2021 David Matamoros based on code from Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport Templates from 'core/templates';\nimport {addIconToContainer} from 'core/loadingicon';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport {get_strings as getStrings} from 'core/str';\nimport {getContent} from 'core/local/repository/dynamic_tabs';\nimport {isAnyWatchedFormDirty, resetAllFormDirtyStates} from 'core_form/changechecker';\n\nconst SELECTORS = {\n dynamicTabs: '.dynamictabs',\n activeTab: '.dynamictabs .nav-link.active',\n allActiveTabs: '.dynamictabs .nav-link[data-toggle=\"tab\"]:not(.disabled)',\n tabContent: '.dynamictabs .tab-pane [data-tab-content]',\n tabToggle: 'a[data-toggle=\"tab\"]',\n tabPane: '.dynamictabs .tab-pane',\n};\n\nSELECTORS.forTabName = tabName => `.dynamictabs [data-tab-content=\"${tabName}\"]`;\nSELECTORS.forTabId = tabName => `.dynamictabs [data-toggle=\"tab\"][href=\"#${tabName}\"]`;\n\n/**\n * Initialises the tabs view on the page (only one tabs view per page is supported)\n */\nexport const init = () => {\n const tabToggle = $(SELECTORS.tabToggle);\n\n // Listen to click, warn user if they are navigating away with unsaved form changes.\n tabToggle.on('click', (event) => {\n if (!isAnyWatchedFormDirty()) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n getStrings([\n {key: 'changesmade', component: 'moodle'},\n {key: 'changesmadereallygoaway', component: 'moodle'},\n {key: 'confirm', component: 'moodle'},\n ]).then(([strChangesMade, strChangesMadeReally, strConfirm]) =>\n // Reset form dirty state on confirmation, re-trigger the event.\n Notification.confirm(strChangesMade, strChangesMadeReally, strConfirm, null, () => {\n resetAllFormDirtyStates();\n $(event.target).trigger(event.type);\n })\n ).catch(Notification.exception);\n });\n\n // This code listens to Bootstrap events 'show.bs.tab' and 'shown.bs.tab' which is triggered using JQuery and\n // can not be converted yet to native events.\n tabToggle\n .on('show.bs.tab', function() {\n // Clean content from previous tab.\n const previousTabName = getActiveTabName();\n if (previousTabName) {\n const previousTab = document.querySelector(SELECTORS.forTabName(previousTabName));\n previousTab.textContent = '';\n }\n })\n .on('shown.bs.tab', function() {\n const tab = $($(this).attr('href'));\n if (tab.length !== 1) {\n return;\n }\n loadTab(tab.attr('id'));\n });\n\n if (!openTabFromHash()) {\n const tabs = document.querySelector(SELECTORS.allActiveTabs);\n if (tabs) {\n openTab(tabs.getAttribute('aria-controls'));\n } else {\n // We may hide tabs if there is only one available, just load the contents of the first tab.\n const tabPane = document.querySelector(SELECTORS.tabPane);\n if (tabPane) {\n tabPane.classList.add('active', 'show');\n loadTab(tabPane.getAttribute('id'));\n }\n }\n }\n};\n\n/**\n * Returns id/name of the currently active tab\n *\n * @return {String|null}\n */\nconst getActiveTabName = () => {\n const element = document.querySelector(SELECTORS.activeTab);\n return element?.getAttribute('aria-controls') || null;\n};\n\n/**\n * Returns the id/name of the first tab\n *\n * @return {String|null}\n */\nconst getFirstTabName = () => {\n const element = document.querySelector(SELECTORS.tabContent);\n return element?.dataset.tabContent || null;\n};\n\n/**\n * Loads contents of a tab using an AJAX request\n *\n * @param {String} tabName\n */\nconst loadTab = (tabName) => {\n // If tabName is not specified find the active tab, or if is not defined, the first available tab.\n tabName = tabName ?? getActiveTabName() ?? getFirstTabName();\n const tab = document.querySelector(SELECTORS.forTabName(tabName));\n if (!tab) {\n return;\n }\n\n const pendingPromise = new Pending('core/dynamic_tabs:loadTab:' + tabName);\n let tabjs = '';\n\n addIconToContainer(tab)\n .then(() => {\n let tabArgs = {...tab.dataset};\n delete tabArgs.tabClass;\n delete tabArgs.tabContent;\n return getContent(tab.dataset.tabClass, JSON.stringify(tabArgs));\n })\n .then((data) => {\n tabjs = data.javascript;\n return Templates.render(data.template, JSON.parse(data.content));\n })\n .then((html, js) => {\n return Templates.replaceNodeContents(tab, html, js + tabjs);\n })\n .then(() => {\n pendingPromise.resolve();\n return null;\n })\n .catch(Notification.exception);\n};\n\n/**\n * Return the tab given the tab name\n *\n * @param {String} tabName\n * @return {HTMLElement}\n */\nconst getTab = (tabName) => {\n return document.querySelector(SELECTORS.forTabId(tabName));\n};\n\n/**\n * Return the tab pane given the tab name\n *\n * @param {String} tabName\n * @return {HTMLElement}\n */\nconst getTabPane = (tabName) => {\n return document.getElementById(tabName);\n};\n\n/**\n * Open the tab on page load. If this script loads before theme_boost/tab we need to open tab ourselves\n *\n * @param {String} tabName\n * @return {Boolean}\n */\nconst openTab = (tabName) => {\n const tab = getTab(tabName);\n if (!tab) {\n return false;\n }\n\n loadTab(tabName);\n tab.classList.add('active');\n getTabPane(tabName).classList.add('active', 'show');\n return true;\n};\n\n/**\n * If there is a location hash that is the same as the tab name - open this tab.\n *\n * @return {Boolean}\n */\nconst openTabFromHash = () => {\n const hash = document.location.hash;\n if (hash.match(/^#\\w+$/g)) {\n return openTab(hash.replace(/^#/g, ''));\n }\n\n return false;\n};\n"],"names":["SELECTORS","dynamicTabs","activeTab","allActiveTabs","tabContent","tabToggle","tabPane","tabName","on","event","preventDefault","stopPropagation","key","component","then","_ref","strChangesMade","strChangesMadeReally","strConfirm","Notification","confirm","target","trigger","type","catch","exception","previousTabName","getActiveTabName","document","querySelector","forTabName","textContent","tab","this","attr","length","loadTab","openTabFromHash","tabs","openTab","getAttribute","classList","add","element","dataset","getFirstTabName","pendingPromise","Pending","tabjs","tabArgs","tabClass","JSON","stringify","data","javascript","Templates","render","template","parse","content","html","js","replaceNodeContents","resolve","forTabId","getTab","getElementById","getTabPane","hash","location","match","replace"],"mappings":";;;;;;;4QAgCMA,UAAY,CACdC,YAAa,eACbC,UAAW,gCACXC,cAAe,2DACfC,WAAY,4CACZC,UAAW,uBACXC,QAAS,yBAGbN,WAAuBO,mDAA8CA,cACrEP,SAAqBO,2DAAsDA,6BAKvD,WACVF,WAAY,mBAAEL,UAAUK,cAG9BA,UAAUG,GAAG,SAAUC,SACd,4CAILA,MAAMC,iBACND,MAAME,uCAEK,CACP,CAACC,IAAK,cAAeC,UA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AAKO,MAAML,KAAKM,aAE1D7C,MAAK,CAAC8C,KAAMC,KACFN,mBAAUO,oBAAoB9B,IAAK4B,KAAMC,GAAKb,SAExDlC,MAAK,KACFgC,eAAeiB,UACR,QAEVvC,MAAML,sBAAaM,YA6BlBc,QAAWhC,gBACPyB,IArBMzB,CAAAA,SACLqB,SAASC,cAAc7B,UAAUgE,SAASzD,UAoBrC0D,CAAO1D,iBACdyB,MAILI,QAAQ7B,SACRyB,IAAIS,UAAUC,IAAI,UAjBFnC,CAAAA,SACTqB,SAASsC,eAAe3D,SAiB/B4D,CAAW5D,SAASkC,UAAUC,IAAI,SAAU,SACrC,IAQLL,gBAAkB,WACd+B,KAAOxC,SAASyC,SAASD,aAC3BA,KAAKE,MAAM,YACJ/B,QAAQ6B,KAAKG,QAAQ,MAAO"} \ No newline at end of file +{"version":3,"file":"dynamic_tabs.min.js","sources":["../src/dynamic_tabs.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 * Dynamic Tabs UI element with AJAX loading of tabs content\n *\n * @module core/dynamic_tabs\n * @copyright 2021 David Matamoros based on code from Marina Glancy\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport Templates from 'core/templates';\nimport {addIconToContainer} from 'core/loadingicon';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport {get_strings as getStrings} from 'core/str';\nimport {getContent} from 'core/local/repository/dynamic_tabs';\nimport {isAnyWatchedFormDirty, resetAllFormDirtyStates} from 'core_form/changechecker';\n\nconst SELECTORS = {\n dynamicTabs: '.dynamictabs',\n activeTab: '.dynamictabs .nav-link.active',\n allActiveTabs: '.dynamictabs .nav-link[data-toggle=\"tab\"]:not(.disabled)',\n tabContent: '.dynamictabs .tab-pane [data-tab-content]',\n tabToggle: 'a[data-toggle=\"tab\"]',\n tabPane: '.dynamictabs .tab-pane',\n};\n\nSELECTORS.forTabName = tabName => `.dynamictabs [data-tab-content=\"${tabName}\"]`;\nSELECTORS.forTabId = tabName => `.dynamictabs [data-toggle=\"tab\"][href=\"#${tabName}\"]`;\n\n/**\n * Initialises the tabs view on the page (only one tabs view per page is supported)\n */\nexport const init = () => {\n const tabToggle = $(SELECTORS.tabToggle);\n\n // Listen to click, warn user if they are navigating away with unsaved form changes.\n tabToggle.on('click', (event) => {\n if (!isAnyWatchedFormDirty()) {\n return;\n }\n\n event.preventDefault();\n event.stopPropagation();\n\n getStrings([\n {key: 'changesmade', component: 'moodle'},\n {key: 'changesmadereallygoaway', component: 'moodle'},\n {key: 'confirm', component: 'moodle'},\n ]).then(([strChangesMade, strChangesMadeReally, strConfirm]) =>\n // Reset form dirty state on confirmation, re-trigger the event.\n Notification.confirm(strChangesMade, strChangesMadeReally, strConfirm, null, () => {\n resetAllFormDirtyStates();\n $(event.target).trigger(event.type);\n })\n ).catch(Notification.exception);\n });\n\n // This code listens to Bootstrap events 'show.bs.tab' and 'shown.bs.tab' which is triggered using JQuery and\n // can not be converted yet to native events.\n tabToggle\n .on('show.bs.tab', function() {\n // Clean content from previous tab.\n const previousTabName = getActiveTabName();\n if (previousTabName) {\n const previousTab = document.querySelector(SELECTORS.forTabName(previousTabName));\n previousTab.textContent = '';\n }\n })\n .on('shown.bs.tab', function() {\n const tab = $($(this).attr('href'));\n if (tab.length !== 1) {\n return;\n }\n loadTab(tab.attr('id'));\n });\n\n if (!openTabFromHash()) {\n const tabs = document.querySelector(SELECTORS.allActiveTabs);\n if (tabs) {\n openTab(tabs.getAttribute('aria-controls'));\n } else {\n // We may hide tabs if there is only one available, just load the contents of the first tab.\n const tabPane = document.querySelector(SELECTORS.tabPane);\n if (tabPane) {\n tabPane.classList.add('active', 'show');\n loadTab(tabPane.getAttribute('id'));\n }\n }\n }\n};\n\n/**\n * Returns id/name of the currently active tab\n *\n * @return {String|null}\n */\nconst getActiveTabName = () => {\n const element = document.querySelector(SELECTORS.activeTab);\n return element?.getAttribute('aria-controls') || null;\n};\n\n/**\n * Returns the id/name of the first tab\n *\n * @return {String|null}\n */\nconst getFirstTabName = () => {\n const element = document.querySelector(SELECTORS.tabContent);\n return element?.dataset.tabContent || null;\n};\n\n/**\n * Loads contents of a tab using an AJAX request\n *\n * @param {String} tabName\n */\nconst loadTab = (tabName) => {\n // If tabName is not specified find the active tab, or if is not defined, the first available tab.\n tabName = tabName ?? getActiveTabName() ?? getFirstTabName();\n const tab = document.querySelector(SELECTORS.forTabName(tabName));\n if (!tab) {\n return;\n }\n\n const pendingPromise = new Pending('core/dynamic_tabs:loadTab:' + tabName);\n\n addIconToContainer(tab)\n .then(() => {\n let tabArgs = {...tab.dataset};\n delete tabArgs.tabClass;\n delete tabArgs.tabContent;\n return getContent(tab.dataset.tabClass, JSON.stringify(tabArgs));\n })\n .then(response => Promise.all([\n $.parseHTML(response.javascript, null, true).map(node => node.innerHTML).join(\"\\n\"),\n Templates.renderForPromise(response.template, JSON.parse(response.content)),\n ]))\n .then(([responseJs, {html, js}]) => Templates.replaceNodeContents(tab, html, js + responseJs))\n .then(() => pendingPromise.resolve())\n .catch(Notification.exception);\n};\n\n/**\n * Return the tab given the tab name\n *\n * @param {String} tabName\n * @return {HTMLElement}\n */\nconst getTab = (tabName) => {\n return document.querySelector(SELECTORS.forTabId(tabName));\n};\n\n/**\n * Return the tab pane given the tab name\n *\n * @param {String} tabName\n * @return {HTMLElement}\n */\nconst getTabPane = (tabName) => {\n return document.getElementById(tabName);\n};\n\n/**\n * Open the tab on page load. If this script loads before theme_boost/tab we need to open tab ourselves\n *\n * @param {String} tabName\n * @return {Boolean}\n */\nconst openTab = (tabName) => {\n const tab = getTab(tabName);\n if (!tab) {\n return false;\n }\n\n loadTab(tabName);\n tab.classList.add('active');\n getTabPane(tabName).classList.add('active', 'show');\n return true;\n};\n\n/**\n * If there is a location hash that is the same as the tab name - open this tab.\n *\n * @return {Boolean}\n */\nconst openTabFromHash = () => {\n const hash = document.location.hash;\n if (hash.match(/^#\\w+$/g)) {\n return openTab(hash.replace(/^#/g, ''));\n }\n\n return false;\n};\n"],"names":["SELECTORS","dynamicTabs","activeTab","allActiveTabs","tabContent","tabToggle","tabPane","tabName","on","event","preventDefault","stopPropagation","key","component","then","_ref","strChangesMade","strChangesMadeReally","strConfirm","Notification","confirm","target","trigger","type","catch","exception","previousTabName","getActiveTabName","document","querySelector","forTabName","textContent","tab","this","attr","length","loadTab","openTabFromHash","tabs","openTab","getAttribute","classList","add","element","dataset","getFirstTabName","pendingPromise","Pending","tabArgs","tabClass","JSON","stringify","response","Promise","all","$","parseHTML","javascript","map","node","innerHTML","join","Templates","renderForPromise","template","parse","content","_ref3","responseJs","html","js","replaceNodeContents","resolve","forTabId","getTab","getElementById","getTabPane","hash","location","match","replace"],"mappings":";;;;;;;4QAgCMA,UAAY,CACdC,YAAa,eACbC,UAAW,gCACXC,cAAe,2DACfC,WAAY,4CACZC,UAAW,uBACXC,QAAS,yBAGbN,WAAuBO,mDAA8CA,cACrEP,SAAqBO,2DAAsDA,6BAKvD,WACVF,WAAY,mBAAEL,UAAUK,cAG9BA,UAAUG,GAAG,SAAUC,SACd,4CAILA,MAAMC,iBACND,MAAME,uCAEK,CACP,CAACC,IAAK,cAAeC,UAAW,UAChC,CAACD,IAAK,0BAA2BC,UAAW,UAC5C,CAACD,IAAK,UAAWC,UAAW,YAC7BC,MAAKC,WAAEC,eAAgBC,qBAAsBC,wBAE5CC,sBAAaC,QAAQJ,eAAgBC,qBAAsBC,WAAY,MAAM,sEAEvET,MAAMY,QAAQC,QAAQb,MAAMc,YAEpCC,MAAML,sBAAaM,eAKzB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MAAML,sBAAaM,YA6BlBc,QAAWhC,gBACPyB,IArBMzB,CAAAA,SACLqB,SAASC,cAAc7B,UAAUyE,SAASlE,UAoBrCmE,CAAOnE,iBACdyB,MAILI,QAAQ7B,SACRyB,IAAIS,UAAUC,IAAI,UAjBFnC,CAAAA,SACTqB,SAAS+C,eAAepE,SAiB/BqE,CAAWrE,SAASkC,UAAUC,IAAI,SAAU,SACrC,IAQLL,gBAAkB,WACdwC,KAAOjD,SAASkD,SAASD,aAC3BA,KAAKE,MAAM,YACJxC,QAAQsC,KAAKG,QAAQ,MAAO"} \ No newline at end of file diff --git a/lib/amd/src/dynamic_tabs.js b/lib/amd/src/dynamic_tabs.js index fca4f3e7201..73d2cdfa0c3 100644 --- a/lib/amd/src/dynamic_tabs.js +++ b/lib/amd/src/dynamic_tabs.js @@ -138,7 +138,6 @@ const loadTab = (tabName) => { } const pendingPromise = new Pending('core/dynamic_tabs:loadTab:' + tabName); - let tabjs = ''; addIconToContainer(tab) .then(() => { @@ -147,17 +146,12 @@ const loadTab = (tabName) => { delete tabArgs.tabContent; return getContent(tab.dataset.tabClass, JSON.stringify(tabArgs)); }) - .then((data) => { - tabjs = data.javascript; - return Templates.render(data.template, JSON.parse(data.content)); - }) - .then((html, js) => { - return Templates.replaceNodeContents(tab, html, js + tabjs); - }) - .then(() => { - pendingPromise.resolve(); - return null; - }) + .then(response => Promise.all([ + $.parseHTML(response.javascript, null, true).map(node => node.innerHTML).join("\n"), + Templates.renderForPromise(response.template, JSON.parse(response.content)), + ])) + .then(([responseJs, {html, js}]) => Templates.replaceNodeContents(tab, html, js + responseJs)) + .then(() => pendingPromise.resolve()) .catch(Notification.exception); }; diff --git a/reportbuilder/amd/build/editor.min.js b/reportbuilder/amd/build/editor.min.js index ef5676a467e..a56734144fc 100644 --- a/reportbuilder/amd/build/editor.min.js +++ b/reportbuilder/amd/build/editor.min.js @@ -1,3 +1,3 @@ -define("core_reportbuilder/editor",["exports","core/inplace_editable","core/loadingicon","core/notification","core/pending","core/templates","core/str","core/toast","core_reportbuilder/local/selectors","core_reportbuilder/local/editor/columns","core_reportbuilder/local/editor/conditions","core_reportbuilder/local/editor/filters","core_reportbuilder/local/editor/sorting","core_reportbuilder/local/editor/card_view","core_reportbuilder/local/repository/reports","core_reportbuilder/local/repository/modals"],(function(_exports,_inplace_editable,_loadingicon,_notification,_pending,_templates,_str,_toast,reportSelectors,_columns,_conditions,_filters,_sorting,_card_view,_reports,_modals){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)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending),_templates=_interopRequireDefault(_templates),reportSelectors=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}(reportSelectors);let initialized=!1;_exports.init=()=>{(0,_columns.init)(initialized),(0,_conditions.init)(initialized),(0,_filters.init)(initialized),(0,_sorting.init)(initialized),(0,_card_view.init)(initialized),initialized||(document.addEventListener("click",(event=>{const toggleEditViewMode=event.target.closest(reportSelectors.actions.toggleEditPreview);if(toggleEditViewMode){event.preventDefault();const reportElement=event.target.closest(reportSelectors.regions.report),pendingPromise=new _pending.default("core_reportbuilder/reports:get"),toggledEditMode="1"!==toggleEditViewMode.dataset.editMode;let customjs="";(0,_loadingicon.addIconToContainer)(toggleEditViewMode).then((()=>(0,_reports.getReport)(reportElement.dataset.reportId,toggledEditMode))).then((response=>(customjs=response.javascript,_templates.default.render("core_reportbuilder/local/dynamictabs/editor",response)))).then(((html,js)=>_templates.default.replaceNode(reportElement,html,js+customjs))).then((()=>pendingPromise.resolve())).catch(_notification.default.exception)}const reportEdit=event.target.closest(reportSelectors.actions.reportEdit);if(reportEdit){event.preventDefault();const reportModal=(0,_modals.createReportModal)(event.target,(0,_str.get_string)("editreportdetails","core_reportbuilder"),reportEdit.dataset.reportId);reportModal.addEventListener(reportModal.events.FORM_SUBMITTED,(()=>{(0,_str.get_string)("reportupdated","core_reportbuilder").then(_toast.add).then((()=>window.location.reload())).catch(_notification.default.exception)})),reportModal.show()}})),initialized=!0)}})); +define("core_reportbuilder/editor",["exports","jquery","core/inplace_editable","core/loadingicon","core/notification","core/pending","core/templates","core/str","core/toast","core_reportbuilder/local/selectors","core_reportbuilder/local/editor/columns","core_reportbuilder/local/editor/conditions","core_reportbuilder/local/editor/filters","core_reportbuilder/local/editor/sorting","core_reportbuilder/local/editor/card_view","core_reportbuilder/local/repository/reports","core_reportbuilder/local/repository/modals"],(function(_exports,_jquery,_inplace_editable,_loadingicon,_notification,_pending,_templates,_str,_toast,reportSelectors,_columns,_conditions,_filters,_sorting,_card_view,_reports,_modals){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)}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending),_templates=_interopRequireDefault(_templates),reportSelectors=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}(reportSelectors);let initialized=!1;_exports.init=()=>{(0,_columns.init)(initialized),(0,_conditions.init)(initialized),(0,_filters.init)(initialized),(0,_sorting.init)(initialized),(0,_card_view.init)(initialized),initialized||(document.addEventListener("click",(event=>{const toggleEditViewMode=event.target.closest(reportSelectors.actions.toggleEditPreview);if(toggleEditViewMode){event.preventDefault();const reportElement=event.target.closest(reportSelectors.regions.report),pendingPromise=new _pending.default("core_reportbuilder/reports:get"),toggledEditMode="1"!==toggleEditViewMode.dataset.editMode;(0,_loadingicon.addIconToContainer)(toggleEditViewMode).then((()=>(0,_reports.getReport)(reportElement.dataset.reportId,toggledEditMode))).then((response=>Promise.all([_jquery.default.parseHTML(response.javascript,null,!0).map((node=>node.innerHTML)).join("\n"),_templates.default.renderForPromise("core_reportbuilder/local/dynamictabs/editor",response)]))).then((_ref=>{let[responseJs,{html:html,js:js}]=_ref;return _templates.default.replaceNode(reportElement,html,js+responseJs)})).then((()=>pendingPromise.resolve())).catch(_notification.default.exception)}const reportEdit=event.target.closest(reportSelectors.actions.reportEdit);if(reportEdit){event.preventDefault();const reportModal=(0,_modals.createReportModal)(event.target,(0,_str.get_string)("editreportdetails","core_reportbuilder"),reportEdit.dataset.reportId);reportModal.addEventListener(reportModal.events.FORM_SUBMITTED,(()=>{(0,_str.get_string)("reportupdated","core_reportbuilder").then(_toast.add).then((()=>window.location.reload())).catch(_notification.default.exception)})),reportModal.show()}})),initialized=!0)}})); //# sourceMappingURL=editor.min.js.map \ No newline at end of file diff --git a/reportbuilder/amd/build/editor.min.js.map b/reportbuilder/amd/build/editor.min.js.map index 6780dc5f660..488e7a52b0d 100644 --- a/reportbuilder/amd/build/editor.min.js.map +++ b/reportbuilder/amd/build/editor.min.js.map @@ -1 +1 @@ -{"version":3,"file":"editor.min.js","sources":["../src/editor.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 * Report builder editor\n *\n * @module core_reportbuilder/editor\n * @copyright 2021 David Matamoros \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport 'core/inplace_editable';\nimport {addIconToContainer} from 'core/loadingicon';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport Templates from 'core/templates';\nimport {get_string as getString} from 'core/str';\nimport {add as addToast} from 'core/toast';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {init as columnsEditorInit} from 'core_reportbuilder/local/editor/columns';\nimport {init as conditionsEditorInit} from 'core_reportbuilder/local/editor/conditions';\nimport {init as filtersEditorInit} from 'core_reportbuilder/local/editor/filters';\nimport {init as sortingEditorInit} from 'core_reportbuilder/local/editor/sorting';\nimport {init as cardviewEditorInit} from 'core_reportbuilder/local/editor/card_view';\nimport {getReport} from 'core_reportbuilder/local/repository/reports';\nimport {createReportModal} from 'core_reportbuilder/local/repository/modals';\n\nlet initialized = false;\n\n/**\n * Initialise editor and all it's modules\n */\nexport const init = () => {\n columnsEditorInit(initialized);\n conditionsEditorInit(initialized);\n filtersEditorInit(initialized);\n sortingEditorInit(initialized);\n cardviewEditorInit(initialized);\n\n // Ensure we only add our listeners once (can be called multiple times by mustache template).\n if (initialized) {\n return;\n }\n\n // Add event handlers to generic report editor elements.\n document.addEventListener('click', event => {\n\n // Toggle between edit and preview mode.\n const toggleEditViewMode = event.target.closest(reportSelectors.actions.toggleEditPreview);\n if (toggleEditViewMode) {\n event.preventDefault();\n\n const reportElement = event.target.closest(reportSelectors.regions.report);\n const pendingPromise = new Pending('core_reportbuilder/reports:get');\n const toggledEditMode = toggleEditViewMode.dataset.editMode !== \"1\";\n\n let customjs = '';\n\n addIconToContainer(toggleEditViewMode)\n .then(() => getReport(reportElement.dataset.reportId, toggledEditMode))\n .then(response => {\n customjs = response.javascript;\n return Templates.render('core_reportbuilder/local/dynamictabs/editor', response);\n })\n .then((html, js) => {\n return Templates.replaceNode(reportElement, html, js + customjs);\n })\n .then(() => pendingPromise.resolve())\n .catch(Notification.exception);\n }\n\n // Edit report details modal.\n const reportEdit = event.target.closest(reportSelectors.actions.reportEdit);\n if (reportEdit) {\n event.preventDefault();\n\n const reportModal = createReportModal(event.target, getString('editreportdetails', 'core_reportbuilder'),\n reportEdit.dataset.reportId);\n reportModal.addEventListener(reportModal.events.FORM_SUBMITTED, () => {\n getString('reportupdated', 'core_reportbuilder')\n .then(addToast)\n .then(() => {\n return window.location.reload();\n })\n .catch(Notification.exception);\n });\n reportModal.show();\n }\n });\n\n initialized = true;\n};\n"],"names":["initialized","document","addEventListener","event","toggleEditViewMode","target","closest","reportSelectors","actions","toggleEditPreview","preventDefault","reportElement","regions","report","pendingPromise","Pending","toggledEditMode","dataset","editMode","customjs","then","reportId","response","javascript","Templates","render","html","js","replaceNode","resolve","catch","Notification","exception","reportEdit","reportModal","events","FORM_SUBMITTED","addToast","window","location","reload","show"],"mappings":"i6DAyCIA,aAAc,gBAKE,uBACEA,kCACGA,+BACHA,+BACAA,iCACCA,aAGfA,cAKJC,SAASC,iBAAiB,SAASC,cAGzBC,mBAAqBD,MAAME,OAAOC,QAAQC,gBAAgBC,QAAQC,sBACpEL,mBAAoB,CACpBD,MAAMO,uBAEAC,cAAgBR,MAAME,OAAOC,QAAQC,gBAAgBK,QAAQC,QAC7DC,eAAiB,IAAIC,iBAAQ,kCAC7BC,gBAA0D,MAAxCZ,mBAAmBa,QAAQC,aAE/CC,SAAW,uCAEIf,oBACdgB,MAAK,KAAM,sBAAUT,cAAcM,QAAQI,SAAUL,mBACrDI,MAAKE,WACFH,SAAWG,SAASC,WACbC,mBAAUC,OAAO,8CAA+CH,aAE1EF,MAAK,CAACM,KAAMC,KACFH,mBAAUI,YAAYjB,cAAee,KAAMC,GAAKR,YAE1DC,MAAK,IAAMN,eAAee,YAC1BC,MAAMC,sBAAaC,iBAItBC,WAAa9B,MAAME,OAAOC,QAAQC,gBAAgBC,QAAQyB,eAC5DA,WAAY,CACZ9B,MAAMO,uBAEAwB,aAAc,6BAAkB/B,MAAME,QAAQ,mBAAU,oBAAqB,sBAC/E4B,WAAWhB,QAAQI,UACvBa,YAAYhC,iBAAiBgC,YAAYC,OAAOC,gBAAgB,yBAClD,gBAAiB,sBACtBhB,KAAKiB,YACLjB,MAAK,IACKkB,OAAOC,SAASC,WAE1BV,MAAMC,sBAAaC,cAE5BE,YAAYO,WAIpBzC,aAAc"} \ No newline at end of file +{"version":3,"file":"editor.min.js","sources":["../src/editor.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 * Report builder editor\n *\n * @module core_reportbuilder/editor\n * @copyright 2021 David Matamoros \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport $ from 'jquery';\nimport 'core/inplace_editable';\nimport {addIconToContainer} from 'core/loadingicon';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport Templates from 'core/templates';\nimport {get_string as getString} from 'core/str';\nimport {add as addToast} from 'core/toast';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {init as columnsEditorInit} from 'core_reportbuilder/local/editor/columns';\nimport {init as conditionsEditorInit} from 'core_reportbuilder/local/editor/conditions';\nimport {init as filtersEditorInit} from 'core_reportbuilder/local/editor/filters';\nimport {init as sortingEditorInit} from 'core_reportbuilder/local/editor/sorting';\nimport {init as cardviewEditorInit} from 'core_reportbuilder/local/editor/card_view';\nimport {getReport} from 'core_reportbuilder/local/repository/reports';\nimport {createReportModal} from 'core_reportbuilder/local/repository/modals';\n\nlet initialized = false;\n\n/**\n * Initialise editor and all it's modules\n */\nexport const init = () => {\n columnsEditorInit(initialized);\n conditionsEditorInit(initialized);\n filtersEditorInit(initialized);\n sortingEditorInit(initialized);\n cardviewEditorInit(initialized);\n\n // Ensure we only add our listeners once (can be called multiple times by mustache template).\n if (initialized) {\n return;\n }\n\n // Add event handlers to generic report editor elements.\n document.addEventListener('click', event => {\n\n // Toggle between edit and preview mode.\n const toggleEditViewMode = event.target.closest(reportSelectors.actions.toggleEditPreview);\n if (toggleEditViewMode) {\n event.preventDefault();\n\n const reportElement = event.target.closest(reportSelectors.regions.report);\n const pendingPromise = new Pending('core_reportbuilder/reports:get');\n const toggledEditMode = toggleEditViewMode.dataset.editMode !== \"1\";\n\n addIconToContainer(toggleEditViewMode)\n .then(() => getReport(reportElement.dataset.reportId, toggledEditMode))\n .then(response => Promise.all([\n $.parseHTML(response.javascript, null, true).map(node => node.innerHTML).join(\"\\n\"),\n Templates.renderForPromise('core_reportbuilder/local/dynamictabs/editor', response),\n ]))\n .then(([responseJs, {html, js}]) => Templates.replaceNode(reportElement, html, js + responseJs))\n .then(() => pendingPromise.resolve())\n .catch(Notification.exception);\n }\n\n // Edit report details modal.\n const reportEdit = event.target.closest(reportSelectors.actions.reportEdit);\n if (reportEdit) {\n event.preventDefault();\n\n const reportModal = createReportModal(event.target, getString('editreportdetails', 'core_reportbuilder'),\n reportEdit.dataset.reportId);\n reportModal.addEventListener(reportModal.events.FORM_SUBMITTED, () => {\n getString('reportupdated', 'core_reportbuilder')\n .then(addToast)\n .then(() => {\n return window.location.reload();\n })\n .catch(Notification.exception);\n });\n reportModal.show();\n }\n });\n\n initialized = true;\n};\n"],"names":["initialized","document","addEventListener","event","toggleEditViewMode","target","closest","reportSelectors","actions","toggleEditPreview","preventDefault","reportElement","regions","report","pendingPromise","Pending","toggledEditMode","dataset","editMode","then","reportId","response","Promise","all","$","parseHTML","javascript","map","node","innerHTML","join","Templates","renderForPromise","_ref","responseJs","html","js","replaceNode","resolve","catch","Notification","exception","reportEdit","reportModal","events","FORM_SUBMITTED","addToast","window","location","reload","show"],"mappings":"09DA0CIA,aAAc,gBAKE,uBACEA,kCACGA,+BACHA,+BACAA,iCACCA,aAGfA,cAKJC,SAASC,iBAAiB,SAASC,cAGzBC,mBAAqBD,MAAME,OAAOC,QAAQC,gBAAgBC,QAAQC,sBACpEL,mBAAoB,CACpBD,MAAMO,uBAEAC,cAAgBR,MAAME,OAAOC,QAAQC,gBAAgBK,QAAQC,QAC7DC,eAAiB,IAAIC,iBAAQ,kCAC7BC,gBAA0D,MAAxCZ,mBAAmBa,QAAQC,6CAEhCd,oBACde,MAAK,KAAM,sBAAUR,cAAcM,QAAQG,SAAUJ,mBACrDG,MAAKE,UAAYC,QAAQC,IAAI,CAC1BC,gBAAEC,UAAUJ,SAASK,WAAY,MAAM,GAAMC,KAAIC,MAAQA,KAAKC,YAAWC,KAAK,MAC9EC,mBAAUC,iBAAiB,8CAA+CX,cAE7EF,MAAKc,WAAEC,YAAYC,KAACA,KAADC,GAAOA,iBAASL,mBAAUM,YAAY1B,cAAewB,KAAMC,GAAKF,eACnFf,MAAK,IAAML,eAAewB,YAC1BC,MAAMC,sBAAaC,iBAItBC,WAAavC,MAAME,OAAOC,QAAQC,gBAAgBC,QAAQkC,eAC5DA,WAAY,CACZvC,MAAMO,uBAEAiC,aAAc,6BAAkBxC,MAAME,QAAQ,mBAAU,oBAAqB,sBAC/EqC,WAAWzB,QAAQG,UACvBuB,YAAYzC,iBAAiByC,YAAYC,OAAOC,gBAAgB,yBAClD,gBAAiB,sBACtB1B,KAAK2B,YACL3B,MAAK,IACK4B,OAAOC,SAASC,WAE1BV,MAAMC,sBAAaC,cAE5BE,YAAYO,WAIpBlD,aAAc"} \ No newline at end of file diff --git a/reportbuilder/amd/build/local/editor/conditions.min.js b/reportbuilder/amd/build/local/editor/conditions.min.js index 6c93eb44e1b..b0be685a8ea 100644 --- a/reportbuilder/amd/build/local/editor/conditions.min.js +++ b/reportbuilder/amd/build/local/editor/conditions.min.js @@ -1,3 +1,3 @@ -define("core_reportbuilder/local/editor/conditions",["exports","jquery","core/custom_interaction_events","core/event_dispatcher","core/inplace_editable","core/notification","core/pending","core/prefetch","core/sortable_list","core/str","core/templates","core/toast","core_form/dynamicform","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/conditions"],(function(_exports,_jquery,_custom_interaction_events,_event_dispatcher,_inplace_editable,_notification,_pending,_prefetch,_sortable_list,_str,_templates,_toast,_dynamicform,reportEvents,reportSelectors,_conditions){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)}function _interopRequireWildcard(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]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_custom_interaction_events=_interopRequireDefault(_custom_interaction_events),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending),_sortable_list=_interopRequireDefault(_sortable_list),_templates=_interopRequireDefault(_templates),_dynamicform=_interopRequireDefault(_dynamicform),reportEvents=_interopRequireWildcard(reportEvents),reportSelectors=_interopRequireWildcard(reportSelectors);const reloadSettingsConditionsRegion=(reportElement,templateContext)=>{const pendingPromise=new _pending.default("core_reportbuilder/conditions:reload"),settingsConditionsRegion=reportElement.querySelector(reportSelectors.regions.settingsConditions);return _templates.default.renderForPromise("core_reportbuilder/local/settings/conditions",{conditions:templateContext}).then((_ref=>{let{html:html,js:js}=_ref;_templates.default.replaceNode(settingsConditionsRegion,html,js+templateContext.javascript),initConditionsForm();const reportAddCondition=reportElement.querySelector(reportSelectors.actions.reportAddCondition);return null==reportAddCondition||reportAddCondition.focus(),pendingPromise.resolve()}))},initConditionsForm=()=>{_custom_interaction_events.default.define(reportSelectors.actions.reportAddCondition,[_custom_interaction_events.default.events.accessibleChange]);const reportElement=document.querySelector(reportSelectors.regions.report),conditionFormContainer=reportElement.querySelector(reportSelectors.regions.settingsConditions);if(!conditionFormContainer)return;const conditionForm=new _dynamicform.default(conditionFormContainer,"\\core_reportbuilder\\form\\condition");conditionForm.addEventListener(conditionForm.events.FORM_SUBMITTED,(event=>{event.preventDefault(),(0,_str.get_string)("conditionsapplied","core_reportbuilder").then(_toast.add).catch(_notification.default.exception),(0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement)})),conditionForm.addEventListener(conditionForm.events.NOSUBMIT_BUTTON_PRESSED,(event=>{event.preventDefault(),_notification.default.saveCancelPromise((0,_str.get_string)("resetconditions","core_reportbuilder"),(0,_str.get_string)("resetconditionsconfirm","core_reportbuilder"),(0,_str.get_string)("resetall","core_reportbuilder"),{triggerElement:event.detail}).then((()=>{const pendingPromise=new _pending.default("core_reportbuilder/conditions:reset");return(0,_conditions.resetConditions)(reportElement.dataset.reportId).then((data=>reloadSettingsConditionsRegion(reportElement,data))).then((()=>(0,_toast.add)((0,_str.get_string)("conditionsreset","core_reportbuilder")))).then((()=>((0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement),pendingPromise.resolve()))).catch(_notification.default.exception)})).catch((()=>{}))}))};_exports.init=initialized=>{((0,_prefetch.prefetchStrings)("core_reportbuilder",["conditionadded","conditiondeleted","conditionmoved","conditionsapplied","conditionsreset","deletecondition","deleteconditionconfirm","resetall","resetconditions","resetconditionsconfirm"]),(0,_prefetch.prefetchStrings)("core",["delete"]),initConditionsForm(),initialized)||((0,_jquery.default)(document).on(_custom_interaction_events.default.events.accessibleChange,reportSelectors.actions.reportAddCondition,(event=>{const reportAddCondition=event.target.closest(reportSelectors.actions.reportAddCondition);if(reportAddCondition){if(event.preventDefault(),0===reportAddCondition.selectedIndex)return;const reportElement=reportAddCondition.closest(reportSelectors.regions.report),pendingPromise=new _pending.default("core_reportbuilder/conditions:add");(0,_conditions.addCondition)(reportElement.dataset.reportId,reportAddCondition.value).then((data=>reloadSettingsConditionsRegion(reportElement,data))).then((()=>(0,_str.get_string)("conditionadded","core_reportbuilder",reportAddCondition.options[reportAddCondition.selectedIndex].text))).then(_toast.add).then((()=>((0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement),pendingPromise.resolve()))).catch(_notification.default.exception)}})),document.addEventListener("click",(event=>{const reportRemoveCondition=event.target.closest(reportSelectors.actions.reportRemoveCondition);if(reportRemoveCondition){event.preventDefault();const reportElement=reportRemoveCondition.closest(reportSelectors.regions.report),conditionContainer=reportRemoveCondition.closest(reportSelectors.regions.activeCondition),conditionName=conditionContainer.dataset.conditionName;_notification.default.saveCancelPromise((0,_str.get_string)("deletecondition","core_reportbuilder",conditionName),(0,_str.get_string)("deleteconditionconfirm","core_reportbuilder",conditionName),(0,_str.get_string)("delete","core"),{triggerElement:reportRemoveCondition}).then((()=>{const pendingPromise=new _pending.default("core_reportbuilder/conditions:remove");return(0,_conditions.deleteCondition)(reportElement.dataset.reportId,conditionContainer.dataset.conditionId).then((data=>reloadSettingsConditionsRegion(reportElement,data))).then((()=>(0,_toast.add)((0,_str.get_string)("conditiondeleted","core_reportbuilder",conditionName)))).then((()=>((0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement),pendingPromise.resolve()))).catch(_notification.default.exception)})).catch((()=>{}))}})),new _sortable_list.default("".concat(reportSelectors.regions.activeConditions),{isHorizontal:!1}).getElementName=element=>Promise.resolve(element.data("conditionName")),(0,_jquery.default)(document).on(_sortable_list.default.EVENTS.DROP,reportSelectors.regions.activeCondition,((event,info)=>{if(info.positionChanged){const pendingPromise=new _pending.default("core_reportbuilder/conditions:reorder"),reportElement=event.target.closest(reportSelectors.regions.report),conditionId=info.element.data("conditionId"),conditionPosition=info.element.data("conditionPosition");let targetConditionPosition=info.targetNextElement.data("conditionPosition")||info.element.siblings().length+2;targetConditionPosition>conditionPosition&&targetConditionPosition--,(0,_conditions.reorderCondition)(reportElement.dataset.reportId,conditionId,targetConditionPosition).then((data=>reloadSettingsConditionsRegion(reportElement,data))).then((()=>(0,_str.get_string)("conditionmoved","core_reportbuilder",info.element.data("conditionName")))).then(_toast.add).then((()=>((0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement),pendingPromise.resolve()))).catch(_notification.default.exception)}})))}})); +define("core_reportbuilder/local/editor/conditions",["exports","jquery","core/custom_interaction_events","core/event_dispatcher","core/inplace_editable","core/notification","core/pending","core/prefetch","core/sortable_list","core/str","core/templates","core/toast","core_form/dynamicform","core_reportbuilder/local/events","core_reportbuilder/local/selectors","core_reportbuilder/local/repository/conditions"],(function(_exports,_jquery,_custom_interaction_events,_event_dispatcher,_inplace_editable,_notification,_pending,_prefetch,_sortable_list,_str,_templates,_toast,_dynamicform,reportEvents,reportSelectors,_conditions){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)}function _interopRequireWildcard(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]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_custom_interaction_events=_interopRequireDefault(_custom_interaction_events),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending),_sortable_list=_interopRequireDefault(_sortable_list),_templates=_interopRequireDefault(_templates),_dynamicform=_interopRequireDefault(_dynamicform),reportEvents=_interopRequireWildcard(reportEvents),reportSelectors=_interopRequireWildcard(reportSelectors);const reloadSettingsConditionsRegion=(reportElement,templateContext)=>{const pendingPromise=new _pending.default("core_reportbuilder/conditions:reload"),settingsConditionsRegion=reportElement.querySelector(reportSelectors.regions.settingsConditions);return _templates.default.renderForPromise("core_reportbuilder/local/settings/conditions",{conditions:templateContext}).then((_ref=>{let{html:html,js:js}=_ref;const conditionsjs=_jquery.default.parseHTML(templateContext.javascript,null,!0).map((node=>node.innerHTML)).join("\n");_templates.default.replaceNode(settingsConditionsRegion,html,js+conditionsjs),initConditionsForm();const reportAddCondition=reportElement.querySelector(reportSelectors.actions.reportAddCondition);return null==reportAddCondition||reportAddCondition.focus(),pendingPromise.resolve()}))},initConditionsForm=()=>{_custom_interaction_events.default.define(reportSelectors.actions.reportAddCondition,[_custom_interaction_events.default.events.accessibleChange]);const reportElement=document.querySelector(reportSelectors.regions.report),conditionFormContainer=reportElement.querySelector(reportSelectors.regions.settingsConditions);if(!conditionFormContainer)return;const conditionForm=new _dynamicform.default(conditionFormContainer,"\\core_reportbuilder\\form\\condition");conditionForm.addEventListener(conditionForm.events.FORM_SUBMITTED,(event=>{event.preventDefault(),(0,_str.get_string)("conditionsapplied","core_reportbuilder").then(_toast.add).catch(_notification.default.exception),(0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement)})),conditionForm.addEventListener(conditionForm.events.NOSUBMIT_BUTTON_PRESSED,(event=>{event.preventDefault(),_notification.default.saveCancelPromise((0,_str.get_string)("resetconditions","core_reportbuilder"),(0,_str.get_string)("resetconditionsconfirm","core_reportbuilder"),(0,_str.get_string)("resetall","core_reportbuilder"),{triggerElement:event.detail}).then((()=>{const pendingPromise=new _pending.default("core_reportbuilder/conditions:reset");return(0,_conditions.resetConditions)(reportElement.dataset.reportId).then((data=>reloadSettingsConditionsRegion(reportElement,data))).then((()=>(0,_toast.add)((0,_str.get_string)("conditionsreset","core_reportbuilder")))).then((()=>((0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement),pendingPromise.resolve()))).catch(_notification.default.exception)})).catch((()=>{}))}))};_exports.init=initialized=>{((0,_prefetch.prefetchStrings)("core_reportbuilder",["conditionadded","conditiondeleted","conditionmoved","conditionsapplied","conditionsreset","deletecondition","deleteconditionconfirm","resetall","resetconditions","resetconditionsconfirm"]),(0,_prefetch.prefetchStrings)("core",["delete"]),initConditionsForm(),initialized)||((0,_jquery.default)(document).on(_custom_interaction_events.default.events.accessibleChange,reportSelectors.actions.reportAddCondition,(event=>{const reportAddCondition=event.target.closest(reportSelectors.actions.reportAddCondition);if(reportAddCondition){if(event.preventDefault(),0===reportAddCondition.selectedIndex)return;const reportElement=reportAddCondition.closest(reportSelectors.regions.report),pendingPromise=new _pending.default("core_reportbuilder/conditions:add");(0,_conditions.addCondition)(reportElement.dataset.reportId,reportAddCondition.value).then((data=>reloadSettingsConditionsRegion(reportElement,data))).then((()=>(0,_str.get_string)("conditionadded","core_reportbuilder",reportAddCondition.options[reportAddCondition.selectedIndex].text))).then(_toast.add).then((()=>((0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement),pendingPromise.resolve()))).catch(_notification.default.exception)}})),document.addEventListener("click",(event=>{const reportRemoveCondition=event.target.closest(reportSelectors.actions.reportRemoveCondition);if(reportRemoveCondition){event.preventDefault();const reportElement=reportRemoveCondition.closest(reportSelectors.regions.report),conditionContainer=reportRemoveCondition.closest(reportSelectors.regions.activeCondition),conditionName=conditionContainer.dataset.conditionName;_notification.default.saveCancelPromise((0,_str.get_string)("deletecondition","core_reportbuilder",conditionName),(0,_str.get_string)("deleteconditionconfirm","core_reportbuilder",conditionName),(0,_str.get_string)("delete","core"),{triggerElement:reportRemoveCondition}).then((()=>{const pendingPromise=new _pending.default("core_reportbuilder/conditions:remove");return(0,_conditions.deleteCondition)(reportElement.dataset.reportId,conditionContainer.dataset.conditionId).then((data=>reloadSettingsConditionsRegion(reportElement,data))).then((()=>(0,_toast.add)((0,_str.get_string)("conditiondeleted","core_reportbuilder",conditionName)))).then((()=>((0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement),pendingPromise.resolve()))).catch(_notification.default.exception)})).catch((()=>{}))}})),new _sortable_list.default("".concat(reportSelectors.regions.activeConditions),{isHorizontal:!1}).getElementName=element=>Promise.resolve(element.data("conditionName")),(0,_jquery.default)(document).on(_sortable_list.default.EVENTS.DROP,reportSelectors.regions.activeCondition,((event,info)=>{if(info.positionChanged){const pendingPromise=new _pending.default("core_reportbuilder/conditions:reorder"),reportElement=event.target.closest(reportSelectors.regions.report),conditionId=info.element.data("conditionId"),conditionPosition=info.element.data("conditionPosition");let targetConditionPosition=info.targetNextElement.data("conditionPosition")||info.element.siblings().length+2;targetConditionPosition>conditionPosition&&targetConditionPosition--,(0,_conditions.reorderCondition)(reportElement.dataset.reportId,conditionId,targetConditionPosition).then((data=>reloadSettingsConditionsRegion(reportElement,data))).then((()=>(0,_str.get_string)("conditionmoved","core_reportbuilder",info.element.data("conditionName")))).then(_toast.add).then((()=>((0,_event_dispatcher.dispatchEvent)(reportEvents.tableReload,{},reportElement),pendingPromise.resolve()))).catch(_notification.default.exception)}})))}})); //# sourceMappingURL=conditions.min.js.map \ No newline at end of file diff --git a/reportbuilder/amd/build/local/editor/conditions.min.js.map b/reportbuilder/amd/build/local/editor/conditions.min.js.map index 5905df489e1..b8670246d7b 100644 --- a/reportbuilder/amd/build/local/editor/conditions.min.js.map +++ b/reportbuilder/amd/build/local/editor/conditions.min.js.map @@ -1 +1 @@ -{"version":3,"file":"conditions.min.js","sources":["../../../src/local/editor/conditions.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 * Report builder conditions editor\n *\n * @module core_reportbuilder/local/editor/conditions\n * @copyright 2021 Paul Holden \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport $ from 'jquery';\nimport CustomEvents from 'core/custom_interaction_events';\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport 'core/inplace_editable';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport {prefetchStrings} from 'core/prefetch';\nimport SortableList from 'core/sortable_list';\nimport {get_string as getString} from 'core/str';\nimport Templates from 'core/templates';\nimport {add as addToast} from 'core/toast';\nimport DynamicForm from 'core_form/dynamicform';\nimport * as reportEvents from 'core_reportbuilder/local/events';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {addCondition, deleteCondition, reorderCondition, resetConditions} from 'core_reportbuilder/local/repository/conditions';\n\n/**\n * Reload conditions settings region\n *\n * @param {Element} reportElement\n * @param {Object} templateContext\n * @return {Promise}\n */\nconst reloadSettingsConditionsRegion = (reportElement, templateContext) => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reload');\n const settingsConditionsRegion = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n\n return Templates.renderForPromise('core_reportbuilder/local/settings/conditions', {conditions: templateContext})\n .then(({html, js}) => {\n Templates.replaceNode(settingsConditionsRegion, html, js + templateContext.javascript);\n\n initConditionsForm();\n\n // Re-focus the add condition element after reloading the region.\n const reportAddCondition = reportElement.querySelector(reportSelectors.actions.reportAddCondition);\n reportAddCondition?.focus();\n\n return pendingPromise.resolve();\n });\n};\n\n/**\n * Initialise conditions form, must be called on each init because the form container is re-created when switching editor modes\n */\nconst initConditionsForm = () => {\n CustomEvents.define(reportSelectors.actions.reportAddCondition, [CustomEvents.events.accessibleChange]);\n\n // Handle dynamic conditions form.\n const reportElement = document.querySelector(reportSelectors.regions.report);\n const conditionFormContainer = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n if (!conditionFormContainer) {\n return;\n }\n const conditionForm = new DynamicForm(conditionFormContainer, '\\\\core_reportbuilder\\\\form\\\\condition');\n\n // Submit report conditions.\n conditionForm.addEventListener(conditionForm.events.FORM_SUBMITTED, event => {\n event.preventDefault();\n\n getString('conditionsapplied', 'core_reportbuilder')\n .then(addToast)\n .catch(Notification.exception);\n\n // After the form has been submitted, we should trigger report table reload.\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n });\n\n // Reset report conditions.\n conditionForm.addEventListener(conditionForm.events.NOSUBMIT_BUTTON_PRESSED, event => {\n event.preventDefault();\n\n Notification.saveCancelPromise(\n getString('resetconditions', 'core_reportbuilder'),\n getString('resetconditionsconfirm', 'core_reportbuilder'),\n getString('resetall', 'core_reportbuilder'),\n {triggerElement: event.detail}\n ).then(() => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reset');\n\n return resetConditions(reportElement.dataset.reportId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => addToast(getString('conditionsreset', 'core_reportbuilder')))\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }).catch(() => {\n return;\n });\n });\n};\n\n/**\n * Initialise module, prefetch all required strings\n *\n * @param {Boolean} initialized Ensure we only add our listeners once\n */\nexport const init = initialized => {\n prefetchStrings('core_reportbuilder', [\n 'conditionadded',\n 'conditiondeleted',\n 'conditionmoved',\n 'conditionsapplied',\n 'conditionsreset',\n 'deletecondition',\n 'deleteconditionconfirm',\n 'resetall',\n 'resetconditions',\n 'resetconditionsconfirm',\n ]);\n\n prefetchStrings('core', [\n 'delete',\n ]);\n\n initConditionsForm();\n if (initialized) {\n return;\n }\n\n // Add condition to report. Use custom events helper to ensure consistency across platforms.\n $(document).on(CustomEvents.events.accessibleChange, reportSelectors.actions.reportAddCondition, event => {\n const reportAddCondition = event.target.closest(reportSelectors.actions.reportAddCondition);\n if (reportAddCondition) {\n event.preventDefault();\n\n // Check if dropdown is closed with no condition selected.\n if (reportAddCondition.selectedIndex === 0) {\n return;\n }\n\n const reportElement = reportAddCondition.closest(reportSelectors.regions.report);\n const pendingPromise = new Pending('core_reportbuilder/conditions:add');\n\n addCondition(reportElement.dataset.reportId, reportAddCondition.value)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionadded', 'core_reportbuilder',\n reportAddCondition.options[reportAddCondition.selectedIndex].text))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n });\n\n document.addEventListener('click', event => {\n\n // Remove condition from report.\n const reportRemoveCondition = event.target.closest(reportSelectors.actions.reportRemoveCondition);\n if (reportRemoveCondition) {\n event.preventDefault();\n\n const reportElement = reportRemoveCondition.closest(reportSelectors.regions.report);\n const conditionContainer = reportRemoveCondition.closest(reportSelectors.regions.activeCondition);\n const conditionName = conditionContainer.dataset.conditionName;\n\n Notification.saveCancelPromise(\n getString('deletecondition', 'core_reportbuilder', conditionName),\n getString('deleteconditionconfirm', 'core_reportbuilder', conditionName),\n getString('delete', 'core'),\n {triggerElement: reportRemoveCondition}\n ).then(() => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:remove');\n\n return deleteCondition(reportElement.dataset.reportId, conditionContainer.dataset.conditionId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => addToast(getString('conditiondeleted', 'core_reportbuilder', conditionName)))\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }).catch(() => {\n return;\n });\n }\n });\n\n // Initialize sortable list to handle active conditions moving (note JQuery dependency, see MDL-72293 for resolution).\n var activeConditionsSortableList = new SortableList(`${reportSelectors.regions.activeConditions}`,\n {isHorizontal: false});\n activeConditionsSortableList.getElementName = element => Promise.resolve(element.data('conditionName'));\n\n $(document).on(SortableList.EVENTS.DROP, reportSelectors.regions.activeCondition, (event, info) => {\n if (info.positionChanged) {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reorder');\n const reportElement = event.target.closest(reportSelectors.regions.report);\n const conditionId = info.element.data('conditionId');\n const conditionPosition = info.element.data('conditionPosition');\n\n // Select target position, if moving to the end then count number of element siblings.\n let targetConditionPosition = info.targetNextElement.data('conditionPosition') || info.element.siblings().length + 2;\n if (targetConditionPosition > conditionPosition) {\n targetConditionPosition--;\n }\n\n reorderCondition(reportElement.dataset.reportId, conditionId, targetConditionPosition)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionmoved', 'core_reportbuilder', info.element.data('conditionName')))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n });\n};\n"],"names":["reloadSettingsConditionsRegion","reportElement","templateContext","pendingPromise","Pending","settingsConditionsRegion","querySelector","reportSelectors","regions","settingsConditions","Templates","renderForPromise","conditions","then","_ref","html","js","replaceNode","javascript","initConditionsForm","reportAddCondition","actions","focus","resolve","define","CustomEvents","events","accessibleChange","document","report","conditionFormContainer","conditionForm","DynamicForm","addEventListener","FORM_SUBMITTED","event","preventDefault","addToast","catch","Notification","exception","reportEvents","tableReload","NOSUBMIT_BUTTON_PRESSED","saveCancelPromise","triggerElement","detail","dataset","reportId","data","initialized","on","target","closest","selectedIndex","value","options","text","reportRemoveCondition","conditionContainer","activeCondition","conditionName","conditionId","SortableList","activeConditions","isHorizontal","getElementName","element","Promise","EVENTS","DROP","info","positionChanged","conditionPosition","targetConditionPosition","targetNextElement","siblings","length"],"mappings":"qqEAgDMA,+BAAiC,CAACC,cAAeC,yBAC7CC,eAAiB,IAAIC,iBAAQ,wCAC7BC,yBAA2BJ,cAAcK,cAAcC,gBAAgBC,QAAQC,2BAE9EC,mBAAUC,iBAAiB,+CAAgD,CAACC,WAAYV,kBAC1FW,MAAKC,WAACC,KAACA,KAADC,GAAOA,4BACAC,YAAYZ,yBAA0BU,KAAMC,GA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AAaM,OAAOC,KAAM/D,gBAAgBC,QAAQoD,iBAAiB,CAACzB,MAAOoC,WAClFA,KAAKC,gBAAiB,OAChBrE,eAAiB,IAAIC,iBAAQ,yCAC7BH,cAAgBkC,MAAMiB,OAAOC,QAAQ9C,gBAAgBC,QAAQqB,QAC7DiC,YAAcS,KAAKJ,QAAQlB,KAAK,eAChCwB,kBAAoBF,KAAKJ,QAAQlB,KAAK,yBAGxCyB,wBAA0BH,KAAKI,kBAAkB1B,KAAK,sBAAwBsB,KAAKJ,QAAQS,WAAWC,OAAS,EAC/GH,wBAA0BD,mBAC1BC,2DAGazE,cAAc8C,QAAQC,SAAUc,YAAaY,yBACzD7D,MAAKoC,MAAQjD,+BAA+BC,cAAegD,QAC3DpC,MAAK,KAAM,mBAAU,iBAAkB,qBAAsB0D,KAAKJ,QAAQlB,KAAK,oBAC/EpC,KAAKwB,YACLxB,MAAK,yCACY4B,aAAaC,YAAa,GAAIzC,eACrCE,eAAeoB,aAEzBe,MAAMC,sBAAaC"} \ No newline at end of file +{"version":3,"file":"conditions.min.js","sources":["../../../src/local/editor/conditions.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 * Report builder conditions editor\n *\n * @module core_reportbuilder/local/editor/conditions\n * @copyright 2021 Paul Holden \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\"use strict\";\n\nimport $ from 'jquery';\nimport CustomEvents from 'core/custom_interaction_events';\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport 'core/inplace_editable';\nimport Notification from 'core/notification';\nimport Pending from 'core/pending';\nimport {prefetchStrings} from 'core/prefetch';\nimport SortableList from 'core/sortable_list';\nimport {get_string as getString} from 'core/str';\nimport Templates from 'core/templates';\nimport {add as addToast} from 'core/toast';\nimport DynamicForm from 'core_form/dynamicform';\nimport * as reportEvents from 'core_reportbuilder/local/events';\nimport * as reportSelectors from 'core_reportbuilder/local/selectors';\nimport {addCondition, deleteCondition, reorderCondition, resetConditions} from 'core_reportbuilder/local/repository/conditions';\n\n/**\n * Reload conditions settings region\n *\n * @param {Element} reportElement\n * @param {Object} templateContext\n * @return {Promise}\n */\nconst reloadSettingsConditionsRegion = (reportElement, templateContext) => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reload');\n const settingsConditionsRegion = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n\n return Templates.renderForPromise('core_reportbuilder/local/settings/conditions', {conditions: templateContext})\n .then(({html, js}) => {\n const conditionsjs = $.parseHTML(templateContext.javascript, null, true).map(node => node.innerHTML).join(\"\\n\");\n Templates.replaceNode(settingsConditionsRegion, html, js + conditionsjs);\n\n initConditionsForm();\n\n // Re-focus the add condition element after reloading the region.\n const reportAddCondition = reportElement.querySelector(reportSelectors.actions.reportAddCondition);\n reportAddCondition?.focus();\n\n return pendingPromise.resolve();\n });\n};\n\n/**\n * Initialise conditions form, must be called on each init because the form container is re-created when switching editor modes\n */\nconst initConditionsForm = () => {\n CustomEvents.define(reportSelectors.actions.reportAddCondition, [CustomEvents.events.accessibleChange]);\n\n // Handle dynamic conditions form.\n const reportElement = document.querySelector(reportSelectors.regions.report);\n const conditionFormContainer = reportElement.querySelector(reportSelectors.regions.settingsConditions);\n if (!conditionFormContainer) {\n return;\n }\n const conditionForm = new DynamicForm(conditionFormContainer, '\\\\core_reportbuilder\\\\form\\\\condition');\n\n // Submit report conditions.\n conditionForm.addEventListener(conditionForm.events.FORM_SUBMITTED, event => {\n event.preventDefault();\n\n getString('conditionsapplied', 'core_reportbuilder')\n .then(addToast)\n .catch(Notification.exception);\n\n // After the form has been submitted, we should trigger report table reload.\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n });\n\n // Reset report conditions.\n conditionForm.addEventListener(conditionForm.events.NOSUBMIT_BUTTON_PRESSED, event => {\n event.preventDefault();\n\n Notification.saveCancelPromise(\n getString('resetconditions', 'core_reportbuilder'),\n getString('resetconditionsconfirm', 'core_reportbuilder'),\n getString('resetall', 'core_reportbuilder'),\n {triggerElement: event.detail}\n ).then(() => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reset');\n\n return resetConditions(reportElement.dataset.reportId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => addToast(getString('conditionsreset', 'core_reportbuilder')))\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }).catch(() => {\n return;\n });\n });\n};\n\n/**\n * Initialise module, prefetch all required strings\n *\n * @param {Boolean} initialized Ensure we only add our listeners once\n */\nexport const init = initialized => {\n prefetchStrings('core_reportbuilder', [\n 'conditionadded',\n 'conditiondeleted',\n 'conditionmoved',\n 'conditionsapplied',\n 'conditionsreset',\n 'deletecondition',\n 'deleteconditionconfirm',\n 'resetall',\n 'resetconditions',\n 'resetconditionsconfirm',\n ]);\n\n prefetchStrings('core', [\n 'delete',\n ]);\n\n initConditionsForm();\n if (initialized) {\n return;\n }\n\n // Add condition to report. Use custom events helper to ensure consistency across platforms.\n $(document).on(CustomEvents.events.accessibleChange, reportSelectors.actions.reportAddCondition, event => {\n const reportAddCondition = event.target.closest(reportSelectors.actions.reportAddCondition);\n if (reportAddCondition) {\n event.preventDefault();\n\n // Check if dropdown is closed with no condition selected.\n if (reportAddCondition.selectedIndex === 0) {\n return;\n }\n\n const reportElement = reportAddCondition.closest(reportSelectors.regions.report);\n const pendingPromise = new Pending('core_reportbuilder/conditions:add');\n\n addCondition(reportElement.dataset.reportId, reportAddCondition.value)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionadded', 'core_reportbuilder',\n reportAddCondition.options[reportAddCondition.selectedIndex].text))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n });\n\n document.addEventListener('click', event => {\n\n // Remove condition from report.\n const reportRemoveCondition = event.target.closest(reportSelectors.actions.reportRemoveCondition);\n if (reportRemoveCondition) {\n event.preventDefault();\n\n const reportElement = reportRemoveCondition.closest(reportSelectors.regions.report);\n const conditionContainer = reportRemoveCondition.closest(reportSelectors.regions.activeCondition);\n const conditionName = conditionContainer.dataset.conditionName;\n\n Notification.saveCancelPromise(\n getString('deletecondition', 'core_reportbuilder', conditionName),\n getString('deleteconditionconfirm', 'core_reportbuilder', conditionName),\n getString('delete', 'core'),\n {triggerElement: reportRemoveCondition}\n ).then(() => {\n const pendingPromise = new Pending('core_reportbuilder/conditions:remove');\n\n return deleteCondition(reportElement.dataset.reportId, conditionContainer.dataset.conditionId)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => addToast(getString('conditiondeleted', 'core_reportbuilder', conditionName)))\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }).catch(() => {\n return;\n });\n }\n });\n\n // Initialize sortable list to handle active conditions moving (note JQuery dependency, see MDL-72293 for resolution).\n var activeConditionsSortableList = new SortableList(`${reportSelectors.regions.activeConditions}`,\n {isHorizontal: false});\n activeConditionsSortableList.getElementName = element => Promise.resolve(element.data('conditionName'));\n\n $(document).on(SortableList.EVENTS.DROP, reportSelectors.regions.activeCondition, (event, info) => {\n if (info.positionChanged) {\n const pendingPromise = new Pending('core_reportbuilder/conditions:reorder');\n const reportElement = event.target.closest(reportSelectors.regions.report);\n const conditionId = info.element.data('conditionId');\n const conditionPosition = info.element.data('conditionPosition');\n\n // Select target position, if moving to the end then count number of element siblings.\n let targetConditionPosition = info.targetNextElement.data('conditionPosition') || info.element.siblings().length + 2;\n if (targetConditionPosition > conditionPosition) {\n targetConditionPosition--;\n }\n\n reorderCondition(reportElement.dataset.reportId, conditionId, targetConditionPosition)\n .then(data => reloadSettingsConditionsRegion(reportElement, data))\n .then(() => getString('conditionmoved', 'core_reportbuilder', info.element.data('conditionName')))\n .then(addToast)\n .then(() => {\n dispatchEvent(reportEvents.tableReload, {}, reportElement);\n return pendingPromise.resolve();\n })\n .catch(Notification.exception);\n }\n });\n};\n"],"names":["reloadSettingsConditionsRegion","reportElement","templateContext","pendingPromise","Pending","settingsConditionsRegion","querySelector","reportSelectors","regions","settingsConditions","Templates","renderForPromise","conditions","then","_ref","html","js","conditionsjs","$","parseHTML","javascript","map","node","innerHTML","join","replaceNode","initConditionsForm","reportAddCondition","actions","focus","resolve","define","CustomEvents","events","accessibleChange","document","report","conditionFormContainer","conditionForm","DynamicForm","addEventListener","FORM_SUBMITTED","event","preventDefault","addToast","catch","Notification","exception","reportEvents","tableReload","NOSUBMIT_BUTTON_PRESSED","saveCancelPromise","triggerElement","detail","dataset","reportId","data","initialized","on","target","closest","selectedIndex","value","options","text","reportRemoveCondition","conditionContainer","activeCondition","conditionName","conditionId","SortableList","activeConditions","isHorizontal","getElementName","element","Promise","EVENTS","DROP","info","positionChanged","conditionPosition","targetConditionPosition","targetNextElement","siblings","length"],"mappings":"qqEAgDMA,+BAAiC,CAACC,cAAeC,yBAC7CC,eAAiB,IAAIC,iBAAQ,wCAC7BC,yBAA2BJ,cAAcK,cAAcC,gBAAgBC,QAAQC,2BAE9EC,mBAAUC,iBAAiB,+CAAgD,CAACC,WAAYV,kBAC1FW,MAAKC,WAACC,KAACA,KAADC,GAAOA,eACJC,aAAeC,gBAAEC,UAAUjB,gBAAgBkB,WAAY,MAAM,GAAMC,KAAIC,MAAQA,KAAKC,YAAWC,KAAK,yBAChGC,YAAYpB,yBAA0BU,KAAMC,GAAKC,cAE3DS,2BAGMC,mBAAqB1B,cAAcK,cAAcC,gBAAgBqB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,MAAOoC,WAClFA,KAAKC,gBAAiB,OAChB5E,eAAiB,IAAIC,iBAAQ,yCAC7BH,cAAgByC,MAAMiB,OAAOC,QAAQrD,gBAAgBC,QAAQ4B,QAC7DiC,YAAcS,KAAKJ,QAAQlB,KAAK,eAChCwB,kBAAoBF,KAAKJ,QAAQlB,KAAK,yBAGxCyB,wBAA0BH,KAAKI,kBAAkB1B,KAAK,sBAAwBsB,KAAKJ,QAAQS,WAAWC,OAAS,EAC/GH,wBAA0BD,mBAC1BC,2DAGahF,cAAcqD,QAAQC,SAAUc,YAAaY,yBACzDpE,MAAK2C,MAAQxD,+BAA+BC,cAAeuD,QAC3D3C,MAAK,KAAM,mBAAU,iBAAkB,qBAAsBiE,KAAKJ,QAAQlB,KAAK,oBAC/E3C,KAAK+B,YACL/B,MAAK,yCACYmC,aAAaC,YAAa,GAAIhD,eACrCE,eAAe2B,aAEzBe,MAAMC,sBAAaC"} \ No newline at end of file diff --git a/reportbuilder/amd/src/editor.js b/reportbuilder/amd/src/editor.js index be04a21e018..029cd196a9c 100644 --- a/reportbuilder/amd/src/editor.js +++ b/reportbuilder/amd/src/editor.js @@ -23,6 +23,7 @@ "use strict"; +import $ from 'jquery'; import 'core/inplace_editable'; import {addIconToContainer} from 'core/loadingicon'; import Notification from 'core/notification'; @@ -68,17 +69,13 @@ export const init = () => { const pendingPromise = new Pending('core_reportbuilder/reports:get'); const toggledEditMode = toggleEditViewMode.dataset.editMode !== "1"; - let customjs = ''; - addIconToContainer(toggleEditViewMode) .then(() => getReport(reportElement.dataset.reportId, toggledEditMode)) - .then(response => { - customjs = response.javascript; - return Templates.render('core_reportbuilder/local/dynamictabs/editor', response); - }) - .then((html, js) => { - return Templates.replaceNode(reportElement, html, js + customjs); - }) + .then(response => Promise.all([ + $.parseHTML(response.javascript, null, true).map(node => node.innerHTML).join("\n"), + Templates.renderForPromise('core_reportbuilder/local/dynamictabs/editor', response), + ])) + .then(([responseJs, {html, js}]) => Templates.replaceNode(reportElement, html, js + responseJs)) .then(() => pendingPromise.resolve()) .catch(Notification.exception); } diff --git a/reportbuilder/amd/src/local/editor/conditions.js b/reportbuilder/amd/src/local/editor/conditions.js index 53f84f0f3fc..c6efbbbcd87 100644 --- a/reportbuilder/amd/src/local/editor/conditions.js +++ b/reportbuilder/amd/src/local/editor/conditions.js @@ -52,7 +52,8 @@ const reloadSettingsConditionsRegion = (reportElement, templateContext) => { return Templates.renderForPromise('core_reportbuilder/local/settings/conditions', {conditions: templateContext}) .then(({html, js}) => { - Templates.replaceNode(settingsConditionsRegion, html, js + templateContext.javascript); + const conditionsjs = $.parseHTML(templateContext.javascript, null, true).map(node => node.innerHTML).join("\n"); + Templates.replaceNode(settingsConditionsRegion, html, js + conditionsjs); initConditionsForm();