[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 YUI.add('moodle-mod_quiz-quizquestionbank', function (Y, NAME) { 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 19 /** 20 * Add questions from question bank functionality for a popup in quiz editing page. 21 * 22 * @package mod_quiz 23 * @copyright 2014 The Open University 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 */ 26 27 var CSS = { 28 QBANKLOADING: 'div.questionbankloading', 29 ADDQUESTIONLINKS: 'ul.menu a.questionbank', 30 ADDTOQUIZCONTAINER: 'td.addtoquizaction', 31 PREVIEWCONTAINER: 'td.previewaction', 32 SEARCHOPTIONS: '#advancedsearch' 33 }; 34 35 var PARAMS = { 36 PAGE: 'addonpage', 37 HEADER: 'header' 38 }; 39 40 var POPUP = function() { 41 POPUP.superclass.constructor.apply(this, arguments); 42 }; 43 44 Y.extend(POPUP, Y.Base, { 45 loadingDiv: '', 46 dialogue: null, 47 addonpage: 0, 48 searchRegionInitialised: false, 49 50 create_dialogue: function() { 51 // Create a dialogue on the page and hide it. 52 var config = { 53 headerContent: '', 54 bodyContent: Y.one(CSS.QBANKLOADING), 55 draggable: true, 56 modal: true, 57 centered: true, 58 width: null, 59 visible: false, 60 postmethod: 'form', 61 footerContent: null, 62 extraClasses: ['mod_quiz_qbank_dialogue'] 63 }; 64 this.dialogue = new M.core.dialogue(config); 65 this.dialogue.bodyNode.delegate('click', this.link_clicked, 'a[href]', this); 66 this.dialogue.hide(); 67 68 this.loadingDiv = this.dialogue.bodyNode.getHTML(); 69 70 Y.later(100, this, function() { 71 this.load_content(window.location.search); 72 }); 73 }, 74 75 initializer: function() { 76 if (!Y.one(CSS.QBANKLOADING)) { 77 return; 78 } 79 this.create_dialogue(); 80 Y.one('body').delegate('click', this.display_dialogue, CSS.ADDQUESTIONLINKS, this); 81 }, 82 83 display_dialogue: function(e) { 84 e.preventDefault(); 85 this.dialogue.set('headerContent', e.currentTarget.getData(PARAMS.HEADER)); 86 87 this.addonpage = e.currentTarget.getData(PARAMS.PAGE); 88 var controlsDiv = this.dialogue.bodyNode.one('.modulespecificbuttonscontainer'); 89 if (controlsDiv) { 90 var hidden = controlsDiv.one('input[name=addonpage]'); 91 if (!hidden) { 92 hidden = controlsDiv.appendChild('<input type="hidden" name="addonpage">'); 93 } 94 hidden.set('value', this.addonpage); 95 } 96 97 this.initialiseSearchRegion(); 98 this.dialogue.show(); 99 }, 100 101 load_content: function(queryString) { 102 Y.log('Starting load.', 'debug', 'moodle-mod_quiz-quizquestionbank'); 103 this.dialogue.bodyNode.append(this.loadingDiv); 104 105 // If to support old IE. 106 if (window.history.replaceState) { 107 window.history.replaceState(null, '', M.cfg.wwwroot + '/mod/quiz/edit.php' + queryString); 108 } 109 110 Y.io(M.cfg.wwwroot + '/mod/quiz/questionbank.ajax.php' + queryString, { 111 method: 'GET', 112 on: { 113 success: this.load_done, 114 failure: this.load_failed 115 }, 116 context: this 117 }); 118 119 Y.log('Load request sent.', 'debug', 'moodle-mod_quiz-quizquestionbank'); 120 }, 121 122 load_done: function(transactionid, response) { 123 var result = JSON.parse(response.responseText); 124 if (!result.status || result.status !== 'OK') { 125 // Because IIS is useless, Moodle can't send proper HTTP response 126 // codes, so we have to detect failures manually. 127 this.load_failed(transactionid, response); 128 return; 129 } 130 131 Y.log('Load completed.', 'debug', 'moodle-mod_quiz-quizquestionbank'); 132 133 this.dialogue.bodyNode.setHTML(result.contents); 134 Y.use('moodle-question-chooser', function() { 135 M.question.init_chooser({}); 136 }); 137 this.dialogue.bodyNode.one('form').delegate('change', this.options_changed, '.searchoptions', this); 138 139 if (this.dialogue.visible) { 140 Y.later(0, this.dialogue, this.dialogue.centerDialogue); 141 } 142 M.question.qbankmanager.init(); 143 144 this.searchRegionInitialised = false; 145 if (this.dialogue.get('visible')) { 146 this.initialiseSearchRegion(); 147 } 148 149 this.dialogue.fire('widget:contentUpdate'); 150 // TODO MDL-47602 really, the base class should listen for the even fired 151 // on the previous line, and fix things like makeResponsive. 152 // However, it does not. So the next two lines are a hack to fix up 153 // display issues (e.g. overall scrollbars on the page). Once the base class 154 // is fixed, this comment and the following four lines should be deleted. 155 if (this.dialogue.get('visible')) { 156 this.dialogue.hide(); 157 this.dialogue.show(); 158 } 159 }, 160 161 load_failed: function() { 162 Y.log('Load failed.', 'debug', 'moodle-mod_quiz-quizquestionbank'); 163 }, 164 165 link_clicked: function(e) { 166 // Add question to quiz. mofify the URL, then let it work as normal. 167 if (e.currentTarget.ancestor(CSS.ADDTOQUIZCONTAINER)) { 168 e.currentTarget.set('href', e.currentTarget.get('href') + '&addonpage=' + this.addonpage); 169 return; 170 } 171 172 // Question preview. Needs to open in a pop-up. 173 if (e.currentTarget.ancestor(CSS.PREVIEWCONTAINER)) { 174 window.openpopup(e, { 175 url: e.currentTarget.get('href'), 176 name: 'questionpreview', 177 options: 'height=600,width=800,top=0,left=0,menubar=0,location=0,scrollbars,' + 178 'resizable,toolbar,status,directories=0,fullscreen=0,dependent' 179 }); 180 return; 181 } 182 183 // Click on expand/collaspse search-options. Has its own handler. 184 // We should not interfere. 185 if (e.currentTarget.ancestor(CSS.SEARCHOPTIONS)) { 186 return; 187 } 188 189 // Anything else means reload the pop-up contents. 190 e.preventDefault(); 191 this.load_content(e.currentTarget.get('search')); 192 }, 193 194 options_changed: function(e) { 195 e.preventDefault(); 196 this.load_content('?' + Y.IO.stringify(e.currentTarget.get('form'))); 197 }, 198 199 initialiseSearchRegion: function() { 200 if (this.searchRegionInitialised === true) { 201 return; 202 } 203 if (!Y.one(CSS.SEARCHOPTIONS)) { 204 return; 205 } 206 207 M.util.init_collapsible_region(Y, "advancedsearch", "question_bank_advanced_search", 208 M.util.get_string('clicktohideshow', 'moodle')); 209 this.searchRegionInitialised = true; 210 } 211 }); 212 213 M.mod_quiz = M.mod_quiz || {}; 214 M.mod_quiz.quizquestionbank = M.mod_quiz.quizquestionbank || {}; 215 M.mod_quiz.quizquestionbank.init = function() { 216 return new POPUP(); 217 }; 218 219 220 }, '@VERSION@', { 221 "requires": [ 222 "base", 223 "event", 224 "node", 225 "io", 226 "io-form", 227 "yui-later", 228 "moodle-question-qbankmanager", 229 "moodle-core-notification-dialogue" 230 ] 231 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |