1 |
efrain |
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 |
* This class manages the confirmation pop-up (also called the pre-flight check)
|
|
|
18 |
* that is sometimes shown when a use clicks the start attempt button.
|
|
|
19 |
*
|
|
|
20 |
* This is also responsible for opening the pop-up window, if the quiz requires to be in one.
|
|
|
21 |
*
|
|
|
22 |
* @module mod_quiz/preflightcheck
|
|
|
23 |
* @copyright 2016 The Open University
|
|
|
24 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
25 |
* @since 3.1
|
|
|
26 |
*/
|
|
|
27 |
define(['jquery', 'core/yui', 'core_form/changechecker'], function($, Y, FormChangeChecker) {
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* @alias module:mod_quiz/preflightcheck
|
|
|
31 |
*/
|
|
|
32 |
var t = {
|
|
|
33 |
confirmDialogue: null,
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Initialise the start attempt button.
|
|
|
37 |
*
|
|
|
38 |
* @param {String} startButton the id of the start attempt button that we will be enhancing.
|
|
|
39 |
* @param {String} confirmationTitle the title of the dialogue.
|
|
|
40 |
* @param {String} confirmationForm selector for the confirmation form to show in the dialogue.
|
|
|
41 |
* @param {String} popupoptions If not null, the quiz should be launced in a pop-up.
|
|
|
42 |
*/
|
|
|
43 |
init: function(startButton, confirmationTitle, confirmationForm, popupoptions) {
|
|
|
44 |
var finalStartButton = startButton;
|
|
|
45 |
|
|
|
46 |
Y.use('moodle-core-notification', function() {
|
|
|
47 |
if (Y.one(confirmationForm)) {
|
|
|
48 |
t.confirmDialogue = new M.core.dialogue({
|
|
|
49 |
headerContent: confirmationTitle,
|
|
|
50 |
bodyContent: Y.one(confirmationForm),
|
|
|
51 |
draggable: true,
|
|
|
52 |
visible: false,
|
|
|
53 |
center: true,
|
|
|
54 |
modal: true,
|
|
|
55 |
width: null,
|
|
|
56 |
extraClasses: ['mod_quiz_preflight_popup']
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
Y.one(startButton).on('click', t.displayDialogue);
|
|
|
60 |
Y.one('#id_cancel').on('click', t.hideDialogue);
|
|
|
61 |
|
|
|
62 |
finalStartButton = t.confirmDialogue.get('boundingBox').one('[name="submitbutton"]');
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
if (popupoptions) {
|
|
|
66 |
Y.one(finalStartButton).on('click', t.launchQuizPopup, t, popupoptions);
|
|
|
67 |
}
|
|
|
68 |
});
|
|
|
69 |
},
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Display the dialogue.
|
|
|
73 |
* @param {Y.EventFacade} e the event being responded to, if any.
|
|
|
74 |
*/
|
|
|
75 |
displayDialogue: function(e) {
|
|
|
76 |
if (e) {
|
|
|
77 |
e.halt();
|
|
|
78 |
}
|
|
|
79 |
t.confirmDialogue.show();
|
|
|
80 |
},
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* Hide the dialogue.
|
|
|
84 |
* @param {Y.EventFacade} e the event being responded to, if any.
|
|
|
85 |
*/
|
|
|
86 |
hideDialogue: function(e) {
|
|
|
87 |
if (e) {
|
|
|
88 |
e.halt();
|
|
|
89 |
}
|
|
|
90 |
t.confirmDialogue.hide(e);
|
|
|
91 |
},
|
|
|
92 |
|
|
|
93 |
/**
|
|
|
94 |
* Event handler for the quiz start attempt button.
|
|
|
95 |
* @param {Event} e the event being responded to
|
|
|
96 |
* @param {Object} popupoptions
|
|
|
97 |
*/
|
|
|
98 |
launchQuizPopup: function(e, popupoptions) {
|
|
|
99 |
e.halt();
|
|
|
100 |
Y.use('io-form', function() {
|
|
|
101 |
var form = e.target.ancestor('form');
|
|
|
102 |
|
|
|
103 |
FormChangeChecker.resetFormDirtyState(form.getDOMNode());
|
|
|
104 |
window.openpopup(e, {
|
|
|
105 |
url: form.get('action') + '?' + Y.IO.stringify(form).replace(/\bcancel=/, 'x='),
|
|
|
106 |
windowname: 'quizpopup',
|
|
|
107 |
options: popupoptions,
|
|
|
108 |
fullscreen: true,
|
|
|
109 |
});
|
|
|
110 |
});
|
|
|
111 |
}
|
|
|
112 |
};
|
|
|
113 |
|
|
|
114 |
return t;
|
|
|
115 |
});
|