{"version":3,"file":"tool_selector.min.js","sources":["https:\/\/moodle.sonsbeekmedia.nl\/caie_39\/mod\/teachingtools\/amd\/src\/tool_selector.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 * The App Changer module allows the user to change the teaching tool to\n * a compatible app.\n *\n * @module mod_teachingtools\/tool_selector\n * @copyright 2023 Bas Brands \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\nimport Templates from 'core\/templates';\nimport Ajax from 'core\/ajax';\nimport Notification from 'core\/notification';\n\nexport default class ToolSelector {\n\n constructor(rootElement, tool) {\n this.rootElement = rootElement;\n this.toolWrapper = this.rootElement.closest('[data-region=\"toolwrapper\"]');\n this.appSlider = this.rootElement.querySelector('.appslider');\n this.cmid = this.rootElement.dataset.cmid;\n this.addEventListeners();\n this.setCardActive(tool);\n }\n\n addEventListeners() {\n if (this.toolWrapper.dataset.changerInitialised) {\n return;\n }\n this.toolWrapper.addEventListener('click', (e) => {\n if (e.target.closest('[data-action=\"changetool\"]')) {\n const tool = e.target.closest('[data-action=\"changetool\"]').dataset.tool;\n this.change(tool);\n }\n });\n this.toolWrapper.dataset.changerInitialised = true;\n }\n\n setCardActive(tool) {\n const changer = this.toolWrapper.querySelectorAll('[data-action=\"changetool\"]');\n changer.forEach((changer) => {\n const card = changer.closest('.card');\n card.classList.remove('active');\n if (changer.dataset.tool === tool) {\n card.classList.add('active');\n }\n });\n }\n\n change(tool) {\n \/\/ Load the app template and javascript.\n const template = `teachingapp_${tool}\/teachingapp`;\n \/\/ Get how far the user has scrolled in the appslider.\n this.appSlider = this.toolWrapper.querySelector('.appslider');\n const scroll = this.appSlider.scrollLeft;\n this.getToolContext(tool, this.cmid).then((result) => {\n if (result.dataset) {\n const context = JSON.parse(result.dataset);\n Templates.render(template, context).then((html, js) => {\n Templates.replaceNodeContents(this.toolWrapper, html, js);\n \/\/ Restore the scroll position.\n this.appSlider = this.toolWrapper.querySelector('.appslider');\n this.appSlider.scrollLeft = scroll;\n const splashImage = document.querySelector('[data-type=\"splash\"]');\n if (splashImage) {\n splashImage.remove();\n }\n this.setCardActive(tool);\n return;\n }).catch();\n }\n return false;\n }).catch(Notification.exception);\n\n }\n\n getToolContext(tool) {\n \/\/ Store the label in the database\n var args = {\n 'cmid': this.cmid,\n 'tool': tool,\n };\n\n const request = {\n methodname: 'mod_teachingtools_tooldataset',\n args: args\n };\n\n let promise = Ajax.call([request])[0]\n .fail(Notification.exception);\n\n return promise;\n }\n}"],"names":["constructor","rootElement","tool","toolWrapper","this","closest","appSlider","querySelector","cmid","dataset","addEventListeners","setCardActive","changerInitialised","addEventListener","e","target","change","querySelectorAll","forEach","changer","card","classList","remove","add","template","scroll","scrollLeft","getToolContext","then","result","context","JSON","parse","render","html","js","replaceNodeContents","splashImage","document","catch","Notification","exception","request","methodname","args","Ajax","call","fail"],"mappings":";;;;;;;;yPA6BIA,YAAYC,YAAaC,WAChBD,YAAcA,iBACdE,YAAcC,KAAKH,YAAYI,QAAQ,oCACvCC,UAAYF,KAAKH,YAAYM,cAAc,mBAC3CC,KAAOJ,KAAKH,YAAYQ,QAAQD,UAChCE,yBACAC,cAAcT,MAGvBQ,oBACQN,KAAKD,YAAYM,QAAQG,0BAGxBT,YAAYU,iBAAiB,SAAUC,OACpCA,EAAEC,OAAOV,QAAQ,8BAA+B,OAC1CH,KAAOY,EAAEC,OAAOV,QAAQ,8BAA8BI,QAAQP,UAC\/Dc,OAAOd,eAGfC,YAAYM,QAAQG,oBAAqB,GAGlDD,cAAcT,MACME,KAAKD,YAAYc,iBAAiB,8BAC1CC,SAASC,gBACPC,KAAOD,QAAQd,QAAQ,SAC7Be,KAAKC,UAAUC,OAAO,UAClBH,QAAQV,QAAQP,OAASA,MACzBkB,KAAKC,UAAUE,IAAI,aAK\/BP,OAAOd,YAEGsB,+BAA0BtB,0BAE3BI,UAAYF,KAAKD,YAAYI,cAAc,oBAC1CkB,OAASrB,KAAKE,UAAUoB,gBACzBC,eAAezB,KAAME,KAAKI,MAAMoB,MAAMC,YACnCA,OAAOpB,QAAS,OACVqB,QAAUC,KAAKC,MAAMH,OAAOpB,4BACxBwB,OAAOT,SAAUM,SAASF,MAAK,CAACM,KAAMC,yBAClCC,oBAAoBhC,KAAKD,YAAa+B,KAAMC,SAEjD7B,UAAYF,KAAKD,YAAYI,cAAc,mBAC3CD,UAAUoB,WAAaD,aACtBY,YAAcC,SAAS\/B,cAAc,wBACvC8B,aACAA,YAAYf,cAEXX,cAAcT,SAEpBqC,eAEA,KACRA,MAAMC,sBAAaC,WAI1Bd,eAAezB,YAOLwC,QAAU,CACZC,WAAY,gCACZC,KAPO,MACCxC,KAAKI,UACLN,cAQE2C,cAAKC,KAAK,CAACJ,UAAU,GAC9BK,KAAKP,sBAAaC"}