3.23 KB
Newer Older
{"version":3,"sources":["../../../src/local/courseindex/placeholder.js"],"names":["Component","state","exporter","reactive","getExporter","data","course","Templates","renderForPromise","html","js","replaceNode","element","target","selectors","document","getElementById","BaseComponent"],"mappings":"yOAyBA,uD,87DAGqBA,CAAAA,C,wKAwBAC,C,iGAEPC,C,CAAW,KAAKC,QAAL,CAAcC,WAAd,E,CACXC,C,CAAOH,CAAQ,CAACI,MAAT,CAAgBL,CAAhB,C,yBAIgBM,WAAUC,gBAAV,CACrB,iDADqB,CAErBH,CAFqB,C,iBAAlBI,C,GAAAA,I,CAAMC,C,GAAAA,E,CAIbH,UAAUI,WAAV,CAAsB,KAAKC,OAA3B,CAAoCH,CAApC,CAA0CC,CAA1C,E,6NA1BIG,C,CAAQC,C,CAAW,CAC3B,MAAO,IAAId,CAAAA,CAAJ,CAAc,CACjBY,OAAO,CAAEG,QAAQ,CAACC,cAAT,CAAwBH,CAAxB,CADQ,CAEjBV,QAAQ,CAAE,8BAFO,CAGjBW,SAAS,CAATA,CAHiB,CAAd,CAKV,C,cAfkCG,e","sourcesContent":["// This file is part of Moodle -\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 GNU GPL v3 or later\n */\n\nimport {BaseComponent} from 'core/reactive';\nimport Templates from 'core/templates';\nimport {getCurrentCourseEditor} from 'core_courseformat/courseeditor';\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     * 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        // Collect section information from the state.\n        const exporter = this.reactive.getExporter();\n        const data = exporter.course(state);\n\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        } catch (error) {\n            throw error;\n        }\n    }\n}\n"],"file":"placeholder.min.js"}