1 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 * Initialise the question bank modal on the quiz page.
19 * @module mod_quiz/quizquestionbank
21 * @copyright 2018 Ryan Wyllie <ryan@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 'core/custom_interaction_events',
30 'mod_quiz/modal_quiz_question_bank'
41 ADD_QUESTION_LINKS: '.menu [data-action="questionbank"]',
45 init: function(contextId) {
48 // Create a question bank modal using the factory.
49 // The same modal will be used by all of the add question
50 // links on the page. The content of the modal will be
51 // changed depending on which link is clicked.
54 type: ModalQuizQuestionBank.TYPE,
57 // Created a deligated listener rather than a single
59 [body, SELECTORS.ADD_QUESTION_LINKS]
60 ).then(function(modal) {
61 // Save the Moodle context id that the modal is being rendered in.
62 modal.setContextId(contextId);
64 body.on(CustomEvents.events.activate, SELECTORS.ADD_QUESTION_LINKS, function(e) {
65 // We need to listen for activations on the trigger elements because there are
66 // several on the page and we need to know which one was activated in order to
67 // set some relevant data on the modal.
68 var triggerElement = $(e.target).closest(SELECTORS.ADD_QUESTION_LINKS);
69 modal.setAddOnPageId(triggerElement.attr('data-addonpage'));
70 modal.setTitle(triggerElement.attr('data-header'));
74 }).fail(Notification.exception);