Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"dropdown.min.js","sources":["../src/dropdown.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 * Dropdown handler for the Event monitor tool.\n *\n * @module     tool_monitor/dropdown\n * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = () => {\n    const componentSelector = document.querySelector('[data-field=\"component\"]');\n    const eventSelector = document.querySelector('[data-field=\"eventname\"]');\n\n    const matchesComponent = (component, event) => event.startsWith(`\\\\${component}\\\\`);\n\n    // Helper to fetch events for a component.\n    const getEventsForComponent = (component) => {\n        const events = Object.entries(JSON.parse(eventSelector.dataset.eventlist));\n        return events.filter(([eventName], index) => {\n            // Always return the Choose... option.\n            if (index === 0) {\n                return true;\n            }\n            return matchesComponent(component, eventName);\n        });\n    };\n\n    // Helper to fetch the <option> elements for a compoment.\n    const getEventOptionsForComponent = (component) => {\n        return getEventsForComponent(component).map(([name, description]) => {\n            const option = document.createElement('option');\n            option.value = name;\n            option.text = description;\n            return option;\n        });\n    };\n\n    // Change handler for the component selector.\n    componentSelector.addEventListener('change', () => {\n        eventSelector.innerHTML = '';\n        getEventOptionsForComponent(componentSelector.value).forEach((option) => {\n            eventSelector.options.add(option);\n        });\n        eventSelector.options.value = '';\n    });\n\n    // Set the initial value.\n    // Rather than emptying the list and re-adding as the change handler does, remove any options that don't match.\n    // This means that the current selection (when editing) is maintained.\n    const initialCount = eventSelector.options.length;\n    [...eventSelector.options].reverse().forEach((option, index) => {\n        if (option.value === '') {\n            // The first value is the \"Choose...\" pseudo-option.\n            return;\n        }\n        if (!matchesComponent(componentSelector.value, option.value)) {\n            eventSelector.options.remove(initialCount - index - 1);\n        }\n    });\n};\n"],"names":["componentSelector","document","querySelector","eventSelector","matchesComponent","component","event","startsWith","getEventOptionsForComponent","Object","entries","JSON","parse","dataset","eventlist","filter","index","eventName","getEventsForComponent","map","_ref2","name","description","option","createElement","value","text","addEventListener","innerHTML","forEach","options","add","initialCount","length","reverse","remove"],"mappings":"0JAuBoB,WACVA,kBAAoBC,SAASC,cAAc,4BAC3CC,cAAgBF,SAASC,cAAc,4BAEvCE,iBAAmB,CAACC,UAAWC,QAAUA,MAAMC,uBAAgBF,iBAe/DG,4BAA+BH,WAZNA,CAAAA,WACZI,OAAOC,QAAQC,KAAKC,MAAMT,cAAcU,QAAQC,YACjDC,QAAO,MAAcC,aAAZC,uBAEL,IAAVD,OAGGZ,iBAAiBC,UAAWY,cAMhCC,CAAsBb,WAAWc,KAAIC,YAAEC,KAAMC,yBAC1CC,OAAStB,SAASuB,cAAc,iBACtCD,OAAOE,MAAQJ,KACfE,OAAOG,KAAOJ,YACPC,UAKfvB,kBAAkB2B,iBAAiB,UAAU,KACzCxB,cAAcyB,UAAY,GAC1BpB,4BAA4BR,kBAAkByB,OAAOI,SAASN,SAC1DpB,cAAc2B,QAAQC,IAAIR,WAE9BpB,cAAc2B,QAAQL,MAAQ,YAM5BO,aAAe7B,cAAc2B,QAAQG,WACvC9B,cAAc2B,SAASI,UAAUL,SAAQ,CAACN,OAAQP,SAC7B,KAAjBO,OAAOE,QAINrB,iBAAiBJ,kBAAkByB,MAAOF,OAAOE,QAClDtB,cAAc2B,QAAQK,OAAOH,aAAehB,MAAQ"}