2 * The quizbase class to provide shared functionality to Modules within Moodle.
4 * @module moodle-mod_quiz-quizbase
6 var QUIZBASENAME = 'mod_quiz-quizbase';
8 var QUIZBASE = function() {
9 QUIZBASE.superclass.constructor.apply(this, arguments);
13 * The coursebase class to provide shared functionality to Modules within
16 * @class M.course.coursebase
19 Y.extend(QUIZBASE, Y.Base, {
24 * Register a new Javascript Module
26 * @method register_module
27 * @param {Object} The instantiated module to call functions on
30 register_module : function(object) {
31 this.registermodules.push(object);
37 * Invoke the specified function in all registered modules with the given arguments
39 * @method invoke_function
40 * @param {String} functionname The name of the function to call
41 * @param {mixed} args The argument supplied to the function
44 invoke_function : function(functionname, args) {
46 for (module in this.registermodules) {
47 if (functionname in this.registermodules[module]) {
48 this.registermodules[module][functionname](args);
59 // Ensure that M.course exists and that coursebase is initialised correctly
60 M.mod_quiz = M.mod_quiz || {};
61 M.mod_quiz.quizbase = M.mod_quiz.quizbase || new QUIZBASE();
63 // Abstract functions that needs to be defined per format (course/format/somename/format.js)
64 M.mod_quiz.edit = M.mod_quiz.edit || {};
67 * Swap section (should be defined in format.js if requred)
69 * @param {YUI} Y YUI3 instance
70 * @param {string} node1 node to swap to
71 * @param {string} node2 node to swap with
72 * @return {NodeList} section list
74 M.mod_quiz.edit.swap_sections = function(Y, node1, node2) {
76 COURSECONTENT : 'mod-quiz-edit-content',
77 SECTIONADDMENUS : 'section_add_menus'
80 var sectionlist = Y.Node.all('.' + CSS.COURSECONTENT + ' li.section');
82 sectionlist.item(node1).one('.' + CSS.SECTIONADDMENUS).swap(sectionlist.item(node2).one('.' + CSS.SECTIONADDMENUS));
86 * Process sections after ajax response (should be defined in format.js)
87 * If some response is expected, we pass it over to format, as it knows better
90 * @param {YUI} Y YUI3 instance
91 * @param {NodeList} list of sections
92 * @param {array} response ajax response
93 * @param {string} sectionfrom first affected section
94 * @param {string} sectionto last affected section
97 M.mod_quiz.edit.process_sections = function(Y, sectionlist, response, sectionfrom, sectionto) {
99 SECTIONNAME : 'sectionname'
102 SECTIONLEFTSIDE : '.left .section-handle img'
105 if (response.action === 'move') {
106 // If moving up swap around 'sectionfrom' and 'sectionto' so the that loop operates.
107 if (sectionfrom > sectionto) {
108 var temp = sectionto;
109 sectionto = sectionfrom;
113 // Update titles and move icons in all affected sections.
114 var ele, str, stridx, newstr;
116 for (var i = sectionfrom; i <= sectionto; i++) {
117 // Update section title.
118 sectionlist.item(i).one('.' + CSS.SECTIONNAME).setContent(response.sectiontitles[i]);
121 ele = sectionlist.item(i).one(SELECTORS.SECTIONLEFTSIDE);
122 str = ele.getAttribute('alt');
123 stridx = str.lastIndexOf(' ');
124 newstr = str.substr(0, stridx + 1) + i;
125 ele.setAttribute('alt', newstr);
126 ele.setAttribute('title', newstr); // For FireFox as 'alt' is not refreshed.
128 // Remove the current class as section has been moved.
129 sectionlist.item(i).removeClass('current');
131 // If there is a current section, apply corresponding class in order to highlight it.
132 if (response.current !== -1) {
133 // Add current class to the required section.
134 sectionlist.item(response.current).addClass('current');