Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
{"version":3,"file":"bulkedittoggler.min.js","sources":["../../../src/local/content/bulkedittoggler.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 * The bulk editor toggler button control.\n *\n * @module     core_courseformat/local/content/bulkedittoggler\n * @class      core_courseformat/local/content/bulkedittoggler\n * @copyright  2023 Ferran Recio <ferran@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {BaseComponent} from 'core/reactive';\nimport {getCurrentCourseEditor} from 'core_courseformat/courseeditor';\nimport Pending from 'core/pending';\n\nexport default class Component extends BaseComponent {\n\n    /**\n     * Constructor hook.\n     */\n    create() {\n        // Optional component name for debugging.\n        this.name = 'bulk_editor_toogler';\n        // Default query selectors.\n        this.selectors = {\n            BODY: `body`,\n            SELECTABLE: `[data-bulkcheckbox][data-is-selectable]`,\n        };\n        // Component css classes.\n        this.classes = {\n            HIDDEN: `d-none`,\n            BULK: `bulkenabled`,\n        };\n    }\n\n    /**\n     * Static method to create a component instance from the mustache template.\n     *\n     * @param {string} target optional altentative DOM main element CSS selector\n     * @param {object} selectors optional css selector overrides\n     * @return {Component}\n     */\n    static init(target, selectors) {\n        return new this({\n            element: document.querySelector(target),\n            reactive: getCurrentCourseEditor(),\n            selectors\n        });\n    }\n\n    /**\n     * Initial state ready method.\n     */\n    stateReady() {\n        // Capture completion events.\n        this.addEventListener(\n            this.element,\n            'click',\n            this._enableBulk\n        );\n    }\n\n    /**\n     * Component watchers.\n     *\n     * @returns {Array} of watchers\n     */\n    getWatchers() {\n        return [\n            {watch: `bulk.enabled:updated`, handler: this._refreshToggler},\n        ];\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 (state.bulk in this case).\n     */\n    _refreshToggler({element}) {\n        this.element.classList.toggle(this.classes.HIDDEN, element.enabled ?? false);\n        document.querySelector(this.selectors.BODY)?.classList.toggle(this.classes.BULK, element.enabled);\n    }\n\n    /**\n     * Dispatch the enable bulk mutation.\n     *\n     * The enable bulk button is outside of the course content main div.\n     * Because content/actions captures click events only in the course\n     * content, this button needs to trigger the enable bulk mutation\n     * by itself.\n     */\n    _enableBulk() {\n        const pendingToggle = new Pending(`courseformat/content:bulktoggle_on`);\n        this.reactive.dispatch('bulkEnable', true);\n        // Wait for a while and focus on the first checkbox.\n        setTimeout(() => {\n            document.querySelector(this.selectors.SELECTABLE)?.focus();\n            pendingToggle.resolve();\n        }, 150);\n    }\n}\n"],"names":["Component","BaseComponent","create","name","selectors","BODY","SELECTABLE","classes","HIDDEN","BULK","target","this","element","document","querySelector","reactive","stateReady","addEventListener","_enableBulk","getWatchers","watch","handler","_refreshToggler","classList","toggle","enabled","pendingToggle","Pending","dispatch","setTimeout","focus","resolve"],"mappings":";;;;;;;;qJA4BqBA,kBAAkBC,wBAKnCC,cAESC,KAAO,2BAEPC,UAAY,CACbC,YACAC,2DAGCC,QAAU,CACXC,gBACAC,gCAWIC,OAAQN,kBACT,IAAIO,KAAK,CACZC,QAASC,SAASC,cAAcJ,QAChCK,UAAU,0CACVX,UAAAA,YAORY,kBAESC,iBACDN,KAAKC,QACL,QACAD,KAAKO,aASbC,oBACW,CACH,CAACC,6BAA+BC,QAASV,KAAKW,kBAUtDA,qEAAgBV,QAACA,mBACRA,QAAQW,UAAUC,OAAOb,KAAKJ,QAAQC,gCAAQI,QAAQa,qFAC3DZ,SAASC,cAAcH,KAAKP,UAAUC,8DAAOkB,UAAUC,OAAOb,KAAKJ,QAAQE,KAAMG,QAAQa,SAW7FP,oBACUQ,cAAgB,IAAIC,4DACrBZ,SAASa,SAAS,cAAc,GAErCC,YAAW,+DACPhB,SAASC,cAAcH,KAAKP,UAAUE,sEAAawB,QACnDJ,cAAcK,YACf"}