Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 20... Línea 20...
20
 * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
20
 * @copyright  2023 Andrew Lyons <andrew@nicols.co.uk>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
22
 */
Línea 23... Línea 23...
23
 
23
 
-
 
24
import Modal from 'core/modal';
-
 
25
import * as Fragment from 'core/fragment';
-
 
26
import {getString} from 'core/str';
Línea 24... Línea 27...
24
import Modal from 'core/modal';
27
import AutoComplete from 'core/form-autocomplete';
25
 
28
 
26
export default class AddQuestionModal extends Modal {
29
export default class AddQuestionModal extends Modal {
27
    configure(modalConfig) {
30
    configure(modalConfig) {
Línea 34... Línea 37...
34
 
37
 
35
        // Apply question modal configuration.
38
        // Apply question modal configuration.
36
        this.setContextId(modalConfig.contextId);
39
        this.setContextId(modalConfig.contextId);
Línea -... Línea 40...
-
 
40
        this.setAddOnPageId(modalConfig.addOnPage);
-
 
41
 
-
 
42
        // Store the quiz module id for when we need to POST to the quiz.
-
 
43
        // This is because the URL cmid param will change during filter operations as we will be in another bank context.
-
 
44
        this.quizCmId = modalConfig.quizCmId;
-
 
45
        this.bankCmId = modalConfig.bankCmId;
-
 
46
 
-
 
47
        // Store the original title of the modal, so we can revert back to it once we have switched to another bank.
37
        this.setAddOnPageId(modalConfig.addOnPage);
48
        this.originalTitle = modalConfig.title;
38
 
49
 
39
        // Apply standard configuration.
50
        // Apply standard configuration.
Línea 40... Línea 51...
40
        super.configure(modalConfig);
51
        super.configure(modalConfig);
Línea 87... Línea 98...
87
     */
98
     */
88
    getAddOnPageId() {
99
    getAddOnPageId() {
89
        return this.addOnPageId;
100
        return this.addOnPageId;
90
    }
101
    }
Línea -... Línea 102...
-
 
102
 
-
 
103
    /**
-
 
104
     * Update the modal with a list of banks to switch to and enhance the standard selects to Autocomplete fields.
-
 
105
     *
-
 
106
     * @param {String} Selector for the original select element.
-
 
107
     * @return {Promise} Modal.
-
 
108
     */
-
 
109
    async handleSwitchBankContentReload(Selector) {
-
 
110
        this.setTitle(getString('selectquestionbank', 'mod_quiz'));
-
 
111
 
-
 
112
        // Create a 'Go back' button and set it in the footer.
-
 
113
        const el = document.createElement('button');
-
 
114
        el.classList.add('btn', 'btn-primary');
-
 
115
        el.textContent = await getString('gobacktoquiz', 'mod_quiz');
-
 
116
        el.setAttribute('data-action', 'go-back');
-
 
117
        el.setAttribute('value', this.bankCmId);
-
 
118
        this.setFooter(el);
-
 
119
 
-
 
120
        this.setBody(
-
 
121
            Fragment.loadFragment(
-
 
122
                'mod_quiz',
-
 
123
                'switch_question_bank',
-
 
124
                this.getContextId(),
-
 
125
                {
-
 
126
                    'quizcmid': this.quizCmId,
-
 
127
                    'bankcmid': this.bankCmId,
-
 
128
                })
-
 
129
        );
-
 
130
        const placeholder = await getString('searchbyname', 'mod_quiz');
-
 
131
        await this.getBodyPromise();
-
 
132
        await AutoComplete.enhance(
-
 
133
            Selector,
-
 
134
            false,
-
 
135
            'core_question/question_banks_datasource',
-
 
136
            placeholder,
-
 
137
            false,
-
 
138
            true,
-
 
139
            '',
-
 
140
            true
-
 
141
        );
-
 
142
 
-
 
143
        // Hide the selection element as we don't need it.
-
 
144
        document.querySelector('.search-banks .form-autocomplete-selection')?.classList.add('d-none');
-
 
145
 
-
 
146
        return this;
91
 
147
    }