Proyectos de Subversion Moodle

Rev

Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

{"version":3,"file":"section.min.js","sources":["../../../src/local/content/section.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 section format component.\n *\n * @module     core_courseformat/local/content/section\n * @class      core_courseformat/local/content/section\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 Header from 'core_courseformat/local/content/section/header';\nimport DndSection from 'core_courseformat/local/courseeditor/dndsection';\nimport Templates from 'core/templates';\n\nexport default class extends DndSection {\n\n    /**\n     * Constructor hook.\n     */\n    create() {\n        // Optional component name for debugging.\n        this.name = 'content_section';\n        // Default query selectors.\n        this.selectors = {\n            SECTION_ITEM: `[data-for='section_title']`,\n            CM: `[data-for=\"cmitem\"]`,\n            SECTIONINFO: `[data-for=\"sectioninfo\"]`,\n            SECTIONBADGES: `[data-region=\"sectionbadges\"]`,\n            SHOWSECTION: `[data-action=\"sectionShow\"]`,\n            HIDESECTION: `[data-action=\"sectionHide\"]`,\n            ACTIONTEXT: `.menu-action-text`,\n            ICON: `.icon`,\n        };\n        // Most classes will be loaded later by DndCmItem.\n        this.classes = {\n            LOCKED: 'editinprogress',\n            HASDESCRIPTION: 'description',\n            HIDE: 'd-none',\n            HIDDEN: 'hidden',\n            CURRENT: 'current',\n        };\n\n        // We need our id to watch specific events.\n        this.id = this.element.dataset.id;\n    }\n\n    /**\n     * Initial state ready method.\n     *\n     * @param {Object} state the initial state\n     */\n    stateReady(state) {\n        this.configState(state);\n        // Drag and drop is only available for components compatible course formats.\n        if (this.reactive.isEditing && this.reactive.supportComponents) {\n            // Section zero and other formats sections may not have a title to drag.\n            const sectionItem = this.getElement(this.selectors.SECTION_ITEM);\n            if (sectionItem) {\n                // Init the inner dragable element.\n                const headerComponent = new Header({\n                    ...this,\n                    element: sectionItem,\n                    fullregion: this.element,\n                });\n                this.configDragDrop(headerComponent);\n            }\n        }\n    }\n\n    /**\n     * Component watchers.\n     *\n     * @returns {Array} of watchers\n     */\n    getWatchers() {\n        return [\n            {watch: `section[${this.id}]:updated`, handler: this._refreshSection},\n        ];\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        // If the format uses one section per page sections dropping in the content is ignored.\n       if (dropdata?.type === 'section' && this.reactive.sectionReturn !== null) {\n            return false;\n        }\n        return super.validateDropData(dropdata);\n    }\n\n    /**\n     * Get the last CM element of that section.\n     *\n     * @returns {element|null}\n     */\n    getLastCm() {\n        const cms = this.getElements(this.selectors.CM);\n        // DndUpload may add extra elements so :last-child selector cannot be used.\n        if (!cms || cms.length === 0) {\n            return null;\n        }\n        return cms[cms.length - 1];\n    }\n\n    /**\n     * Update a content section using the state information.\n     *\n     * @param {object} param\n     * @param {Object} param.element details the update details.\n     */\n    _refreshSection({element}) {\n        // Update classes.\n        this.element.classList.toggle(this.classes.DRAGGING, element.dragging ?? false);\n        this.element.classList.toggle(this.classes.LOCKED, element.locked ?? false);\n        this.element.classList.toggle(this.classes.HIDDEN, !element.visible ?? false);\n        this.element.classList.toggle(this.classes.CURRENT, element.current ?? false);\n        this.locked = element.locked;\n        // The description box classes depends on the section state.\n        const sectioninfo = this.getElement(this.selectors.SECTIONINFO);\n        if (sectioninfo) {\n            sectioninfo.classList.toggle(this.classes.HASDESCRIPTION, element.hasrestrictions);\n        }\n        // Update section badges and menus.\n        this._updateBadges(element);\n        this._updateActionsMenu(element);\n    }\n\n    /**\n     * Update a section badges using the state information.\n     *\n     * @param {object} section the section state.\n     */\n    _updateBadges(section) {\n        const current = this.getElement(`${this.selectors.SECTIONBADGES} [data-type='iscurrent']`);\n        current?.classList.toggle(this.classes.HIDE, !section.current);\n\n        const hiddenFromStudents = this.getElement(`${this.selectors.SECTIONBADGES} [data-type='hiddenfromstudents']`);\n        hiddenFromStudents?.classList.toggle(this.classes.HIDE, section.visible);\n    }\n\n    /**\n     * Update a section action menus.\n     *\n     * @param {object} section the section state.\n     */\n    async _updateActionsMenu(section) {\n        let selector;\n        let newAction;\n        if (section.visible) {\n            selector = this.selectors.SHOWSECTION;\n            newAction = 'sectionHide';\n        } else {\n            selector = this.selectors.HIDESECTION;\n            newAction = 'sectionShow';\n        }\n        // Find the affected action.\n        const affectedAction = this.getElement(selector);\n        if (!affectedAction) {\n            return;\n        }\n        // Change action.\n        affectedAction.dataset.action = newAction;\n        // Change text.\n        const actionText = affectedAction.querySelector(this.selectors.ACTIONTEXT);\n        if (affectedAction.dataset?.swapname && actionText) {\n            const oldText = actionText?.innerText;\n            actionText.innerText = affectedAction.dataset.swapname;\n            affectedAction.dataset.swapname = oldText;\n        }\n        // Change icon.\n        const icon = affectedAction.querySelector(this.selectors.ICON);\n        if (affectedAction.dataset?.swapicon && icon) {\n            const newIcon = affectedAction.dataset.swapicon;\n            if (newIcon) {\n                const pixHtml = await Templates.renderPix(newIcon, 'core');\n                Templates.replaceNode(icon, pixHtml, '');\n            }\n        }\n    }\n}\n"],"names":["DndSection","create","name","selectors","SECTION_ITEM","CM","SECTIONINFO","SECTIONBADGES","SHOWSECTION","HIDESECTION","ACTIONTEXT","ICON","classes","LOCKED","HASDESCRIPTION","HIDE","HIDDEN","CURRENT","id","this","element","dataset","stateReady","state","configState","reactive","isEditing","supportComponents","sectionItem","getElement","headerComponent","Header","fullregion","configDragDrop","getWatchers","watch","handler","_refreshSection","validateDropData","dropdata","type","sectionReturn","super","getLastCm","cms","getElements","length","classList","toggle","DRAGGING","dragging","locked","visible","current","sectioninfo","hasrestrictions","_updateBadges","_updateActionsMenu","section","hiddenFromStudents","selector","newAction","affectedAction","action","actionText","querySelector","swapname","oldText","innerText","icon","swapicon","newIcon","pixHtml","Templates","renderPix","replaceNode"],"mappings":";;;;;;;;kPA4B6BA,oBAKzBC,cAESC,KAAO,uBAEPC,UAAY,CACbC,0CACAC,yBACAC,uCACAC,8CACAC,0CACAC,0CACAC,+BACAC,mBAGCC,QAAU,CACXC,OAAQ,iBACRC,eAAgB,cAChBC,KAAM,SACNC,OAAQ,SACRC,QAAS,gBAIRC,GAAKC,KAAKC,QAAQC,QAAQH,GAQnCI,WAAWC,eACFC,YAAYD,OAEbJ,KAAKM,SAASC,WAAaP,KAAKM,SAASE,kBAAmB,OAEtDC,YAAcT,KAAKU,WAAWV,KAAKhB,UAAUC,iBAC/CwB,YAAa,OAEPE,gBAAkB,IAAIC,gBAAO,IAC5BZ,KACHC,QAASQ,YACTI,WAAYb,KAAKC,eAEhBa,eAAeH,mBAUhCI,oBACW,CACH,CAACC,wBAAkBhB,KAAKD,gBAAekB,QAASjB,KAAKkB,kBAU7DC,iBAAiBC,iBAES,aAAnBA,MAAAA,gBAAAA,SAAUC,OAAsD,OAAhCrB,KAAKM,SAASgB,gBAG1CC,MAAMJ,iBAAiBC,UAQlCI,kBACUC,IAAMzB,KAAK0B,YAAY1B,KAAKhB,UAAUE,WAEvCuC,KAAsB,IAAfA,IAAIE,OAGTF,IAAIA,IAAIE,OAAS,GAFb,KAWfT,kGAAgBjB,QAACA,mBAERA,QAAQ2B,UAAUC,OAAO7B,KAAKP,QAAQqC,mCAAU7B,QAAQ8B,+DACxD9B,QAAQ2B,UAAUC,OAAO7B,KAAKP,QAAQC,+BAAQO,QAAQ+B,yDACtD/B,QAAQ2B,UAAUC,OAAO7B,KAAKP,QAAQI,iCAASI,QAAQgC,4DACvDhC,QAAQ2B,UAA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