Rev 1 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
{"version":3,"file":"dndsectionitem.min.js","sources":["../../../src/local/courseeditor/dndsectionitem.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 <http://www.gnu.org/licenses/>.\n\n/**\n * Course index section title draggable component.\n *\n * This component is used to control specific course section interactions like drag and drop\n * in both course index and course content
.\n *\n * @module core_courseformat/local/courseeditor/dndsectionitem\n * @class core_courseformat/local/courseeditor/dndsectionitem\n * @copyright 2021 Ferran Recio <ferran@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {BaseComponent, DragDrop} from 'core/reactive';\n\nexport default class extends BaseComponent {\n\n /**\n * Initial state ready method.\n *\n * @param {number} sectionid the section id\n * @param {Object} state the initial state\n * @param {Element} fullregion the complete section region to mark as dragged\n * @param {Boolean} isDndAllowed Whether drag and drop is allowed in this section.\n */\n configDragDrop(sectionid, state, fullregion, isDndAllowed = true) {\n\n this.id = sectionid;\n if (this.section === undefined) {\n this.section = state.section.get(this.id);\n }\n if (this.course === undefined) {\n this.course = state.course;\n }\n\
n // Prevent topic zero and delegated sections from being draggable.\n if (this.section.number > 0 && this.section.component === null) {\n this.getDraggableData = this._getDraggableData;\n }\n\n this.fullregion = fullregion;\n\n // Drag and drop is only available for components compatible course formats.\n if (this.reactive.isEditing && this.reactive.supportComponents && isDndAllowed) {\n // Init the dropzone.\n this.dragdrop = new DragDrop(this);\n // Save dropzone classes.\n this.classes = this.dragdrop.getClasses();\n }\n }\n\n /**\n * Remove all subcomponents dependencies.\n */\n destroy() {\n if (this.dragdrop !== undefined) {\n this.dragdrop.unregister();\n }\n }\n\n /**\n * Enable or disable the draggable property.\n *\n * @param {bool} value the new draggable value\n */\n setDraggable(value) {\n if (this.getDraggableData) {\n
this.dragdrop?.setDraggable(value);\n }\n }\n\n // Drag and drop methods.\n\n /**\n * The element drop start hook.\n *\n * @param {Object} dropdata the dropdata\n */\n dragStart(dropdata) {\n this.reactive.dispatch('sectionDrag', [dropdata.id], true);\n }\n\n /**\n * The element end start hook.\n *\n * @param {Object} dropdata the dropdata\n */\n dragEnd(dropdata) {\n this.reactive.dispatch('sectionDrag', [dropdata.id], false);\n }\n\n /**\n * Get the draggable data of this component.\n *\n * @returns {Object} exported course module drop data\n */\n _getDraggableData() {\n const exporter = this.reactive.getExporter();\n return exporter.sectionDraggableData(this.reactive.state, this.id);\n }\n\n /**\n * Validate if the drop data can be dropped over the component.\n *\n * @param {Object} dropdata the exported drop data.\n * @returns {boolean}\n */\n validateD
ropData(dropdata) {\n // Course module validation.\n if (dropdata?.type === 'cm') {\n // Prevent content loops with subsections.\n if (this.section?.component && dropdata?.hasdelegatedsection === true) {\n return false;\n }\n // The first section element is already there so we can ignore it.\n const firstcmid = this.section?.cmlist[0];\n return dropdata.id !== firstcmid;\n }\n return false;\n }\n\n /**\n * Display the component dropzone.\n */\n showDropZone() {\n this.element.classList.add(this.classes.DROPZONE);\n }\n\n /**\n * Hide the component dropzone.\n */\n hideDropZone() {\n this.element.classList.remove(this.classes.DROPZONE);\n }\n\n /**\n * Drop event handler.\n *\n * @param {Object} dropdata the accepted drop data\n * @param {Event} event the drop event\n */\n drop(dropdata, event) {\n // Call the move muta
tion.\n if (dropdata.type == 'cm') {\n const mutation = (event.altKey) ? 'cmDuplicate' : 'cmMove';\n this.reactive.dispatch(mutation, [dropdata.id], this.id, this.section?.cmlist[0]);\n }\n }\n}\n"],"names":["BaseComponent","configDragDrop","sectionid","state","fullregion","isDndAllowed","id","undefined","this","section","get","course","number","component","getDraggableData","_getDraggableData","reactive","isEditing","supportComponents","dragdrop","DragDrop","classes","getClasses","destroy","unregister","setDraggable","value","dragStart","dropdata","dispatch","dragEnd","getExporter","sectionDraggableData","validateDropData","type","hasdelegatedsection","firstcmid","_this$section2","cmlist","showDropZone","element","classList","add","DROPZONE","hideDropZone","remove","drop","event","mutation","altKey","_this$section3"],"mappings":";;;;;;;;;;;;uBA6B6BA,wBAUzBC,eAAeC,UAAWC,MAAOC,gBAAYC,6EAEpCC,GAAKJ,eACWK,IAAjBC,KAAKC,eACAA,QAAUN,MAAMM,QAAQC,IAAIF,KAAKF,UAEtBC,IAAhBC,KAAKG
,cACAA,OAASR,MAAMQ,QAIpBH,KAAKC,QAAQG,OAAS,GAAgC,OAA3BJ,KAAKC,QAAQI,iBACnCC,iBAAmBN,KAAKO,wBAG5BX,WAAaA,WAGdI,KAAKQ,SAASC,WAAaT,KAAKQ,SAASE,mBAAqBb,oBAEzDc,SAAW,IAAIC,mBAASZ,WAExBa,QAAUb,KAAKW,SAASG,cAOrCC,eAC0BhB,IAAlBC,KAAKW,eACAA,SAASK,aAStBC,aAAaC,0BACLlB,KAAKM,+CACAK,mDAAUM,aAAaC,QAWpCC,UAAUC,eACDZ,SAASa,SAAS,cAAe,CAACD,SAAStB,KAAK,GAQzDwB,QAAQF,eACCZ,SAASa,SAAS,cAAe,CAACD,SAAStB,KAAK,GAQzDS,2BACqBP,KAAKQ,SAASe,cACfC,qBAAqBxB,KAAKQ,SAASb,MAAOK,KAAKF,IASnE2B,iBAAiBL,aAEU,QAAnBA,MAAAA,gBAAAA,SAAUM,MAAe,gEAEhBzB,gDAASI,YAA+C,KAAlCe,MAAAA,gBAAAA,SAAUO,4BAC9B,QAGLC,iCAAY5B,KAAKC,yCAAL4B,eAAcC,OAAO,UAChCV,SAAStB,KAAO8B,iBAEpB,EAMXG,oBACSC,QAAQC,UAAUC,IAAIlC,KAAKa,QAAQsB,UAM5CC,oBACSJ,QAAQC,UAAUI,OAAOrC,KAAKa,QAAQsB,UAS/CG,KAAKlB,SAAUmB,UAEU,MAAjBnB,SAASM,KAAc,0BACjBc,SAAYD,MAAME,OAAU,cAAgB,cAC7CjC,SAASa,SAASmB,SAAU,CAACpB,SAAStB,IAAKE,KAAKF,0BAAIE,KAAKC,yCAALyC,eAAcZ,OAAO"}