MDL-40988 quiz: ability to break quizzes into sections
[moodle.git] / mod / quiz / yui / src / modform / js / modform.js
blobb6ee7aaae90e3e4f68813fc6f4680d94d991bdea
1 /**
2  * The modform class has all the JavaScript specific to mod/quiz/mod_form.php.
3  *
4  * @module moodle-mod_quiz-modform
5  */
7 var MODFORM = function() {
8     MODFORM.superclass.constructor.apply(this, arguments);
9 };
11 /**
12  * The coursebase class to provide shared functionality to Modules within
13  * Moodle.
14  *
15  * @class M.course.coursebase
16  * @constructor
17  */
18 Y.extend(MODFORM, Y.Base, {
19     repaginateCheckbox: null,
20     qppSelect: null,
21     qppInitialValue: 0,
23     initializer: function () {
24         this.repaginateCheckbox = Y.one('#id_repaginatenow');
25         if (!this.repaginateCheckbox) {
26             // The checkbox only appears when editing an existing quiz.
27             return;
28         }
30         this.qppSelect = Y.one('#id_questionsperpage');
31         this.qppInitialValue = this.qppSelect.get('value');
32         this.qppSelect.on('change', this.qppChanged, this);
33     },
35     qppChanged: function() {
36         Y.later(50, this, function() {
37             if (!this.repaginateCheckbox.get('disabled')) {
38                 this.repaginateCheckbox.set('checked', this.qppSelect.get('value') !== this.qppInitialValue);
39             }
40         });
41     }
43 });
45 // Ensure that M.mod_quiz exists and that coursebase is initialised correctly
46 M.mod_quiz = M.mod_quiz || {};
47 M.mod_quiz.modform = M.mod_quiz.modform || new MODFORM();
48 M.mod_quiz.modform.init = function() {
49     return new MODFORM();