{"version":3,"file":"content.min.js","sources":["https:\/\/moodle.tau.ac.il\/2023\/course\/format\/topcoll\/amd\/src\/local\/content.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 * Collapsed Topics Course index main component.\n *\n * @module format_topcoll\/local\/content\n * @class format_topcoll\/local\/content\n * @copyright 2022 G J Barnard based upon work done by:\n * @copyright 2020 Ferran Recio \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport Component from 'core_courseformat\/local\/content';\nimport {getCurrentCourseEditor} from 'core_courseformat\/courseeditor';\n\nexport default class TopcollComponent extends Component {\n\n \/**\n * Constructor hook.\n *\n * @param {Object} descriptor the component descriptor\n *\/\n create(descriptor) {\n super.create(descriptor);\n }\n\n \/**\n * Static method to create a component instance form the mustahce template.\n *\n * @param {string} target the DOM main element or its ID\n * @param {object} selectors optional css selector overrides\n * @param {number} sectionReturn the content section return\n * @return {Component}\n *\/\n static init(target, selectors, sectionReturn) {\n return new TopcollComponent({\n element: document.getElementById(target),\n reactive: getCurrentCourseEditor(),\n selectors,\n sectionReturn,\n });\n }\n\n \/**\n * Return the component watchers.\n *\n * @returns {Array} of watchers\n *\/\n getWatchers() {\n \/\/ Section return is a global page variable but most formats define it just before start printing\n \/\/ the course content. This is the reason why we define this page setting here.\n this.reactive.sectionReturn = this.sectionReturn;\n\n \/\/ Check if the course format is compatible with reactive components.\n if (!this.reactive.supportComponents) {\n return [];\n }\n return [\n \/\/ State changes that require to reload some course modules.\n {watch: `cm.visible:updated`, handler: this._reloadCm},\n {watch: `cm.stealth:updated`, handler: this._reloadCm},\n \/\/ Update section number and title.\n {watch: `section.number:updated`, handler: this._refreshSectionNumber},\n \/\/ Sections and cm sorting.\n {watch: `transaction:start`, handler: this._startProcessing},\n {watch: `course.sectionlist:updated`, handler: this._refreshCourseSectionlist},\n {watch: `section.cmlist:updated`, handler: this._refreshSectionCmlist},\n \/\/ Reindex sections and cms.\n {watch: `state:updated`, handler: this._indexContents},\n \/\/ State changes thaty require to reload course modules.\n {watch: `cm.visible:updated`, handler: this._reloadCm},\n {watch: `cm.sectionid:updated`, handler: this._reloadCm},\n ];\n }\n\n \/**\n * Refresh the section list.\n *\n * @param {Object} param\n * @param {Object} param.element details the update details.\n *\/\n _refreshCourseSectionlist({element}) {\n \/\/ If we have a section return means we only show a single section so no need to fix order.\n if (this.reactive.sectionReturn != 0) {\n return;\n }\n const sectionlist = element.sectionlist.slice(1) ?? []; \/\/ Remove section 0 from the list!\n const listparent = this.getElement(this.selectors.COURSE_SECTIONLIST);\n \/\/ For now section cannot be created at a frontend level.\n const createSection = this._createSectionItem.bind(this);\n if (listparent) {\n this._fixTopcollSectionOrder(listparent, sectionlist, this.selectors.SECTION, this.dettachedSections, createSection);\n }\n }\n\n \/**\n * Fix\/reorder the section or cms order.\n *\n * @param {Element} container the HTML element to reorder.\n * @param {Array} neworder an array with the ids order\n * @param {string} selector the element selector\n * @param {Object} dettachedelements a list of dettached elements\n * @param {function} createMethod method to create missing elements\n *\/\n async _fixTopcollSectionOrder(container, neworder, selector, dettachedelements, createMethod) {\n if (!container) {\n return;\n }\n\n \/\/ Empty lists should not be visible.\n if (!neworder.length) {\n container.classList.add('hidden');\n container.innerHTML = '';\n return;\n }\n\n \/\/ Grant the list is visible (in case it was empty).\n container.classList.remove('hidden');\n\n \/\/ Move the elements in order at the beginning of the list.\n neworder.forEach((itemid, index) => {\n let item = this.getElement(selector, itemid) ?? dettachedelements[itemid] ?? createMethod(container, itemid);\n if (!item) {\n \/\/ Missing elements cannot be sorted.\n return;\n }\n let itemno = this.getElement('#tcnoid-'+itemid);\n if (itemno) {\n itemno.textContent = index + 1; \/\/ Update the section number in the 'left' part.\n }\n \/\/ Get the current elemnt at that position.\n const currentitem = container.children[index];\n if (!currentitem) {\n container.append(item);\n return;\n }\n if (currentitem !== item) {\n container.insertBefore(item, currentitem);\n }\n });\n\n \/\/ Dndupload add a fake element we need to keep.\n let dndFakeActivity;\n\n \/\/ Remove the remaining elements.\n while (container.children.length > neworder.length) {\n const lastchild = container.lastChild;\n if (lastchild?.classList?.contains('dndupload-preview')) {\n dndFakeActivity = lastchild;\n } else {\n dettachedelements[lastchild?.dataset?.id ?? 0] = lastchild;\n }\n container.removeChild(lastchild);\n }\n \/\/ Restore dndupload fake element.\n if (dndFakeActivity) {\n container.append(dndFakeActivity);\n }\n }\n}\n"],"names":["TopcollComponent","descriptor","reactive","sectionReturn","this","supportComponents","watch","handler","_reloadCm","_refreshSectionNumber","_startProcessing","_refreshCourseSectionlist","_refreshSectionCmlist","_indexContents","element","sectionlist","slice","listparent","getElement","selectors","COURSE_SECTIONLIST","createSection","_createSectionItem","bind","_fixTopcollSectionOrder","SECTION","dettachedSections","container","neworder","selector","dettachedelements","createMethod","length","classList","add","innerHTML","remove","forEach","itemid","index","item","_this","itemno","textContent","currentitem","children","insertBefore","append","lastchild","lastChild","_lastchild$classList","contains","dndFakeActivity","dataset","_lastchild$dataset","id","removeChild","target","document","getElementById"],"mappings":"wnFA4BqBA,60BAOjB,SAAOC,sFACUA,uCAyBjB,uBAGSC,SAASC,cAAgBC,KAAKD,cAG9BC,KAAKF,SAASG,kBAGZ,CAEH,CAACC,2BAA6BC,QAASH,KAAKI,WAC5C,CAACF,2BAA6BC,QAASH,KAAKI,WAE5C,CAACF,+BAAiCC,QAASH,KAAKK,uBAEhD,CAACH,0BAA4BC,QAASH,KAAKM,kBAC3C,C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