[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* global SELECTOR */ 2 /** 3 * Resource drag and drop. 4 * 5 * @class M.course.dragdrop.resource 6 * @constructor 7 * @extends M.core.dragdrop 8 */ 9 var DRAGRESOURCE = function() { 10 DRAGRESOURCE.superclass.constructor.apply(this, arguments); 11 }; 12 Y.extend(DRAGRESOURCE, M.core.dragdrop, { 13 initializer: function() { 14 // Set group for parent class 15 this.groups = ['resource']; 16 this.samenodeclass = CSS.ACTIVITY; 17 this.parentnodeclass = CSS.SECTION; 18 this.resourcedraghandle = this.get_drag_handle(M.util.get_string('move', 'moodle'), CSS.EDITINGMOVE, CSS.ICONCLASS, true); 19 20 this.samenodelabel = { 21 identifier: 'dragtoafter', 22 component: 'quiz' 23 }; 24 this.parentnodelabel = { 25 identifier: 'dragtostart', 26 component: 'quiz' 27 }; 28 29 // Go through all sections 30 this.setup_for_section(); 31 32 // Initialise drag & drop for all resources/activities 33 var nodeselector = 'li.' + CSS.ACTIVITY; 34 var del = new Y.DD.Delegate({ 35 container: '.' + CSS.COURSECONTENT, 36 nodes: nodeselector, 37 target: true, 38 handles: ['.' + CSS.EDITINGMOVE], 39 dragConfig: {groups: this.groups} 40 }); 41 del.dd.plug(Y.Plugin.DDProxy, { 42 // Don't move the node at the end of the drag 43 moveOnEnd: false, 44 cloneNode: true 45 }); 46 del.dd.plug(Y.Plugin.DDConstrained, { 47 // Keep it inside the .mod-quiz-edit-content 48 constrain: '#' + CSS.SLOTS 49 }); 50 del.dd.plug(Y.Plugin.DDWinScroll); 51 52 M.mod_quiz.quizbase.register_module(this); 53 M.mod_quiz.dragres = this; 54 }, 55 56 /** 57 * Apply dragdrop features to the specified selector or node that refers to section(s) 58 * 59 * @method setup_for_section 60 * @param {String} baseselector The CSS selector or node to limit scope to 61 */ 62 setup_for_section: function() { 63 Y.Node.all('.mod-quiz-edit-content ul.slots ul.section').each(function(resources) { 64 resources.setAttribute('data-draggroups', this.groups.join(' ')); 65 // Define empty ul as droptarget, so that item could be moved to empty list 66 new Y.DD.Drop({ 67 node: resources, 68 groups: this.groups, 69 padding: '20 0 20 0' 70 }); 71 72 // Initialise each resource/activity in this section 73 this.setup_for_resource('li.activity'); 74 }, this); 75 }, 76 77 /** 78 * Apply dragdrop features to the specified selector or node that refers to resource(s) 79 * 80 * @method setup_for_resource 81 * @param {String} baseselector The CSS selector or node to limit scope to 82 */ 83 setup_for_resource: function(baseselector) { 84 Y.Node.all(baseselector).each(function(resourcesnode) { 85 // Replace move icons 86 var move = resourcesnode.one('a.' + CSS.EDITINGMOVE); 87 if (move) { 88 move.replace(this.resourcedraghandle.cloneNode(true)); 89 } 90 }, this); 91 }, 92 93 drag_start: function(e) { 94 // Get our drag object 95 var drag = e.target; 96 drag.get('dragNode').setContent(drag.get('node').get('innerHTML')); 97 drag.get('dragNode').all('img.iconsmall').setStyle('vertical-align', 'baseline'); 98 }, 99 100 drag_dropmiss: function(e) { 101 // Missed the target, but we assume the user intended to drop it 102 // on the last ghost node location, e.drag and e.drop should be 103 // prepared by global_drag_dropmiss parent so simulate drop_hit(e). 104 this.drop_hit(e); 105 }, 106 107 drop_hit: function(e) { 108 var drag = e.drag; 109 // Get a reference to our drag node 110 var dragnode = drag.get('node'); 111 var dropnode = e.drop.get('node'); 112 113 // Add spinner if it not there 114 var actionarea = dragnode.one(CSS.ACTIONAREA); 115 var spinner = M.util.add_spinner(Y, actionarea); 116 117 var params = {}; 118 119 // Handle any variables which we must pass back through to 120 var pageparams = this.get('config').pageparams; 121 var varname; 122 for (varname in pageparams) { 123 params[varname] = pageparams[varname]; 124 } 125 126 // Prepare request parameters 127 params.sesskey = M.cfg.sesskey; 128 params.courseid = this.get('courseid'); 129 params.quizid = this.get('quizid'); 130 params['class'] = 'resource'; 131 params.field = 'move'; 132 params.id = Number(Y.Moodle.mod_quiz.util.slot.getId(dragnode)); 133 params.sectionId = Y.Moodle.core_course.util.section.getId(dropnode.ancestor('li.section', true)); 134 135 var previousslot = dragnode.previous(SELECTOR.SLOT); 136 if (previousslot) { 137 params.previousid = Number(Y.Moodle.mod_quiz.util.slot.getId(previousslot)); 138 } 139 140 var previouspage = dragnode.previous(SELECTOR.PAGE); 141 if (previouspage) { 142 params.page = Number(Y.Moodle.mod_quiz.util.page.getId(previouspage)); 143 } 144 145 // Do AJAX request 146 var uri = M.cfg.wwwroot + this.get('ajaxurl'); 147 148 Y.io(uri, { 149 method: 'POST', 150 data: params, 151 on: { 152 start: function() { 153 this.lock_drag_handle(drag, CSS.EDITINGMOVE); 154 spinner.show(); 155 }, 156 success: function(tid, response) { 157 var responsetext = Y.JSON.parse(response.responseText); 158 var params = {element: dragnode, visible: responsetext.visible}; 159 M.mod_quiz.quizbase.invoke_function('set_visibility_resource_ui', params); 160 this.unlock_drag_handle(drag, CSS.EDITINGMOVE); 161 window.setTimeout(function() { 162 spinner.hide(); 163 }, 250); 164 M.mod_quiz.resource_toolbox.reorganise_edit_page(); 165 }, 166 failure: function(tid, response) { 167 this.ajax_failure(response); 168 this.unlock_drag_handle(drag, CSS.SECTIONHANDLE); 169 spinner.hide(); 170 window.location.reload(true); 171 } 172 }, 173 context: this 174 }); 175 }, 176 177 global_drop_over: function(e) { 178 // Overriding parent method so we can stop the slots being dragged before the first page node. 179 180 // Check that drop object belong to correct group. 181 if (!e.drop || !e.drop.inGroup(this.groups)) { 182 return; 183 } 184 185 // Get a reference to our drag and drop nodes. 186 var drag = e.drag.get('node'), 187 drop = e.drop.get('node'); 188 189 // Save last drop target for the case of missed target processing. 190 this.lastdroptarget = e.drop; 191 192 // Are we dropping within the same parent node? 193 if (drop.hasClass(this.samenodeclass)) { 194 var where; 195 196 if (this.goingup) { 197 where = "before"; 198 } else { 199 where = "after"; 200 } 201 202 drop.insert(drag, where); 203 } else if ((drop.hasClass(this.parentnodeclass) || drop.test('[data-droptarget="1"]')) && !drop.contains(drag)) { 204 // We are dropping on parent node and it is empty 205 if (this.goingup) { 206 drop.append(drag); 207 } else { 208 drop.prepend(drag); 209 } 210 } 211 this.drop_over(e); 212 } 213 }, { 214 NAME: 'mod_quiz-dragdrop-resource', 215 ATTRS: { 216 courseid: { 217 value: null 218 }, 219 quizid: { 220 value: null 221 }, 222 ajaxurl: { 223 value: 0 224 }, 225 config: { 226 value: 0 227 } 228 } 229 }); 230 231 M.mod_quiz = M.mod_quiz || {}; 232 M.mod_quiz.init_resource_dragdrop = function(params) { 233 new DRAGRESOURCE(params); 234 };
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 |