Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 29... Línea 29...
29
import * as FormChangeChecker from 'core_form/changechecker';
29
import * as FormChangeChecker from 'core_form/changechecker';
30
import {call as fetchMany} from 'core/ajax';
30
import {call as fetchMany} from 'core/ajax';
31
import Pending from 'core/pending';
31
import Pending from 'core/pending';
Línea 32... Línea 32...
32
 
32
 
-
 
33
const SELECTORS = {
33
const SELECTORS = {
34
    ANCHOR: 'a[href]',
34
    EXISTING_CATEGORY_CONTAINER: '[data-region="existing-category-container"]',
35
    EXISTING_CATEGORY_CONTAINER: '[data-region="existing-category-container"]',
35
    EXISTING_CATEGORY_TAB: '#id_existingcategoryheader',
36
    EXISTING_CATEGORY_TAB: '#id_existingcategoryheader',
36
    NEW_CATEGORY_CONTAINER: '[data-region="new-category-container"]',
37
    NEW_CATEGORY_CONTAINER: '[data-region="new-category-container"]',
37
    NEW_CATEGORY_TAB: '#id_newcategoryheader',
38
    NEW_CATEGORY_TAB: '#id_newcategoryheader',
38
    TAB_CONTENT: '[data-region="tab-content"]',
39
    TAB_CONTENT: '[data-region="tab-content"]',
39
    ADD_ON_PAGE_FORM_ELEMENT: '[name="addonpage"]',
40
    ADD_ON_PAGE_FORM_ELEMENT: '[name="addonpage"]',
40
    ADD_RANDOM_BUTTON: 'input[type="submit"][name="addrandom"]',
41
    ADD_RANDOM_BUTTON: 'input[type="submit"][name="addrandom"]',
41
    ADD_NEW_CATEGORY_BUTTON: 'input[type="submit"][name="newcategory"]',
42
    ADD_NEW_CATEGORY_BUTTON: 'input[type="submit"][name="newcategory"]',
-
 
43
    SUBMIT_BUTTON_ELEMENT: 'input[type="submit"][name="addrandom"], '
-
 
44
        + 'input[type="submit"][name="newcategory"], '
42
    SUBMIT_BUTTON_ELEMENT: 'input[type="submit"][name="addrandom"], input[type="submit"][name="newcategory"]',
45
        + 'input[type="submit"][name="update"]',
43
    FORM_HEADER: 'legend',
46
    FORM_HEADER: 'legend',
44
    SELECT_NUMBER_TO_ADD: '#menurandomcount',
47
    SELECT_NUMBER_TO_ADD: '#menurandomcount',
45
    NEW_CATEGORY_ELEMENT: '#categoryname',
48
    NEW_CATEGORY_ELEMENT: '#categoryname',
46
    PARENT_CATEGORY_ELEMENT: '#parentcategory',
49
    PARENT_CATEGORY_ELEMENT: '#parentcategory',
47
    FILTER_CONDITION_ELEMENT: '[data-filtercondition]',
50
    FILTER_CONDITION_ELEMENT: '[data-filtercondition]',
48
    FORM_ELEMENT: '#add_random_question_form',
51
    FORM_ELEMENT: '#add_random_question_form',
-
 
52
    MESSAGE_INPUT: '[name="message"]',
-
 
53
    SWITCH_TO_OTHER_BANK: 'button[data-action="switch-question-bank"]',
-
 
54
    NEW_BANKMOD_ID: 'data-newmodid',
-
 
55
    BANK_SEARCH: '#searchbanks',
-
 
56
    GO_BACK_BUTTON: 'button[data-action="go-back"]',
49
    MESSAGE_INPUT: '[name="message"]',
57
    UPDATE_FILTER_BUTTON: 'input[type="submit"][name="update"]',
Línea 50... Línea 58...
50
};
58
};
51
 
59
 
52
export default class ModalAddRandomQuestion extends Modal {
60
export default class ModalAddRandomQuestion extends Modal {
Línea 53... Línea 61...
53
    static TYPE = 'mod_quiz-quiz-add-random-question';
61
    static TYPE = 'mod_quiz-quiz-add-random-question';
54
    static TEMPLATE = 'mod_quiz/modal_add_random_question';
62
    static TEMPLATE = 'mod_quiz/modal_add_random_question';
55
 
63
 
56
    /**
64
    /**
-
 
65
     * Create the add random question modal.
57
     * Create the add random question modal.
66
     *
58
     *
67
     * @param  {Number} contextId Current context id.
59
     * @param  {Number} contextId Current context id.
68
     * @param  {Number} bankCmId Current question bank course module id.
60
     * @param  {string} category Category id and category context id comma separated.
69
     * @param  {string} category Category id and category context id comma separated.
61
     * @param  {string} returnUrl URL to return to after form submission.
70
     * @param  {string} returnUrl URL to return to after form submission.
-
 
71
     * @param  {Number} quizCmId Current quiz course module id.
-
 
72
     * @param  {boolean} showNewCategory Display the New category tab when selecting random questions.
-
 
73
     */
-
 
74
    static init(
-
 
75
        contextId,
-
 
76
        bankCmId,
62
     * @param  {Number} cmid Current course module id.
77
        category,
-
 
78
        returnUrl,
63
     * @param  {boolean} showNewCategory Display the New category tab when selecting random questions.
79
        quizCmId,
64
     */
80
        showNewCategory = true
65
    static init(contextId, category, returnUrl, cmid, showNewCategory = true) {
81
    ) {
66
        const selector = '.menu [data-action="addarandomquestion"]';
82
        const selector = '.menu [data-action="addarandomquestion"], [data-action="editrandomquestion"]';
67
        document.addEventListener('click', (e) => {
83
        document.addEventListener('click', (e) => {
68
            const trigger = e.target.closest(selector);
84
            const trigger = e.target.closest(selector);
69
            if (!trigger) {
85
            if (!trigger) {
Línea -... Línea 86...
-
 
86
                return;
-
 
87
            }
-
 
88
            e.preventDefault();
-
 
89
 
70
                return;
90
            if (trigger.dataset.slotid) {
71
            }
91
                showNewCategory = false;
-
 
92
            }
72
            e.preventDefault();
93
 
73
 
94
            ModalAddRandomQuestion.create({
74
            ModalAddRandomQuestion.create({
95
                contextId,
75
                contextId,
-
 
-
 
96
                bankCmId,
76
                category,
97
                category,
77
                returnUrl,
98
                returnUrl,
78
                cmid,
-
 
-
 
99
                quizCmId,
79
 
100
                showNewCategory,
80
                title: trigger.dataset.header,
101
                title: trigger.dataset.header,
81
                addOnPage: trigger.dataset.addonpage,
102
                addOnPage: trigger.dataset.addonpage,
82
 
103
                slotId: trigger.dataset.slotid,
83
                templateContext: {
104
                templateContext: {
Línea 94... Línea 115...
94
     */
115
     */
95
    constructor(root) {
116
    constructor(root) {
96
        super(root);
117
        super(root);
97
        this.category = null;
118
        this.category = null;
98
        this.returnUrl = null;
119
        this.returnUrl = null;
99
        this.cmid = null;
120
        this.quizCmId = null;
100
        this.loadedForm = false;
121
        this.loadedForm = false;
-
 
122
        this.slotId = 0;
-
 
123
        this.savedFilterCondition = null;
101
    }
124
    }
Línea 102... Línea 125...
102
 
125
 
103
    configure(modalConfig) {
126
    configure(modalConfig) {
Línea 104... Línea 127...
104
        modalConfig.removeOnClose = true;
127
        modalConfig.removeOnClose = true;
105
 
128
 
-
 
129
        this.setCategory(modalConfig.category);
106
        this.setCategory(modalConfig.category);
130
        this.setReturnUrl(modalConfig.returnUrl);
-
 
131
        this.showNewCategory = modalConfig.showNewCategory;
Línea 107... Línea 132...
107
        this.setReturnUrl(modalConfig.returnUrl);
132
        this.setSlotId(modalConfig.slotId ?? 0);
108
        this.setCMID(modalConfig.cmid);
133
        this.setSavedFilterCondition(modalConfig.savedFilterCondition ?? null);
Línea 109... Línea 134...
109
 
134
 
Línea 162... Línea 187...
162
    getReturnUrl() {
187
    getReturnUrl() {
163
        return this.returnUrl;
188
        return this.returnUrl;
164
    }
189
    }
Línea 165... Línea 190...
165
 
190
 
166
    /**
191
    /**
167
     * Set the course module id for the form.
192
     * Set the ID of the quiz slot, if we are editing an existing random question.
168
     *
-
 
169
     * @method setCMID
193
     *
170
     * @param {Number} id
194
     * @param {Number} slotId
171
     */
195
     */
172
    setCMID(id) {
196
    setSlotId(slotId) {
173
        this.cmid = id;
197
        this.slotId = slotId;
Línea 174... Línea 198...
174
    }
198
    }
175
 
199
 
176
    /**
200
    /**
177
     * Returns the course module id for the form.
-
 
178
     *
201
     * Get the current slot ID.
179
     * @method getCMID
202
     *
180
     * @return {Number}
203
     * @return {Number}
181
     */
204
     */
-
 
205
    getSlotId() {
-
 
206
        return this.slotId;
-
 
207
    }
-
 
208
 
-
 
209
    /**
-
 
210
     * Store the current filterCondition JSON string.
-
 
211
     *
-
 
212
     * @param {String} filterCondition
-
 
213
     */
-
 
214
    setSavedFilterCondition(filterCondition) {
-
 
215
        this.savedFilterCondition = filterCondition;
-
 
216
    }
-
 
217
 
-
 
218
    /**
-
 
219
     * Return the saved filterCondition JSON string.
-
 
220
     *
-
 
221
     * @return {String}
-
 
222
     */
182
    getCMID() {
223
    getSavedFilterCondition() {
Línea 183... Línea 224...
183
        return this.cmid;
224
        return this.savedFilterCondition;
184
    }
225
    }
185
 
226
 
Línea 224... Línea 265...
224
     *
265
     *
225
     * @method moveCancelButtonToTabs
266
     * @method moveCancelButtonToTabs
226
     * @param  {jquey} form The form element.
267
     * @param  {jquey} form The form element.
227
     */
268
     */
228
    moveCancelButtonToTabs(form) {
269
    moveCancelButtonToTabs(form) {
229
        const cancelButton = form.find(SELECTORS.CANCEL_BUTTON_ELEMENT).addClass('ml-1');
270
        const cancelButton = form.find(SELECTORS.CANCEL_BUTTON_ELEMENT).addClass('ms-1');
230
        const tabFooters = form.find('[data-region="footer"]');
271
        const tabFooters = form.find('[data-region="footer"]');
231
        // Remove the buttons container element.
272
        // Remove the buttons container element.
232
        cancelButton.closest(SELECTORS.BUTTON_CONTAINER).remove();
273
        cancelButton.closest(SELECTORS.BUTTON_CONTAINER).remove();
233
        cancelButton.clone().appendTo(tabFooters);
274
        cancelButton.clone().appendTo(tabFooters);
234
    }
275
    }
Línea 239... Línea 280...
239
     *
280
     *
240
     * @method loadForm
281
     * @method loadForm
241
     * @return {promise} Resolved with form HTML and JS.
282
     * @return {promise} Resolved with form HTML and JS.
242
     */
283
     */
243
    loadForm() {
284
    loadForm() {
244
        const cmid = this.getCMID();
-
 
245
        const cat = this.getCategory();
-
 
246
        const addonpage = this.getAddOnPageId();
285
        const addonpage = this.getAddOnPageId();
247
        const returnurl = this.getReturnUrl();
286
        const returnurl = this.getReturnUrl();
-
 
287
        const quizcmid = this.quizCmId;
-
 
288
        const bankcmid = this.bankCmId;
-
 
289
        const savedfiltercondition = this.getSavedFilterCondition();
-
 
290
        this.setSavedFilterCondition(null);
Línea 248... Línea 291...
248
 
291
 
249
        return Fragment.loadFragment(
292
        return Fragment.loadFragment(
250
            'mod_quiz',
293
            'mod_quiz',
251
            'add_random_question_form',
294
            'add_random_question_form',
252
            this.getContextId(),
295
            this.getContextId(),
253
            {
296
            {
254
                addonpage,
-
 
255
                cat,
297
                addonpage: addonpage ?? null,
-
 
298
                returnurl,
256
                returnurl,
299
                quizcmid,
-
 
300
                bankcmid,
-
 
301
                slotid: this.getSlotId(),
257
                cmid,
302
                savedfiltercondition,
258
            }
303
            }
259
        )
304
        )
260
        .then((html, js) =>{
305
            .then((html, js) => {
-
 
306
                const form = $(html);
261
            const form = $(html);
307
                if (!this.getSlotId()) {
262
            const existingCategoryTabContent = form.find(SELECTORS.EXISTING_CATEGORY_TAB);
308
                    const existingCategoryTabContent = form.find(SELECTORS.EXISTING_CATEGORY_TAB);
263
            const existingCategoryTab = this.getBody().find(SELECTORS.EXISTING_CATEGORY_CONTAINER);
309
                    const existingCategoryTab = this.getBody().find(SELECTORS.EXISTING_CATEGORY_CONTAINER);
264
            const newCategoryTabContent = form.find(SELECTORS.NEW_CATEGORY_TAB);
310
                    const newCategoryTabContent = form.find(SELECTORS.NEW_CATEGORY_TAB);
265
            const newCategoryTab = this.getBody().find(SELECTORS.NEW_CATEGORY_CONTAINER);
311
                    const newCategoryTab = this.getBody().find(SELECTORS.NEW_CATEGORY_CONTAINER);
266
 
312
 
267
            // Transform the form into tabs for better rendering in the modal.
313
                    // Transform the form into tabs for better rendering in the modal.
268
            this.moveContentIntoTab(existingCategoryTabContent, existingCategoryTab);
314
                    this.moveContentIntoTab(existingCategoryTabContent, existingCategoryTab);
269
            this.moveContentIntoTab(newCategoryTabContent, newCategoryTab);
315
                    this.moveContentIntoTab(newCategoryTabContent, newCategoryTab);
270
            this.moveTabsIntoTabContent(form);
-
 
271
 
-
 
272
            Templates.replaceNode(this.getBody().find(SELECTORS.TAB_CONTENT), form, js);
-
 
273
            return;
-
 
274
        })
-
 
275
        .then(() => {
-
 
276
            // Make sure the form change checker is disabled otherwise it'll stop the user from navigating away from the
-
 
277
            // page once the modal is hidden.
-
 
278
            FormChangeChecker.disableAllChecks();
-
 
279
 
-
 
280
            // Add question to quiz.
-
 
281
            this.getBody()[0].addEventListener('click', (e) => {
-
 
282
                const button = e.target.closest(SELECTORS.SUBMIT_BUTTON_ELEMENT);
-
 
283
                if (!button) {
-
 
284
                    return;
316
                    this.moveTabsIntoTabContent(form);
285
                }
-
 
286
                e.preventDefault();
-
 
287
 
-
 
288
                // Add Random questions if the add random button was clicked.
-
 
289
                const addRandomButton = e.target.closest(SELECTORS.ADD_RANDOM_BUTTON);
-
 
290
                if (addRandomButton) {
-
 
291
                    const randomcount = document.querySelector(SELECTORS.SELECT_NUMBER_TO_ADD).value;
-
 
Línea -... Línea 317...
-
 
317
                }
-
 
318
 
-
 
319
                Templates.replaceNode(this.getBody().find(SELECTORS.TAB_CONTENT), form, js);
-
 
320
                return;
-
 
321
            })
-
 
322
            .then(() => {
-
 
323
                // Make sure the form change checker is disabled otherwise it'll stop the user from navigating away from the
-
 
324
                // page once the modal is hidden.
-
 
325
                FormChangeChecker.disableAllChecks();
-
 
326
 
-
 
327
                // Add question to quiz.
-
 
328
                this.getBody()[0].addEventListener('click', (e) => {
-
 
329
                    const button = e.target.closest(SELECTORS.SUBMIT_BUTTON_ELEMENT);
-
 
330
                    if (!button) {
-
 
331
                        return;
-
 
332
                    }
-
 
333
                    e.preventDefault();
-
 
334
 
-
 
335
                    // Intercept the submission to adjust the POST params so that the quiz mod id is set and not the bank module id.
-
 
336
                    document.querySelector('#questionscontainer input[name="cmid"]').setAttribute('name', this.quizCmId);
-
 
337
 
-
 
338
                    // Add Random questions if the add random button was clicked.
-
 
339
                    const addRandomButton = e.target.closest(SELECTORS.ADD_RANDOM_BUTTON);
-
 
340
                    if (addRandomButton) {
-
 
341
                        const randomcount = document.querySelector(SELECTORS.SELECT_NUMBER_TO_ADD).value;
292
                    const filtercondition = document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset?.filtercondition;
342
                        const filtercondition = document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset?.filtercondition;
-
 
343
 
-
 
344
                        this.addQuestions(quizcmid, addonpage, randomcount, filtercondition, '', '');
-
 
345
                        return;
-
 
346
                    }
-
 
347
                    // Update the filter condition for the slot if the update button was clicked.
-
 
348
                    const updateFilterButton = e.target.closest(SELECTORS.UPDATE_FILTER_BUTTON);
-
 
349
                    if (updateFilterButton) {
293
 
350
                        const filtercondition = document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset?.filtercondition;
294
                    this.addQuestions(cmid, addonpage, randomcount, filtercondition, '', '');
351
                        this.updateFilterCondition(quizcmid, this.getSlotId(), filtercondition);
295
                    return;
352
                        return;
296
                }
353
                    }
297
                // Add new category if the add category button was clicked.
354
                    // Add new category if the add category button was clicked.
298
                const addCategoryButton = e.target.closest(SELECTORS.ADD_NEW_CATEGORY_BUTTON);
355
                    const addCategoryButton = e.target.closest(SELECTORS.ADD_NEW_CATEGORY_BUTTON);
299
                if (addCategoryButton) {
356
                    if (addCategoryButton) {
300
                    this.addQuestions(
357
                        this.addQuestions(
301
                        cmid,
358
                            quizcmid,
302
                        addonpage,
359
                            addonpage,
303
                        1,
360
                            1,
304
                        '',
361
                            '',
-
 
362
                            document.querySelector(SELECTORS.NEW_CATEGORY_ELEMENT).value,
-
 
363
                            document.querySelector(SELECTORS.PARENT_CATEGORY_ELEMENT).value
-
 
364
                        );
-
 
365
                        return;
-
 
366
                    }
-
 
367
                });
-
 
368
 
-
 
369
                this.getModal().on('click', SELECTORS.SWITCH_TO_OTHER_BANK, () => {
305
                        document.querySelector(SELECTORS.NEW_CATEGORY_ELEMENT).value,
370
                    this.setSavedFilterCondition(
-
 
371
                        document.querySelector(SELECTORS.FILTER_CONDITION_ELEMENT).dataset?.filtercondition
-
 
372
                    );
-
 
373
                    this.handleSwitchBankContentReload(SELECTORS.BANK_SEARCH)
-
 
374
                        .then(function(ModalQuizQuestionBank) {
-
 
375
                            $(SELECTORS.BANK_SEARCH)?.on('change', (e) => {
-
 
376
                                const bankCmId = $(e.currentTarget).val();
-
 
377
                                // Have to recreate the modal as we have already used the body for the switch bank content.
-
 
378
                                if (bankCmId > 0) {
-
 
379
                                    ModalAddRandomQuestion.create({
-
 
380
                                        'contextId': ModalQuizQuestionBank.getContextId(),
-
 
381
                                        'bankCmId': bankCmId,
-
 
382
                                        'category': ModalQuizQuestionBank.getCategory(),
-
 
383
                                        'returnUrl': ModalQuizQuestionBank.getReturnUrl(),
-
 
384
                                        'quizCmId': ModalQuizQuestionBank.quizCmId,
-
 
385
                                        'title': ModalQuizQuestionBank.originalTitle,
-
 
386
                                        'addOnPage': ModalQuizQuestionBank.getAddOnPageId(),
-
 
387
                                        'templateContext': {hidden: ModalQuizQuestionBank.showNewCategory},
-
 
388
                                        'showNewCategory': ModalQuizQuestionBank.showNewCategory,
-
 
389
                                        'slotId': ModalQuizQuestionBank.getSlotId(),
-
 
390
                                    })
-
 
391
                                    .then(ModalQuizQuestionBank.destroy())
-
 
392
                                    .catch(Notification.exception);
-
 
393
                                }
306
                        document.querySelector(SELECTORS.PARENT_CATEGORY_ELEMENT).value
394
                            });
-
 
395
                            return ModalQuizQuestionBank;
-
 
396
                        });
-
 
397
                });
-
 
398
 
-
 
399
                this.getModal().on('click', SELECTORS.GO_BACK_BUTTON, (e) => {
-
 
400
                    const anchorElement = $(e.currentTarget);
-
 
401
                    // Have to recreate the modal as we have already used the body for the switch bank content.
-
 
402
                    ModalAddRandomQuestion.create({
-
 
403
                        'contextId': this.getContextId(),
-
 
404
                        'bankCmId': anchorElement.attr('value'),
-
 
405
                        'category': this.getCategory(),
-
 
406
                        'returnUrl': this.getReturnUrl(),
-
 
407
                        'quizCmId': this.quizCmId,
-
 
408
                        'title': this.originalTitle,
-
 
409
                        'addOnPage': this.getAddOnPageId(),
-
 
410
                        'templateContext': {hidden: this.showNewCategory},
-
 
411
                        'showNewCategory': this.showNewCategory,
-
 
412
                        'savedFilterCondition': this.getSavedFilterCondition(),
307
                    );
413
                        'slotId': this.getSlotId(),
-
 
414
                    }).then(this.destroy()).catch(Notification.exception);
-
 
415
                });
-
 
416
 
-
 
417
                this.getModal().on('click', SELECTORS.ANCHOR, (e) => {
-
 
418
                    const anchorElement = $(e.currentTarget);
-
 
419
                    // Have to recreate the modal as we have already used the body for the switch bank content.
-
 
420
                    if (anchorElement.closest('a[' + SELECTORS.NEW_BANKMOD_ID + ']').length) {
-
 
421
                        ModalAddRandomQuestion.create({
-
 
422
                            'contextId': this.getContextId(),
-
 
423
                            'bankCmId': anchorElement.attr(SELECTORS.NEW_BANKMOD_ID),
-
 
424
                            'category': this.getCategory(),
-
 
425
                            'returnUrl': this.getReturnUrl(),
-
 
426
                            'quizCmId': this.quizCmId,
-
 
427
                            'title': this.originalTitle,
-
 
428
                            'addOnPage': this.getAddOnPageId(),
-
 
429
                            'templateContext': {hidden: this.showNewCategory},
-
 
430
                            'showNewCategory': this.showNewCategory,
-
 
431
                            'slotId': this.getSlotId(),
308
                    return;
432
                        }).then(this.destroy()).catch(Notification.exception);
309
                }
433
                    }
310
            });
434
                });
311
        })
435
            })
Línea 312... Línea 436...
312
        .catch(Notification.exception);
436
            .catch(Notification.exception);
313
    }
437
    }
314
 
438
 
315
    /**
439
    /**
316
     * Call web service function to add random questions
440
     * Call web service function to add random questions
317
     *
441
     *
318
     * @param {number} cmid course module id
442
     * @param {number} quizcmid the course module id of the quiz to add questions to.
319
     * @param {number} addonpage the page where random questions will be added to
443
     * @param {number} addonpage the page where random questions will be added to
320
     * @param {number} randomcount Number of random questions
444
     * @param {number} randomcount Number of random questions
321
     * @param {string} filtercondition Filter condition
445
     * @param {string} filtercondition Filter condition
322
     * @param {string} newcategory add new category
446
     * @param {string} newcategory add new category
323
     * @param {string} parentcategory parent category of new category
447
     * @param {string} parentcategory parent category of new category
324
     */
448
     */
325
    async addQuestions(
449
    async addQuestions(
326
        cmid,
450
        quizcmid,
327
        addonpage,
451
        addonpage,
328
        randomcount,
452
        randomcount,
Línea 333... Línea 457...
333
        // We do not need to resolve this Pending because the form submission will result in a page redirect.
457
        // We do not need to resolve this Pending because the form submission will result in a page redirect.
334
        new Pending('mod-quiz/modal_add_random_questions');
458
        new Pending('mod-quiz/modal_add_random_questions');
335
        const call = {
459
        const call = {
336
            methodname: 'mod_quiz_add_random_questions',
460
            methodname: 'mod_quiz_add_random_questions',
337
            args: {
461
            args: {
338
                cmid,
462
                cmid: quizcmid,
339
                addonpage,
463
                addonpage,
340
                randomcount,
464
                randomcount,
341
                filtercondition,
465
                filtercondition,
342
                newcategory,
466
                newcategory,
343
                parentcategory,
467
                parentcategory,
Línea 353... Línea 477...
353
            Notification.exception(e);
477
            Notification.exception(e);
354
        }
478
        }
355
    }
479
    }
Línea 356... Línea 480...
356
 
480
 
-
 
481
    /**
-
 
482
     * Call web service function to update the filter condition for an existing slot.
-
 
483
     *
-
 
484
     * @param {number} quizcmid the course module id of the quiz.
-
 
485
     * @param {number} slotid The slot the random question is in.
-
 
486
     * @param {string} filtercondition The new filter condition.
-
 
487
     */
-
 
488
    async updateFilterCondition(
-
 
489
        quizcmid,
-
 
490
        slotid,
-
 
491
        filtercondition,
-
 
492
    ) {
-
 
493
        // We do not need to resolve this Pending because the form submission will result in a page redirect.
-
 
494
        new Pending('mod-quiz/modal_add_random_questions');
-
 
495
        const call = {
-
 
496
            methodname: 'mod_quiz_update_filter_condition',
-
 
497
            args: {
-
 
498
                cmid: quizcmid,
-
 
499
                slotid,
-
 
500
                filtercondition,
-
 
501
            }
-
 
502
        };
-
 
503
        try {
-
 
504
            const response = await fetchMany([call])[0];
-
 
505
            const form = document.querySelector(SELECTORS.FORM_ELEMENT);
-
 
506
            const messageInput = form.querySelector(SELECTORS.MESSAGE_INPUT);
-
 
507
            messageInput.value = response.message;
-
 
508
            form.submit();
-
 
509
        } catch (e) {
-
 
510
            Notification.exception(e);
-
 
511
        }
-
 
512
    }
-
 
513
 
357
    /**
514
    /**
358
     * Override the modal show function to load the form when this modal is first
515
     * Override the modal show function to load the form when this modal is first
359
     * shown.
516
     * shown.
360
     *
517
     *
361
     * @method show
518
     * @method show
362
     */
519
     */
363
    show() {
520
    show() {
Línea 364... Línea 521...
364
        super.show(this);
521
        super.show(this);
-
 
522
 
365
 
523
        if (!this.loadedForm) {
366
        if (!this.loadedForm) {
524
            this.tabHtml = this.getBody();
367
            this.loadForm(window.location.search);
525
            this.loadForm(window.location.search);
368
            this.loadedForm = true;
526
            this.loadedForm = true;
369
        }
527
        }