Proyectos de Subversion Moodle

Rev

Rev 1 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

{"version":3,"file":"dndsection.min.js","sources":["../../../src/local/courseeditor/dndsection.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 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/dndsection\n * @class      core_courseformat/local/courseeditor/dndsection\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';\nimport {getString} from 'core/str';\nimport {prefetchStrings} from 'core/prefetch';\nimport Templates from 'core/templates';\n\n// Load global strings.\nprefetchStrings('core', ['addfilehere']);\n\nexport default class extends BaseComponent {\n\n    /**\n     * Save some values form the state.\n     *\n     * @param {Object} state the current state\n     */\n    configState(state) {\n        this.id = this.element.dataset.id;\n        this.section = state.section.get(this.id);\n        this.course = state.course;\n    }\n\n    /**\n     * Register state values and the drag and drop subcomponent.\n     *\n     * @param {BaseComponent} sectionitem section item component\n     */\n    configDragDrop(sectionitem) {\n        // Drag and drop is only available for components compatible course formats.\n        if (this.reactive.isEditing && this.reactive.supportComponents) {\n            // Init the inner dragable element.\n            this.sectionitem = sectionitem;\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.sectionitem !== undefined) {\n            this.sectionitem.unregister();\n        }\n        if (this.dragdrop !== undefined) {\n            this.dragdrop.unregister();\n        }\n    }\n\n    /**\n     * Get the last CM element of that section.\n     *\n     * @returns {element|null} the las course module element of the section.\n     */\n    getLastCm() {\n        return null;\n    }\n\n    /**\n     * Get a fallback element when there is no CM in the section.\n     *\n     * This is used to show the correct dropzone position.\n     *\n     * @returns {element|null} the las course module element of the section.\n     */\n    getLastCmFallback() {\n        return null;\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 drop end hook.\n     *\n     * @param {Object} dropdata the dropdata\n     */\n    dragEnd(dropdata) {\n        this.reactive.dispatch('sectionDrag', [dropdata.id], false);\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    validateDropData(dropdata) {\n        // We accept files.\n        if (dropdata?.type === 'files') {\n            return true;\n        }\n        // We accept any course module unless it can form a subsection loop.\n        if (dropdata?.type === 'cm') {\n            if (this.section?.component && dropdata?.hasdelegatedsection === true) {\n                return false;\n            }\n            return true;\n        }\n        if (dropdata?.type === 'section') {\n            // Sections controlled by a plugin cannot accept sections.\n            if (this.section.component !== null) {\n                return false;\n            }\n            // We accept any section but yourself and the next one.\n            return dropdata?.id != this.id && dropdata?.number != this.section.number + 1;\n        }\n        return false;\n    }\n\n    /**\n     * Display the component dropzone.\n     *\n     * @param {Object} dropdata the accepted drop data\n     */\n    showDropZone(dropdata) {\n        if (dropdata.type == 'files') {\n            this.addOverlay({\n                content: getString('addfilehere', 'core'),\n                icon: Templates.renderPix('t/download', 'core'),\n            }).then(() => {\n                // Check if we still need the file dropzone.\n                if (!this.dragdrop?.isDropzoneVisible()) {\n                    this.removeOverlay();\n                }\n                return;\n            }).catch((error) => {\n                throw error;\n            });\n        }\n        if (dropdata.type == 'cm') {\n            const lastCm = this.getLastCm();\n            lastCm?.classList.add(this.classes.DROPDOWN);\n            if (!lastCm) {\n                this.getLastCmFallback()?.classList.add(this.classes.DROPDOWN);\n            }\n        }\n        if (dropdata.type == 'section') {\n            this.element.classList.remove(this.classes.DROPUP);\n            this.element.classList.add(this.classes.DROPDOWN);\n        }\n    }\n\n    /**\n     * Hide the component dropzone.\n     */\n    hideDropZone() {\n        this.getLastCm()?.classList.remove(this.classes.DROPDOWN);\n        this.getLastCmFallback()?.classList.remove(this.classes.DROPDOWN);\n        this.element.classList.remove(this.classes.DROPUP);\n        this.element.classList.remove(this.classes.DROPDOWN);\n        this.removeOverlay();\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        // File handling.\n        if (dropdata.type == 'files') {\n            this.reactive.uploadFiles(\n                this.section.id,\n                this.section.number,\n                dropdata.files\n            );\n            return;\n        }\n        // Call the move mutation.\n        if (dropdata.type == 'cm') {\n            const mutation = (event.altKey) ? 'cmDuplicate' : 'cmMove';\n            this.reactive.dispatch(mutation, [dropdata.id], this.id);\n        }\n        if (dropdata.type == 'section') {\n            this.reactive.dispatch('sectionMoveAfter', [dropdata.id], this.id);\n        }\n    }\n}\n"],"names":["BaseComponent","configState","state","id","this","element","dataset","section","get","course","configDragDrop","sectionitem","reactive","isEditing","supportComponents","dragdrop","DragDrop","classes","getClasses","destroy","undefined","unregister","getLastCm","getLastCmFallback","dragStart","dropdata","dispatch","dragEnd","validateDropData","type","component","hasdelegatedsection","number","showDropZone","addOverlay","content","icon","Templates","renderPix","then","_this$dragdrop","isDropzoneVisible","removeOverlay","catch","error","lastCm","classList","add","DROPDOWN","remove","DROPUP","hideDropZone","drop","event","mutation","altKey","uploadFiles","files"],"mappings":";;;;;;;;;;;iLAiCgB,OAAQ,CAAC,uCAEI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