[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 YUI.add('moodle-report_loglive-fetchlogs', function (Y, NAME) { 2 3 /** 4 * A module to manage ajax requests. 5 * 6 * @module moodle-report_loglive-fetchlogs 7 */ 8 9 /** 10 * A module to manage ajax requests. 11 * 12 * @class moodle-report_loglive.fetchlogs 13 * @extends Base 14 * @constructor 15 */ 16 function FetchLogs() { 17 FetchLogs.superclass.constructor.apply(this, arguments); 18 } 19 20 21 var CSS = { 22 NEWROW: 'newrow', 23 SPINNER: 'spinner', 24 ICONSMALL: 'iconsmall' 25 }, 26 SELECTORS = { 27 NEWROW: '.' + CSS.NEWROW, 28 TBODY: '.flexible tbody', 29 PAUSEBUTTON: '#livelogs-pause-button', 30 SPINNER: '.' + CSS.SPINNER 31 }; 32 33 Y.extend(FetchLogs, Y.Base, { 34 /** 35 * Reference to the callBack object generated by Y.later 36 * 37 * @property callBack 38 * @type Object 39 * @default {} 40 * @protected 41 */ 42 callBack: {}, 43 44 /** 45 * Reference to the spinner node. 46 * 47 * @property callBack 48 * @type Object 49 * @default {} 50 * @protected 51 */ 52 spinner: {}, 53 54 /** 55 * Reference to the toggleButton node. 56 * 57 * @property pauseButton 58 * @type Object 59 * @default {} 60 * @protected 61 */ 62 pauseButton: {}, 63 64 /** 65 * Initializer. 66 * Basic setup and delegations. 67 * 68 * @method initializer 69 */ 70 initializer: function() { 71 // We don't want the pages to be updated when viewing a specific page in the chain. 72 if (this.get('page') === 0) { 73 this.callBack = Y.later(this.get('interval') * 1000, this, this.fetchRecentLogs, null, true); 74 } 75 76 this.spinner = Y.one(SELECTORS.SPINNER); 77 this.pauseButton = Y.one(SELECTORS.PAUSEBUTTON); 78 this.spinner.hide(); 79 Y.delegate('click', this.toggleUpdate, 'button', SELECTORS.PAUSEBUTTON, this); 80 }, 81 82 /** 83 * Method to fetch recent logs. 84 * 85 * @method fetchRecentLogs 86 */ 87 fetchRecentLogs: function() { 88 this.spinner.show(); // Show a loading icon. 89 var data = { 90 logreader: this.get('logreader'), 91 since: this.get('since'), 92 page: this.get('page'), 93 id: this.get('courseid') 94 }; 95 var cfg = { 96 method: 'get', 97 context: this, 98 on: { 99 complete: this.updateLogTable 100 }, 101 data: data 102 }; 103 var url = M.cfg.wwwroot + '/report/loglive/loglive_ajax.php'; 104 Y.io(url, cfg); 105 }, 106 107 /** 108 * Method to update the log table, populate the table with new entries and remove old entries if needed. 109 * 110 * @method updateLogTable 111 */ 112 updateLogTable: function(tid, response) { 113 // Hide loading icon, give sometime to people to actually see it. We should do it, event in case of an error. 114 Y.later(600, this, 'hideLoadingIcon'); 115 var responseobject; 116 // Attempt to parse the response into an object. 117 try { 118 responseobject = Y.JSON.parse(response.responseText); 119 if (responseobject.error) { 120 Y.use('moodle-core-notification-ajaxexception', function() { 121 return new M.core.ajaxException(responseobject); 122 }); 123 return this; 124 } 125 } catch (error) { 126 Y.use('moodle-core-notification-exception', function() { 127 return new M.core.exception(error); 128 }); 129 return this; 130 } 131 this.set('since', responseobject.until); 132 var logs = responseobject.logs; 133 var tbody = Y.one(SELECTORS.TBODY); 134 var firstTr = null; 135 if (tbody && logs) { 136 firstTr = tbody.get('firstChild'); 137 if (firstTr) { 138 tbody.insertBefore(logs, firstTr); 139 } 140 // @Todo, when no data is present our library should generate an empty table. so data can be added 141 // dynamically (MDL-44525). 142 143 // Let us chop off some data from end of table to prevent really long pages. 144 var oldChildren = tbody.get('children').slice(this.get('perpage')); 145 oldChildren.remove(); 146 Y.later(5000, this, 'removeHighlight', responseobject.until); // Remove highlighting from new rows. 147 } 148 }, 149 150 /** 151 * Remove background highlight from the newly added rows. 152 * 153 * @method removeHighlight 154 */ 155 removeHighlight: function(timeStamp) { 156 Y.all('.time' + timeStamp).removeClass(CSS.NEWROW); 157 }, 158 159 /** 160 * Hide the spinning icon. 161 * 162 * @method hideLoadingIcon 163 */ 164 hideLoadingIcon: function() { 165 this.spinner.hide(); 166 }, 167 168 /** 169 * Toggle live update. 170 * 171 * @method toggleUpdate 172 */ 173 toggleUpdate: function() { 174 if (this.callBack) { 175 this.callBack.cancel(); 176 this.callBack = ''; 177 this.pauseButton.setContent(M.util.get_string('resume', 'report_loglive')); 178 } else { 179 this.callBack = Y.later(this.get('interval') * 1000, this, this.fetchRecentLogs, null, true); 180 this.pauseButton.setContent(M.util.get_string('pause', 'report_loglive')); 181 } 182 } 183 }, { 184 NAME: 'fetchLogs', 185 ATTRS: { 186 /** 187 * time stamp from where the new logs needs to be fetched. 188 * 189 * @attribute since 190 * @default null 191 * @type String 192 */ 193 since: null, 194 195 /** 196 * courseid for which the logs are shown. 197 * 198 * @attribute courseid 199 * @default 0 200 * @type int 201 */ 202 courseid: 0, 203 204 /** 205 * Page number shown to user. 206 * 207 * @attribute page 208 * @default 0 209 * @type int 210 */ 211 page: 0, 212 213 /** 214 * Items to show per page. 215 * 216 * @attribute perpage 217 * @default 100 218 * @type int 219 */ 220 perpage: 100, 221 222 /** 223 * Refresh interval. 224 * 225 * @attribute interval 226 * @default 60 227 * @type int 228 */ 229 interval: 60, 230 231 /** 232 * Which logstore is being used. 233 * 234 * @attribute logreader 235 * @default logstore_standard 236 * @type String 237 */ 238 logreader: 'logstore_standard' 239 } 240 }); 241 242 Y.namespace('M.report_loglive.FetchLogs').init = function(config) { 243 return new FetchLogs(config); 244 }; 245 246 247 }, '@VERSION@', {"requires": ["base", "event", "node", "io", "node-event-delegate"]});
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 |