{"version":3,"file":"placeholder.min.js","sources":["https:\/\/www.alsg.org\/home\/course\/format\/amd\/src\/local\/courseindex\/placeholder.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 * Course index placeholder replacer.\n *\n * @module core_courseformat\/local\/courseindex\/placeholder\n * @class core_courseformat\/local\/courseindex\/placeholder\n * @copyright 2021 Ferran Recio \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport {BaseComponent} from 'core\/reactive';\nimport Templates from 'core\/templates';\nimport {getCurrentCourseEditor} from 'core_courseformat\/courseeditor';\nimport Pending from 'core\/pending';\n\nexport default class Component extends BaseComponent {\n\n \/**\n * Static method to create a component instance form the mustache template.\n *\n * @param {element|string} target the DOM main element or its ID\n * @param {object} selectors optional css selector overrides\n * @return {Component}\n *\/\n static init(target, selectors) {\n return new Component({\n element: document.getElementById(target),\n reactive: getCurrentCourseEditor(),\n selectors,\n });\n }\n\n \/**\n * Component creation hook.\n *\/\n create() {\n \/\/ Add a pending operation waiting for the initial content.\n this.pendingContent = new Pending(`core_courseformat\/placeholder:loadcourseindex`);\n }\n\n \/**\n * Initial state ready method.\n *\n * This stateReady to be async because it loads the real courseindex.\n *\n * @param {object} state the initial state\n *\/\n async stateReady(state) {\n\n \/\/ Check if we have a static course index already loded from a previous page.\n if (!this.loadStaticContent()) {\n await this.loadTemplateContent(state);\n }\n }\n\n \/**\n * Load the course index from the session storage if any.\n *\n * @return {boolean} true if the static version is loaded form the session\n *\/\n loadStaticContent() {\n \/\/ Load the previous static course index from the session cache.\n const index = this.reactive.getStorageValue(`courseIndex`);\n if (index.html && index.js) {\n Templates.replaceNode(this.element, index.html, index.js);\n this.pendingContent.resolve();\n return true;\n }\n return false;\n }\n\n \/**\n * Load the course index template.\n *\n * @param {Object} state the initial state\n *\/\n async loadTemplateContent(state) {\n \/\/ Collect section information from the state.\n const exporter = this.reactive.getExporter();\n const data = exporter.course(state);\n try {\n \/\/ To render an HTML into our component we just use the regular Templates module.\n const {html, js} = await Templates.renderForPromise(\n 'core_courseformat\/local\/courseindex\/courseindex',\n data,\n );\n Templates.replaceNode(this.element, html, js);\n this.pendingContent.resolve();\n\n \/\/ Save the rendered template into the session cache.\n this.reactive.setStorageValue(`courseIndex`, {html, js});\n } catch (error) {\n this.pendingContent.resolve(error);\n throw error;\n }\n }\n}\n"],"names":["Component","BaseComponent","target","selectors","element","document","getElementById","reactive","create","pendingContent","Pending","state","this","loadStaticContent","loadTemplateContent","index","getStorageValue","html","js","replaceNode","resolve","data","getExporter","course","Templates","renderForPromise","setStorageValue","error"],"mappings":";;;;;;;;mLA6BqBA,kBAAkBC,oCASvBC,OAAQC,kBACT,IAAIH,UAAU,CACjBI,QAASC,SAASC,eAAeJ,QACjCK,UAAU,0CACVJ,UAAAA,YAORK,cAESC,eAAiB,IAAIC,mFAUbC,OAGRC,KAAKC,2BACAD,KAAKE,oBAAoBH,OASvCE,0BAEUE,MAAQH,KAAKL,SAASS,wCACxBD,MAAME,OAAQF,MAAMG,yBACVC,YAAYP,KAAKR,QAASW,MAAME,KAAMF,MAAMG,SACjDT,eAAeW,WACb,6BAUWT,aAGhBU,KADWT,KAAKL,SAASe,cACTC,OAAOZ,iBAGnBM,KAACA,KAADC,GAAOA,UAAYM,mBAAUC,iBAC\/B,kDACAJ,yBAEMF,YAAYP,KAAKR,QAASa,KAAMC,SACrCT,eAAeW,eAGfb,SAASmB,8BAA+B,CAACT,KAAAA,KAAMC,GAAAA,KACtD,MAAOS,kBACAlB,eAAeW,QAAQO,OACtBA"}