Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"header.min.js","sources":["../../../../src/local/content/section/header.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 header component.\n *\n * This component is used to control specific course section interactions like drag and drop.\n *\n * @module     core_courseformat/local/content/section/header\n * @class      core_courseformat/local/content/section/header\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 DndSectionItem from 'core_courseformat/local/courseeditor/dndsectionitem';\n\nexport default class extends DndSectionItem {\n\n    /**\n     * Constructor hook.\n     *\n     * @param {Object} descriptor\n     */\n    create(descriptor) {\n        // Optional component name for debugging.\n        this.name = 'content_section_header';\n        // Default query selectors.\n        this.selectors = {\n            ACTIONSMENU: `.section_action_menu`,\n            BULKSELECT: `[data-for='sectionBulkSelect']`,\n            BULKCHECKBOX: `[data-bulkcheckbox]`,\n            CHEVRON: `[data-for='sectiontoggler']`,\n        };\n        this.classes = {\n            HIDE: 'd-none',\n            SELECTED: 'selected',\n        };\n        // Get main info from the descriptor.\n        this.id = descriptor.id;\n        this.section = descriptor.section;\n        this.course = descriptor.course;\n        this.fullregion = descriptor.fullregion;\n    }\n\n    /**\n     * Initial state ready method.\n     *\n     * @param {Object} state the initial state\n     */\n    stateReady(state) {\n        this.configDragDrop(this.id, state, this.fullregion);\n        this._refreshBulk({state});\n    }\n\n    /**\n     * Component watchers.\n     *\n     * @returns {Array} of watchers\n     */\n    getWatchers() {\n        return [\n            {watch: `bulk:updated`, handler: this._refreshBulk},\n            {watch: `section[${this.id}].title:updated`, handler: this._refreshSectionTitle},\n        ];\n    }\n\n    /**\n     * Update the section when the section name changes.\n     *\n     * The section header have several HTML that uses the section name\n     * for accessibility and behat tests. This method updates them all.\n     *\n     * @param {object} param\n     * @param {Object} param.element the section info\n     */\n    _refreshSectionTitle(param) {\n        const element = param.element;\n        this.getElement(this.selectors.CHEVRON)?.setAttribute(\"aria-label\", element.title);\n        this._refreshSectionBulkSelector(param);\n    }\n\n    /**\n     * Update the bulk checkbox when the section name changes.\n     *\n     * @param {object} param\n     * @param {Object} param.element the section info\n     */\n    async _refreshSectionBulkSelector({element}) {\n        const checkbox = this.getElement(this.selectors.BULKCHECKBOX);\n        if (!checkbox) {\n            return;\n        }\n        const newLabel = await this.reactive.getFormatString('selectsection', element.title);\n        checkbox.title = newLabel;\n        const label = this.getElement(`label[for='${checkbox.id}']`);\n        if (label) {\n            label.innerText = newLabel;\n        }\n    }\n\n    /**\n     * Update a bulk options.\n     *\n     * @param {object} param\n     * @param {Object} param.state the state data\n     */\n    _refreshBulk({state}) {\n        const bulk = state.bulk;\n        if (!this._isSectionBulkEditable()) {\n            return;\n        }\n        // For now, dragging elements in bulk is not possible.\n        this.setDraggable(!bulk.enabled);\n        this.getElement(this.selectors.BULKSELECT)?.classList.toggle(this.classes.HIDE, !bulk.enabled);\n\n        const disabled = !this._isSectionBulkEnabled(bulk);\n        const selected = this._isSelected(bulk);\n        this.element.classList.toggle(this.classes.SELECTED, selected);\n        this._setCheckboxValue(selected, disabled);\n    }\n\n    /**\n     * Modify the checkbox element.\n     * @param {Boolean} checked the new checked value\n     * @param {Boolean} disabled the new disabled value\n     */\n    _setCheckboxValue(checked, disabled) {\n        const checkbox = this.getElement(this.selectors.BULKCHECKBOX);\n        if (!checkbox) {\n            return;\n        }\n        checkbox.checked = checked;\n        checkbox.disabled = disabled;\n        // Is selectable is used to easily scan the page for bulk checkboxes.\n        if (disabled) {\n            checkbox.removeAttribute('data-is-selectable');\n        } else {\n            checkbox.dataset.isSelectable = 1;\n        }\n    }\n\n    /**\n     * Check if cm bulk selection is available.\n     * @param {Object} bulk the current state bulk attribute\n     * @returns {Boolean}\n     */\n    _isSectionBulkEnabled(bulk) {\n        if (!bulk.enabled) {\n            return false;\n        }\n        return (bulk.selectedType === '' || bulk.selectedType === 'section');\n    }\n\n    /**\n     * Check if the section is bulk editable.\n     * @return {Boolean}\n     */\n    _isSectionBulkEditable() {\n        const section = this.reactive.get('section', this.id);\n        return section?.bulkeditable ?? false;\n    }\n\n    /**\n     * Check if the cm id is part of the current bulk selection.\n     * @param {Object} bulk the current state bulk attribute\n     * @returns {Boolean}\n     */\n    _isSelected(bulk) {\n        if (bulk.selectedType !== 'section') {\n            return false;\n        }\n        return bulk.selection.includes(this.id);\n    }\n}\n"],"names":["DndSectionItem","create","descriptor","name","selectors","ACTIONSMENU","BULKSELECT","BULKCHECKBOX","CHEVRON","classes","HIDE","SELECTED","id","section","course","fullregion","stateReady","state","configDragDrop","this","_refreshBulk","getWatchers","watch","handler","_refreshSectionTitle","param","element","getElement","setAttribute","title","_refreshSectionBulkSelector","checkbox","newLabel","reactive","getFormatString","label","innerText","bulk","_isSectionBulkEditable","setDraggable","enabled","classList","toggle","disabled","_isSectionBulkEnabled","selected","_isSelected","_setCheckboxValue","checked","removeAttribute","dataset","isSelectable","selectedType","get","bulkeditable","selection","includes"],"mappings":";;;;;;;;;;oLA4B6BA,wBAOzBC,OAAOC,iBAEEC,KAAO,8BAEPC,UAAY,CACbC,mCACAC,4CACAC,mCACAC,4CAECC,QAAU,CACXC,KAAM,SACNC,SAAU,iBAGTC,GAAKV,WAAWU,QAChBC,QAAUX,WAAWW,aACrBC,OAASZ,WAAWY,YACpBC,WAAab,WAAWa,WAQjCC,WAAWC,YACFC,eAAeC,KAAKP,GAAIK,MAAOE,KAAKJ,iBACpCK,aAAa,CAACH,MAAAA,QAQvBI,oBACW,C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