Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
// This file is part of Moodle - http://moodle.org/ //
2
// Moodle is free software: you can redistribute it and/or modify
3
// it under the terms of the GNU General Public License as published by
4
// the Free Software Foundation, either version 3 of the License, or
5
// (at your option) any later version.
6
//
7
// Moodle is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
// GNU General Public License for more details.
11
//
12
// You should have received a copy of the GNU General Public License
13
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
14
 
15
/**
16
 * AI provider model selection handler.
17
 *
18
 * @module     aiprovider_openai/modelchooser
19
 * @copyright  2025 Huong Nguyen <huongnv13@gmail.com>
20
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 */
22
 
23
const Selectors = {
24
    fields: {
25
        selector: '[data-modelchooser-field="selector"]',
26
        updateButton: '[data-modelchooser-field="updateButton"]',
27
    },
28
};
29
 
30
/**
31
 * Initialise the AI provider chooser.
32
 */
33
export const init = () => {
34
    const modelSelector = document.querySelector(Selectors.fields.selector);
35
    if (modelSelector) {
36
        modelSelector.addEventListener('change', e => {
37
            modelSelector.options[e.target.selectedIndex].selected = true;
38
            const form = e.target.closest('form');
39
            const updateButton = form.querySelector(Selectors.fields.updateButton);
40
            updateButton.click();
41
        });
42
    }
43
};