[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 /***************************************************************************\ 2 * eGroupWare - API * 3 * http://www.egroupware.org * 4 * Written by: * 5 * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * 6 * sponsored by Thyamad - http://www.thyamad.com * 7 * ------------------------------------------------------------------------- * 8 * Javascript connector (XMLHTTP object interfacing) * 9 * ------------------------------------------------------------------------- * 10 * This program is free software; you can redistribute it and/or modify it * 11 * under the terms of the GNU General Public License as published by the * 12 * Free Software Foundation; either version 2 of the License, or (at your * 13 * option) any later version. * 14 \***************************************************************************/ 15 16 function cConnector() 17 { 18 /* Public Attributes */ 19 this.requests = new Array(); 20 this.progressContents = new Array(); 21 this.visible = false; 22 23 var _this = this; 24 this.nReqs = 0; 25 26 /* Private Attributes */ 27 this._progressBox = null; 28 this._progressHolder = document.createElement('span'); 29 30 /* Removed display of connecting status 31 this.setProgressBox('loading_box',true); 32 this.setProgressContent(1,GLOBALS['messages']['jsapi']['connector_1']); 33 this.setProgressContent(2,GLOBALS['messages']['jsapi']['connector_2']); 34 this.setProgressContent(3,GLOBALS['messages']['jsapi']['connector_3']);*/ 35 36 this._progressHolder.style.visibility = 'hidden'; 37 // this._progressHolder.style.backgroundColor = '#db7e22'; 38 } 39 40 cConnector.prototype.newRequest = function (id, target, method, handler, data) 41 { 42 var _this = this; 43 44 if (this.requests[id] && this.requests[id] != null) 45 { 46 // TODO: Study better ways to do this... 47 return; 48 49 this.requests[id].abort(); 50 delete this.requests[id]; 51 52 setTimeout(function() { _this.newRequest(id, target, method, handler, data); }, 100); 53 54 return; 55 } 56 57 this.nReqs++; 58 document.body.style.cursor = 'progress'; 59 60 var oxmlhttp = null; 61 62 try 63 { 64 oxmlhttp = new XMLHttpRequest(); 65 oxmlhttp.overrideMimeType('text/xml'); 66 } 67 catch (e) 68 { 69 try 70 { 71 oxmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); 72 } 73 catch (e1) 74 { 75 try 76 { 77 oxmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); 78 } 79 catch (e2) 80 { 81 oxmlhttp = null; 82 } 83 } 84 } 85 86 if (!oxmlhttp) 87 { 88 return false; 89 } 90 91 this.requests[id] = oxmlhttp; 92 93 var _this = this; 94 95 var sub_handler = function () 96 { 97 try 98 { 99 _this._setProgressState(oxmlhttp.readyState); 100 101 if (oxmlhttp.readyState == 4 )//&& oxmlhttp.channel.status == 0) 102 { 103 if (!oxmlhttp || !oxmlhttp.status) 104 { 105 return; 106 } 107 108 if (dynapi.debug) 109 { 110 dynapi.debug.print('\nServer Message Arrived:\n\n'+oxmlhttp.responseText+'\n\n'); 111 } 112 switch (oxmlhttp.status) 113 { 114 case 200: 115 if (typeof(handler) == 'function') 116 { 117 handler(oxmlhttp.responseText); 118 } 119 delete _this.requests[id]; 120 _this.nReqs--; 121 if (!_this.nReqs) document.body.style.cursor = ''; 122 break; 123 124 case 404: 125 alert('Page Not Found!'); 126 break; 127 128 default: 129 //alert('Some problem while accessing the server. The status is '+oxmlhttp.status); 130 } 131 } 132 } 133 catch (e) 134 { 135 _this.nReqs--; 136 if (!_this.nReqs) document.body.style.cursor = ''; 137 delete _this.requests[id]; 138 139 // TODO: Handle of special exceptions must be made by API 140 141 // Exception 0x80040111 => trying to access a component without permission to do so 142 if (e && typeof(e) == 'object' && e.result && e.result == 0x80040111) 143 { 144 return; 145 } 146 147 showMessage(e); 148 } 149 } 150 151 try 152 { 153 if (method == '' || method == 'GET') 154 { 155 if (typeof(handler) == 'function') 156 { 157 oxmlhttp.onreadystatechange = sub_handler; 158 } 159 oxmlhttp.open("GET",target,true); 160 oxmlhttp.send(null); 161 } 162 else if (method == 'POST') 163 { 164 if (typeof(handler) == 'function') 165 { 166 oxmlhttp.onreadystatechange = sub_handler; 167 } 168 oxmlhttp.open("POST",target, true); 169 // oxmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 170 // viniciuscb commented here, messages should be in xmlrpc 171 oxmlhttp.setRequestHeader('Content-Type','text/xml'); 172 oxmlhttp.send(data); 173 //oxmlhttp.setRequestHeader('Content-Type','multipart/form-data; boundary=-----------------------------1156053686807595044986274307'); 174 //oxmlhttp.setRequestHeader('Accept', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'); 175 } 176 } 177 catch(e) 178 { 179 showMessage(e); 180 } 181 182 return true; 183 } 184 185 cConnector.prototype.cancelRequest = function (id) 186 { 187 if (!this.requests[id]) 188 { 189 return false; 190 } 191 192 this.requests[id].abort(); 193 } 194 195 cConnector.prototype.setProgressContent = function (state, content) 196 { 197 switch (state) 198 { 199 case 0: 200 case 'UNINITIALIZED': 201 this.progressContents[0] = content; 202 break; 203 204 case 1: 205 case 'LOADING': 206 this.progressContents[1] = content; 207 break; 208 209 case 2: 210 case 'LOADED': 211 this.progressContents[2] = content; 212 break; 213 214 case 3: 215 case 'INTERACTIVE': 216 this.progressContents[3] = content; 217 break; 218 219 case 4: 220 case 'COMPLETED': 221 this.progressContents[4] = content; 222 break; 223 224 default: 225 throw('INVALID STATE!'); 226 } 227 } 228 229 cConnector.prototype.setProgressHolder = function (holder) 230 { 231 var objHolder; 232 233 if (typeof(holder) == 'string') 234 { 235 objHolder = Element(holder); 236 } 237 else if (typeof(holder) == 'object') 238 { 239 objHolder = holder; 240 } 241 else 242 { 243 return false; 244 } 245 246 objHolder.appendChild(this._progressHolder); 247 } 248 249 cConnector.prototype.setProgressBox = function (box, auto) 250 { 251 var objBox; 252 253 if (typeof(box) == 'string') 254 { 255 objBox = Element(box); 256 } 257 else if (typeof(box) == 'object') 258 { 259 objBox = box; 260 } 261 else 262 { 263 return false; 264 } 265 266 this._progressBox = objBox; 267 this._progressBoxAuto = auto ? true : false; 268 objBox.appendChild(this._progressHolder); 269 } 270 271 cConnector.prototype.setVisible = function (visible) 272 { 273 this.visible = visible; 274 if (!visible) 275 { 276 this._progressHolder.style.visibility = 'hidden'; 277 } 278 } 279 280 /****************************************************************************\ 281 * Private Methods * 282 \****************************************************************************/ 283 284 cConnector.prototype._setProgressState = function (state) 285 { 286 switch (state) 287 { 288 case 0: 289 case 4: 290 if (this._progressBox != null) 291 { 292 this._progressBox.style.visibility = 'hidden'; 293 this._progressBox.style.zIndex = '-1'; 294 } 295 296 this._progressHolder.style.visibility = 'hidden'; 297 this._progressHolder.style.zIndex = '-1'; 298 break; 299 300 default: 301 if (this.visible) 302 { 303 if (this._progressBox != null) 304 { 305 if (this._progressBoxAuto) 306 { 307 if (is_ie) 308 { 309 this._progressBox.style.top = parseInt(document.body.offsetHeight)/2 + 'px'; 310 this._progressBox.style.left = parseInt(document.body.offsetWidth)/2 + 'px'; 311 } 312 else 313 { 314 this._progressBox.style.top = parseInt(window.innerHeight)/2 + parseInt(window.pageYOffset) - this._progressBox.style.height/2 + 'px'; 315 this._progressBox.style.left = parseInt(window.innerWidth)/2 + parseInt(window.pageXOffset) - this._progressBox.style.width/2 + 'px'; 316 } 317 } 318 this._progressBox.style.visibility = 'inherit'; 319 this._progressBox.style.zIndex = 1000000; 320 } 321 322 this._progressHolder.style.visibility = 'inherit'; 323 this._progressHolder.style.zIndex = '100'; 324 325 this._progressHolder.innerHTML = this.progressContents[state] ? this.progressContents[state] : ''; 326 } 327 } 328 } 329 330 var Connector; 331 dynapi.onLoad(function(){ 332 Connector = new cConnector(); 333 Connector.setVisible(true); 334 });
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |