{"version":3,"file":"mutations.min.js","sources":["https:\/\/moodle.tau.ac.il\/2023\/course\/format\/multitopic\/amd\/src\/courseformat\/courseeditor\/mutations.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 * Format Multitopic mutations.\n *\n * An instance of this class will be used to add custom mutations to the course editor.\n * To make sure the addMutations method find the proper functions, all functions must\n * be declared as class attributes, not a simple methods. The reason is because many\n * plugins can add extra mutations to the course editor.\n *\n * @module format_multitopic\/courseformat\/courseeditor\/mutations\n * @copyright 2022 onwards James Calder and Otago Polytechnic\n * @copyright based on work by 2021 onwards Ferran Recio \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport {getCurrentCourseEditor} from 'core_courseformat\/courseeditor';\nimport DefaultMutations from 'core_courseformat\/local\/courseeditor\/mutations';\n\nclass MultitopicMutations extends DefaultMutations {\n\n \/**\n * Move course sections to specific course location.\n *\n * @param {StateManager} stateManager the current state manager\n * @param {array} sectionIds the list of section ids to move\n * @param {number} targetSectionId the target section id\n *\/\n sectionMove = async function(stateManager, sectionIds, targetSectionId) {\n if (!targetSectionId) {\n throw new Error(`Mutation sectionMove requires targetSectionId`);\n }\n const course = stateManager.get('course');\n \/\/ ADDED.\n let subsectionIds = [];\n for (const sectionId of sectionIds) {\n const section = stateManager.get(\"section\", sectionId);\n for (let subsection = section;\n subsection && (subsection.id == section.id || subsection.levelsan > section.levelsan);\n subsection = (course.sectionlist.length > subsection.number + 1) ?\n stateManager.get(\"section\", course.sectionlist[subsection.number + 1]) : null) {\n subsectionIds.push(subsection.id);\n }\n }\n \/\/ END ADDED.\n this.sectionLock(stateManager, subsectionIds, true);\n const updates = await this._callEditWebservice('section_move', course.id, sectionIds, targetSectionId);\n if (typeof this.bulkReset === \"function\") {\n this.bulkReset(stateManager);\n }\n stateManager.processUpdates(updates);\n this.sectionLock(stateManager, subsectionIds, false);\n };\n\n \/**\n * Move course sections after a specific course location.\n *\n * @param {StateManager} stateManager the current state manager\n * @param {array} sectionIds the list of section ids to move\n * @param {number} targetSectionId the target section id\n *\/\n sectionMoveAfter = async function(stateManager, sectionIds, targetSectionId) {\n if (!targetSectionId) {\n throw new Error(`Mutation sectionMoveAfter requires targetSectionId`);\n }\n const course = stateManager.get('course');\n \/\/ ADDED.\n let subsectionIds = [];\n for (const sectionId of sectionIds) {\n const section = stateManager.get(\"section\", sectionId);\n for (let subsection = section;\n subsection && (subsection.id == section.id || subsection.levelsan > section.levelsan);\n subsection = (course.sectionlist.length > subsection.number + 1) ?\n stateManager.get(\"section\", course.sectionlist[subsection.number + 1]) : null) {\n subsectionIds.push(subsection.id);\n }\n }\n \/\/ END ADDED.\n this.sectionLock(stateManager, subsectionIds, true);\n const updates = await this._callEditWebservice('section_move_after', course.id, sectionIds, targetSectionId);\n if (typeof this.bulkReset === \"function\") {\n this.bulkReset(stateManager);\n }\n stateManager.processUpdates(updates);\n this.sectionLock(stateManager, subsectionIds, false);\n };\n\n \/**\n * Move course sections into a specific course location.\n *\n * @param {StateManager} stateManager the current state manager\n * @param {array} sectionIds the list of section ids to move\n * @param {number} targetSectionId the target section id\n *\/\n fmtSectionMoveInto = async function(stateManager, sectionIds, targetSectionId) {\n if (!targetSectionId) {\n throw new Error(`Mutation sectionMoveInto requires targetSectionId`);\n }\n const course = stateManager.get('course');\n \/\/ ADDED.\n let subsectionIds = [];\n for (const sectionId of sectionIds) {\n const section = stateManager.get(\"section\", sectionId);\n for (let subsection = section;\n subsection && (subsection.id == section.id || subsection.levelsan > section.levelsan);\n subsection = (course.sectionlist.length > subsection.number + 1) ?\n stateManager.get(\"section\", course.sectionlist[subsection.number + 1]) : null) {\n subsectionIds.push(subsection.id);\n }\n }\n \/\/ END ADDED.\n this.sectionLock(stateManager, subsectionIds, true);\n const updates = await this._callEditWebservice('fmt_section_move_into', course.id, sectionIds, targetSectionId);\n if (typeof this.bulkReset === \"function\") {\n this.bulkReset(stateManager);\n }\n stateManager.processUpdates(updates);\n this.sectionLock(stateManager, subsectionIds, false);\n };\n\n}\n\nexport const init = () => {\n const courseEditor = getCurrentCourseEditor();\n \/\/ Some plugin (activity or block) may have their own mutations already registered.\n \/\/ This is why we use addMutations instead of setMutations here.\n courseEditor.addMutations(new MultitopicMutations());\n};\n"],"names":["MultitopicMutations","DefaultMutations","async","stateManager","sectionIds","targetSectionId","Error","course","get","subsectionIds","sectionId","section","subsection","id","levelsan","sectionlist","length","number","push","sectionLock","updates","this","_callEditWebservice","bulkReset","processUpdates","addMutations"],"mappings":"ugBAgCMA,4BAA4BC,yFAShBC,eAAeC,aAAcC,WAAYC,qBAC9CA,sBACK,IAAIC,6DAERC,OAASJ,aAAaK,IAAI,cAE5BC,cAAgB,OACf,MAAMC,aAAaN,WAAY,OAC1BO,QAAUR,aAAaK,IAAI,UAAWE,eACvC,IAAIE,WAAaD,QACdC,aAAeA,WAAWC,IAAMF,QAAQE,IAAMD,WAAWE,SAAWH,QAAQG,UAC5EF,WAAcL,OAAOQ,YAAYC,OAASJ,WAAWK,OAAS,EAC1Dd,aAAaK,IAAI,UAAWD,OAAOQ,YAAYH,WAAWK,OAAS,IAAM,KACjFR,cAAcS,KAAKN,WAAWC,SAIjCM,YAAYhB,aAAcM,eAAe,SACxCW,cAAgBC,KAAKC,oBAAoB,eAAgBf,OAAOM,GAAIT,WAAYC,iBACxD,mBAAnBgB,KAAKE,gBACPA,UAAUpB,cAEnBA,aAAaqB,eAAeJ,cAC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