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
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Options helper for Tiny AI plugin.
18
 *
19
 * @module      tiny_aiplacement/options
20
 * @copyright   2023 Matt Porritt <matt.porritt@moodle.com>
21
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
import {getPluginOptionName} from 'editor_tiny/options';
25
import {pluginName} from 'tiny_aiplacement/common';
26
 
27
const contextIdName = getPluginOptionName(pluginName, 'contextid');
28
const userIdName = getPluginOptionName(pluginName, 'userid');
29
const textAllowedName = getPluginOptionName(pluginName, 'generate_text');
30
const imageAllowedName = getPluginOptionName(pluginName, 'generate_image');
31
const policyAgreedName = getPluginOptionName(pluginName, 'policyagreed');
32
 
33
/**
34
 * Options registration function.
35
 *
36
 * @param {tinyMCE} editor
37
 */
38
export const register = (editor) => {
39
    const registerOption = editor.options.register;
40
 
41
    registerOption(contextIdName, {
42
        processor: 'number',
43
        "default": 0,
44
    });
45
 
46
    registerOption(userIdName, {
47
        processor: 'number',
48
        "default": 0,
49
    });
50
 
51
    registerOption(textAllowedName, {
52
        processor: 'boolean',
53
        "default": false,
54
    });
55
 
56
    registerOption(imageAllowedName, {
57
        processor: 'boolean',
58
        "default": false,
59
    });
60
 
61
    registerOption(policyAgreedName, {
62
        processor: 'boolean',
63
        "default": false,
64
    });
65
};
66
 
67
/**
68
 * Fetch the context ID value for this editor instance.
69
 *
70
 * @param {tinyMCE} editor The editor instance to fetch the value for
71
 * @returns {int} The value of the contextIdName option
72
 */
73
export const getContextId = (editor) => editor.options.get(contextIdName);
74
 
75
/**
76
 * Fetch the user ID value for this editor instance.
77
 *
78
 * @param {tinyMCE} editor The editor instance to fetch the value for
79
 * @returns {int} The value of the userIdName option
80
 */
81
export const getUserId = (editor) => editor.options.get(userIdName);
82
 
83
/**
84
 * Whether text generation is allowed in this instance.
85
 *
86
 * @param {TinyMCE} editor
87
 * @returns {boolean}
88
 */
89
export const isTextAllowed = (editor) => editor.options.get(textAllowedName);
90
 
91
/**
92
 * Whether image generation is allowed in this instance.
93
 *
94
 * @param {TinyMCE} editor
95
 * @returns {boolean}
96
 */
97
export const isImageAllowed = (editor) => editor.options.get(imageAllowedName);
98
 
99
export const isPolicyAgreed = (editor) => editor.options.get(policyAgreedName);