Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"grouppicker.min.js","sources":["../src/grouppicker.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 * @module     core_group/groupPicker\n * @copyright  2022 Matthew Hilton <matthewhilton@catalyst-au.net>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n/**\n * Class used for interfacing with the group select picker.\n *\n * @class core_group/GroupPicker\n */\nexport default class GroupPicker {\n    /**\n     * Creates the group picker class and finds the corresponding DOM element.\n     *\n     * @param {String} elementId The DOM element id of the <select> input\n     * @throws Error if the element was not found.\n     */\n    constructor(elementId = \"groups\") {\n        const pickerDomElement = document.getElementById(elementId);\n\n        if (!pickerDomElement) {\n            throw new Error(\"Groups picker was not found.\");\n        }\n\n        this.element = pickerDomElement;\n    }\n\n    /**\n     * Returns the DOM element this class is linked to.\n     *\n     * @returns {HTMLElement} The DOM element\n     */\n    getDomElement() {\n        return this.element;\n    }\n\n    /**\n     * Returns the selected group values.\n     *\n     * @returns {Number[]} The group IDs that are currently selected.\n     */\n    getSelectedValues() {\n        const selectedOptionElements = Array.from(this.element.querySelectorAll(\"option:checked\"));\n        const selectedGroups = selectedOptionElements.map(el => parseInt(el.value));\n\n        return selectedGroups;\n    }\n}\n"],"names":["constructor","elementId","pickerDomElement","document","getElementById","Error","element","getDomElement","this","getSelectedValues","Array","from","querySelectorAll","map","el","parseInt","value"],"mappings":";;;;;;MAgCIA,kBAAYC,iEAAY,eACdC,iBAAmBC,SAASC,eAAeH,eAE5CC,uBACK,IAAIG,MAAM,qCAGfC,QAAUJ,iBAQnBK,uBACWC,KAAKF,QAQhBG,2BACmCC,MAAMC,KAAKH,KAAKF,QAAQM,iBAAiB,mBAC1BC,KAAIC,IAAMC,SAASD,GAAGE"}