{"version":3,"file":"courseindex.min.js","sources":["https:\/\/moodle.tau.ac.il\/2023\/course\/format\/multitopic\/amd\/src\/courseformat\/courseindex\/courseindex.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 main component.\n *\n * @module format_multitopic\/courseformat\/courseindex\/courseindex\n * @class format_multitopic\/courseformat\/courseindex\/courseindex\n * @copyright 2022 James Calder and Otago Polytechnic\n * @copyright 2022 Jeremy FitzPatrick and Te W\u0101nanga o Aotearoa\n * @copyright based on work by 2021 Ferran Recio \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport BaseComponent from 'core_courseformat\/local\/courseindex\/courseindex';\nimport {getCurrentCourseEditor} from 'core_courseformat\/courseeditor';\n\nexport default class Component extends BaseComponent {\n\n create() {\n super.create();\n this.selectors.TOPSECTION = `[data-for='section'][data-indent='0']`;\n this.selectors.SECONDSECTIONS = `[data-for='section'][data-indent='1']`;\n this.selectors.THIRDSECTIONS = `[data-for='section'][data-indent='2']`;\n this.topsections = {};\n }\n\n \/**\n * Initial state ready method.\n *\n * @param {Object} state the state data\n *\/\n stateReady(state) {\n super.stateReady(state);\n \/\/ Get cms and sections elements.\n const topsections = this.getElements(this.selectors.TOPSECTION);\n topsections.forEach((section) => {\n this.topsections[section.dataset.id] = section;\n });\n }\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 this({\n element: document.getElementById(target),\n reactive: getCurrentCourseEditor(),\n selectors,\n });\n }\n\n \/**\n * Refresh the section list.\n *\n * @param {object} param\n * @param {Object} param.element\n *\/\n _refreshCourseSectionlist({element}) {\n const topsectionslist = element.firstsectionlist ?? [];\n this._fixOrder(this.element, topsectionslist, this.topsections);\n\n for (let p in element.secondsectionlist) {\n let secondorder = Array.from(element.secondsectionlist[p]);\n secondorder.shift(); \/\/ The first item is the parent to match the tabs.\n let container = this.getElement(\"[data-id='\" + p + \"'] > .collapse > .subsections\");\n let secondsections = container.querySelectorAll(this.selectors.SECONDSECTIONS);\n let secondsectionobj = {};\n secondsections.forEach((section) => {\n secondsectionobj[section.dataset.id] = section;\n });\n \/\/ First check we have all the subsections. If not move it here.\n for (let j = 0; j < secondorder.length; j++) {\n let itemid = secondorder[j];\n if (secondsectionobj[itemid] === undefined) {\n secondsectionobj[itemid] = this.sections[itemid];\n }\n }\n this._fixOrder(container, secondorder, secondsectionobj);\n }\n\n for (let p in element.thirdsectionlist) {\n let thirdorder = element.thirdsectionlist[p];\n let container = this.getElement(\"[data-id='\" + p + \"'] > .collapse > .topics\");\n let thirdsections = container.querySelectorAll(this.selectors.THIRDSECTIONS);\n let thirdsectionsobj = {};\n thirdsections.forEach((section) => {\n thirdsectionsobj[section.dataset.id] = section;\n });\n \/\/ First check we have all the topics. If not move it here.\n for (let j = 0; j < thirdorder.length; j++) {\n let itemid = thirdorder[j];\n if (thirdsectionsobj[itemid] === undefined) {\n thirdsectionsobj[itemid] = this.sections[itemid];\n }\n }\n this._fixOrder(container, thirdorder, thirdsectionsobj);\n }\n\n \/\/ Update URLs.\n const sectionsDom = this.element.querySelectorAll(this.selectors.SECTION);\n for (let sdi = 0; sdi < sectionsDom.length; sdi++) {\n const sectionDom = sectionsDom[sdi];\n const section = this.reactive.get(\"section\", sectionDom.dataset.id);\n if (!section) {\n continue;\n }\n const linkDom = sectionDom.querySelector(\"a.courseindex-link\");\n const link = section.sectionurl.replace(\"&\", \"&\");\n if (linkDom.href != link) {\n linkDom.href = link;\n }\n }\n }\n\n \/**\n * Create a new section instance.\n *\n * @param {Object} details the update details.\n * @param {Object} details.state the state data.\n * @param {Object} details.element the element data.\n *\/\n async _createSection({state, element}) {\n \/\/ Create a fake node while the component is loading.\n const fakeelement = document.createElement('div');\n fakeelement.classList.add('bg-pulse-grey', 'w-100');\n fakeelement.innerHTML = ' ';\n this.sections[element.id] = fakeelement;\n \/\/ Place the fake node on the correct position.\n this._refreshCourseSectionlist({\n state,\n element: state.course,\n });\n \/\/ Collect render data.\n const exporter = this.reactive.getExporter();\n const data = exporter.section(state, element);\n \/\/ Create the new content.\n const newcomponent = await this.renderComponent(fakeelement, 'format_multitopic\/courseformat\/courseindex\/section', data);\n \/\/ CHANGED LINE ABOVE.\n \/\/ Replace the fake node with the real content.\n const newelement = newcomponent.getElement();\n this.sections[element.id] = newelement;\n fakeelement.parentNode.replaceChild(newelement, fakeelement);\n }\n\n}"],"names":["Component","BaseComponent","create","selectors","TOPSECTION","SECONDSECTIONS","THIRDSECTIONS","topsections","stateReady","state","this","getElements","forEach","section","dataset","id","target","element","document","getElementById","reactive","_refreshCourseSectionlist","topsectionslist","firstsectionlist","_fixOrder","p","secondsectionlist","secondorder","Array","from","shift","container","getElement","secondsections","querySelectorAll","secondsectionobj","j","length","itemid","undefined","sections","thirdsectionlist","thirdorder","thirdsections","thirdsectionsobj","sectionsDom","SECTION","sdi","sectionDom","get","linkDom","querySelector","link","sectionurl","replace","href","fakeelement","createElement","classList","add","innerHTML","course","data","getExporter","newelement","renderComponent","parentNode","replaceChild"],"mappings":";;;;;;;;;;6JA6BqBA,kBAAkBC,qBAEnCC,eACUA,cACDC,UAAUC,wDACVD,UAAUE,4DACVF,UAAUG,2DACVC,YAAc,GAQvBC,WAAWC,aACDD,WAAWC,OAEGC,KAAKC,YAAYD,KAAKP,UAAUC,YACxCQ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