[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* eslint-disable no-unused-vars */ 2 /** 3 * Resource and activity toolbox class. 4 * 5 * This class is responsible for managing AJAX interactions with activities and resources 6 * when viewing a course in editing mode. 7 * 8 * @module moodle-course-toolboxes 9 * @namespace M.course.toolboxes 10 */ 11 12 // The CSS classes we use. 13 var CSS = { 14 ACTIVITYINSTANCE: 'activityinstance', 15 AVAILABILITYINFODIV: 'div.availabilityinfo', 16 CONTENTWITHOUTLINK: 'contentwithoutlink', 17 CONDITIONALHIDDEN: 'conditionalhidden', 18 DIMCLASS: 'dimmed', 19 DIMMEDTEXT: 'dimmed_text', 20 EDITINSTRUCTIONS: 'editinstructions', 21 HIDE: 'hide', 22 MODINDENTCOUNT: 'mod-indent-', 23 MODINDENTHUGE: 'mod-indent-huge', 24 MODULEIDPREFIX: 'module-', 25 SECTIONHIDDENCLASS: 'hidden', 26 SECTIONIDPREFIX: 'section-', 27 SHOW: 'editing_show' 28 }, 29 // The CSS selectors we use. 30 SELECTOR = { 31 ACTIONAREA: '.actions', 32 ACTIONLINKTEXT: '.actionlinktext', 33 ACTIVITYACTION: 'a.cm-edit-action[data-action]', 34 ACTIVITYICON: 'img.activityicon', 35 ACTIVITYINSTANCE: '.' + CSS.ACTIVITYINSTANCE, 36 ACTIVITYLINK: '.' + CSS.ACTIVITYINSTANCE + ' > a, .' + CSS.ACTIVITYINSTANCE + 37 ' > span[data-inplaceeditable] > a:not([data-inplaceeditablelink])', 38 ACTIVITYLI: 'li.activity', 39 COMMANDSPAN: '.commands', 40 CONTENTAFTERLINK: 'div.contentafterlink', 41 CONTENTWITHOUTLINK: 'div.contentwithoutlink', 42 GROUPINGLABEL: '.' + CSS.ACTIVITYINSTANCE + ' .groupinglabel', 43 HIDE: 'a.editing_hide', 44 HIGHLIGHT: 'a.editing_highlight', 45 INSTANCENAME: 'span.instancename', 46 MODINDENTDIV: '.mod-indent', 47 MODINDENTOUTER: '.mod-indent-outer', 48 PAGECONTENT: 'body', 49 SECTIONLI: 'li.section', 50 SHOW: 'a.' + CSS.SHOW, 51 SHOWHIDE: 'a.editing_showhide' 52 }, 53 INDENTLIMITS = { 54 MIN: 0, 55 MAX: 16 56 }, 57 BODY = Y.one(document.body); 58 59 // Setup the basic namespace. 60 M.course = M.course || {}; 61 62 /** 63 * The toolbox class is a generic class which should never be directly 64 * instantiated. Please extend it instead. 65 * 66 * @class toolbox 67 * @constructor 68 * @protected 69 * @extends Base 70 */ 71 var TOOLBOX = function() { 72 TOOLBOX.superclass.constructor.apply(this, arguments); 73 }; 74 75 Y.extend(TOOLBOX, Y.Base, { 76 /** 77 * Send a request using the REST API 78 * 79 * @method send_request 80 * @param {Object} data The data to submit with the AJAX request 81 * @param {Node} [statusspinner] A statusspinner which may contain a section loader 82 * @param {Function} success_callback The callback to use on success 83 * @param {Object} [optionalconfig] Any additional configuration to submit 84 * @chainable 85 */ 86 send_request: function(data, statusspinner, success_callback, optionalconfig) { 87 // Default data structure 88 if (!data) { 89 data = {}; 90 } 91 // Handle any variables which we must pass back through to 92 var pageparams = this.get('config').pageparams, 93 varname; 94 for (varname in pageparams) { 95 data[varname] = pageparams[varname]; 96 } 97 98 data.sesskey = M.cfg.sesskey; 99 data.courseId = this.get('courseid'); 100 101 var uri = M.cfg.wwwroot + this.get('ajaxurl'); 102 103 // Define the configuration to send with the request 104 var responsetext = []; 105 var config = { 106 method: 'POST', 107 data: data, 108 on: { 109 success: function(tid, response) { 110 try { 111 responsetext = Y.JSON.parse(response.responseText); 112 if (responsetext.error) { 113 new M.core.ajaxException(responsetext); 114 } 115 } catch (e) { 116 // Ignore. 117 } 118 119 // Run the callback if we have one. 120 if (success_callback) { 121 Y.bind(success_callback, this, responsetext)(); 122 } 123 124 if (statusspinner) { 125 window.setTimeout(function() { 126 statusspinner.hide(); 127 }, 400); 128 } 129 }, 130 failure: function(tid, response) { 131 if (statusspinner) { 132 statusspinner.hide(); 133 } 134 new M.core.ajaxException(response); 135 } 136 }, 137 context: this 138 }; 139 140 // Apply optional config 141 if (optionalconfig) { 142 for (varname in optionalconfig) { 143 config[varname] = optionalconfig[varname]; 144 } 145 } 146 147 if (statusspinner) { 148 statusspinner.show(); 149 } 150 151 // Send the request 152 Y.io(uri, config); 153 return this; 154 } 155 }, 156 { 157 NAME: 'course-toolbox', 158 ATTRS: { 159 /** 160 * The ID of the Moodle Course being edited. 161 * 162 * @attribute courseid 163 * @default 0 164 * @type Number 165 */ 166 courseid: { 167 'value': 0 168 }, 169 170 /** 171 * The Moodle course format. 172 * 173 * @attribute format 174 * @default 'topics' 175 * @type String 176 */ 177 format: { 178 'value': 'topics' 179 }, 180 /** 181 * The URL to use when submitting requests. 182 * @attribute ajaxurl 183 * @default null 184 * @type String 185 */ 186 ajaxurl: { 187 'value': null 188 }, 189 /** 190 * Any additional configuration passed when creating the instance. 191 * 192 * @attribute config 193 * @default {} 194 * @type Object 195 */ 196 config: { 197 'value': {} 198 } 199 } 200 } 201 );
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 |