[2] | 1 | /****************************************** Public variables *************************************************/ |
---|
| 2 | var debug_controller =false; |
---|
| 3 | var files = new Array(); |
---|
| 4 | var progressBar; |
---|
[1369] | 5 | var handlerExecuteForm = null; |
---|
[2] | 6 | |
---|
| 7 | if (document.all) |
---|
| 8 | { |
---|
| 9 | navigator.userAgent.toLowerCase().indexOf('msie 5') != -1 ? is_ie5 = true : is_ie5 = false; |
---|
| 10 | is_ie = true; |
---|
| 11 | is_moz1_6 = false; |
---|
| 12 | is_mozilla = false; |
---|
[4062] | 13 | is_webkit = false; |
---|
[2] | 14 | is_ns4 = false; |
---|
| 15 | } |
---|
| 16 | else if (document.getElementById) |
---|
| 17 | { |
---|
| 18 | navigator.userAgent.toLowerCase().match('mozilla.*rv[:]1\.6.*gecko') ? is_moz1_6 = true : is_moz1_6 = false; |
---|
[4062] | 19 | navigator.userAgent.toLowerCase().match('applewebkit') ? is_webkit = true : is_webkit = false; |
---|
[2] | 20 | is_ie = false; |
---|
| 21 | is_ie5 = false; |
---|
| 22 | is_mozilla = true; |
---|
| 23 | is_ns4 = false; |
---|
| 24 | } |
---|
| 25 | else if (document.layers) |
---|
| 26 | { |
---|
| 27 | is_ie = false; |
---|
| 28 | is_ie5 = false |
---|
| 29 | is_moz1_6 = false; |
---|
| 30 | is_mozilla = false; |
---|
[4062] | 31 | is_webkit = false; |
---|
[2] | 32 | is_ns4 = true; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | /****************************************** Connector Class *************************************************/ |
---|
| 36 | // Constructor |
---|
| 37 | function cConnector() |
---|
| 38 | { |
---|
| 39 | this.requests = new Array(); |
---|
| 40 | this.oxmlhttp = null; |
---|
| 41 | this.isVisibleBar = false; |
---|
| 42 | this.tid = 0; |
---|
| 43 | this.progressBar = null; |
---|
| 44 | this.oldX = 0; |
---|
| 45 | this.oldY = 0; |
---|
[1443] | 46 | this.updateVersion = ""; |
---|
| 47 | this.connectorCache = { |
---|
| 48 | 'valid' : [], |
---|
| 49 | 'result' : [] |
---|
| 50 | }; |
---|
| 51 | this.expurgatedCache = new Array(); // Data to purge from cache |
---|
| 52 | |
---|
[2] | 53 | } |
---|
| 54 | |
---|
| 55 | cConnector.prototype.buildBar = function() |
---|
| 56 | { |
---|
| 57 | var div = document.getElementById('divProgressBar'); |
---|
| 58 | |
---|
| 59 | if(! div) { |
---|
| 60 | div = document.createElement("DIV"); |
---|
| 61 | div.style.visibility = "hidden"; |
---|
| 62 | div.style.width = "103px"; |
---|
| 63 | div.id = 'divProgressBar'; |
---|
| 64 | div.align = "center"; |
---|
| 65 | div.innerHTML = ' <font face="Verdana" size="2" color="WHITE">'+document.getElementById('txt_loading').value+'...</font> '; |
---|
| 66 | div.style.background = "#cc4444"; |
---|
| 67 | div.style.position = 'fixed'; |
---|
| 68 | div.style.top = '0px'; |
---|
| 69 | div.style.right = '0px'; |
---|
| 70 | document.body.appendChild(div); |
---|
| 71 | |
---|
| 72 | if(is_ie) { |
---|
| 73 | var elem = document.all[div.id]; |
---|
| 74 | elem.style.position="absolute"; |
---|
| 75 | var root = document.body; |
---|
| 76 | var posX = elem.offsetLeft-root.scrollLeft; |
---|
| 77 | var posY = elem.offsetTop-root.scrollTop; |
---|
| 78 | root.onscroll = function() { |
---|
| 79 | elem.style.right = '0px'; |
---|
| 80 | elem.style.top = (posY + root.scrollTop) + "px"; |
---|
| 81 | }; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | if(debug_controller) { |
---|
| 85 | div = document.createElement("DIV"); |
---|
| 86 | div.style.width = "800px"; |
---|
| 87 | div.style.height= "400px"; |
---|
| 88 | div.id = "debug_controller"; |
---|
| 89 | div.align='right'; |
---|
| 90 | document.body.appendChild(div); |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | //------------------------------------ BEGIN: Functions for Connector HTTPRequest -------------------------------------------------// |
---|
| 95 | // Serialize Data Method |
---|
| 96 | cConnector.prototype.serialize = function(data) |
---|
| 97 | { var _thisObject = this; |
---|
| 98 | var f = function(data) |
---|
| 99 | { |
---|
| 100 | var str_data; |
---|
| 101 | |
---|
| 102 | if (data == null || |
---|
| 103 | (typeof(data) == 'string' && data == '')) |
---|
| 104 | { |
---|
| 105 | str_data = 'N;'; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | else switch(typeof(data)) |
---|
| 109 | { |
---|
| 110 | case 'object': |
---|
| 111 | var arrayCount = 0; |
---|
| 112 | |
---|
| 113 | str_data = ''; |
---|
| 114 | |
---|
| 115 | for (i in data) |
---|
| 116 | { |
---|
| 117 | if (i == 'length') |
---|
| 118 | { |
---|
| 119 | continue; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | arrayCount++; |
---|
| 123 | switch (typeof(i)) |
---|
| 124 | { |
---|
| 125 | case 'number': |
---|
[1444] | 126 | str_data += 'i:' + i + ';' + f(data[i]); |
---|
[2] | 127 | break; |
---|
| 128 | |
---|
| 129 | case 'string': |
---|
[1444] | 130 | str_data += 's:' + i.length + ':"' + i + '";' + f(data[i]); |
---|
[2] | 131 | break; |
---|
| 132 | |
---|
| 133 | default: |
---|
| 134 | showMessage(Element('cc_msg_err_serialize_data_unknown').value); |
---|
| 135 | break; |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | if (!arrayCount) |
---|
| 140 | { |
---|
| 141 | str_data = 'N;'; |
---|
| 142 | } |
---|
| 143 | else |
---|
| 144 | { |
---|
| 145 | str_data = 'a:' + arrayCount + ':{' + str_data + '}'; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | break; |
---|
| 149 | |
---|
| 150 | case 'string': |
---|
| 151 | str_data = 's:' + data.length + ':"' + data + '";'; |
---|
| 152 | break; |
---|
| 153 | |
---|
| 154 | case 'number': |
---|
| 155 | str_data = 'i:' + data + ';'; |
---|
| 156 | break; |
---|
| 157 | |
---|
| 158 | case 'boolean': |
---|
| 159 | str_data = 'b:' + (data ? '1' : '0') + ';'; |
---|
| 160 | break; |
---|
| 161 | |
---|
| 162 | default: |
---|
| 163 | showMessage(Element('cc_msg_err_serialize_data_unknown').value); |
---|
| 164 | return null; |
---|
| 165 | } |
---|
[569] | 166 | |
---|
[2] | 167 | return str_data; |
---|
| 168 | } |
---|
| 169 | |
---|
[1444] | 170 | return f(data); |
---|
[2] | 171 | } |
---|
[1444] | 172 | |
---|
[7971] | 173 | cConnector.prototype.unserializeArchiver = function(str) |
---|
| 174 | { |
---|
| 175 | _thisObject = this; |
---|
| 176 | var matchB = function (str, iniPos) |
---|
| 177 | { |
---|
| 178 | var nOpen, nClose = iniPos; |
---|
| 179 | do |
---|
| 180 | { |
---|
| 181 | nOpen = str.substr(nClose+1).search(/[0-9]\:\{/ ); |
---|
| 182 | |
---|
| 183 | if (nOpen > 0) |
---|
| 184 | nOpen = nOpen + nClose+3; |
---|
| 185 | |
---|
| 186 | nClose = str.indexOf('}', nClose+1); |
---|
| 187 | |
---|
| 188 | if (nOpen < 0) |
---|
| 189 | { |
---|
| 190 | return nClose; |
---|
| 191 | } |
---|
| 192 | if (nOpen < nClose ) |
---|
| 193 | { |
---|
| 194 | nClose = matchB(str, nOpen); |
---|
| 195 | } |
---|
| 196 | } while (nOpen < nClose); |
---|
| 197 | |
---|
| 198 | return nClose; |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | var f = function (str) |
---|
| 202 | { |
---|
| 203 | switch (str.charAt(0)) |
---|
| 204 | { |
---|
| 205 | case 'a': |
---|
| 206 | |
---|
| 207 | var data = new Array(); |
---|
| 208 | var n = parseInt( str.substring( str.indexOf(':')+1, str.indexOf(':',2) ) ); |
---|
| 209 | var arrayContent = str.substring(str.indexOf('{')+1, str.lastIndexOf('}')); |
---|
| 210 | |
---|
| 211 | for (var i = 0; i < n; i++) |
---|
| 212 | { |
---|
| 213 | var pos = 0; |
---|
| 214 | |
---|
| 215 | /* Process Index */ |
---|
| 216 | var indexStr = arrayContent.substr(pos, arrayContent.indexOf(';')+1); |
---|
| 217 | var index = f(indexStr); |
---|
| 218 | pos = arrayContent.indexOf(';', pos)+1; |
---|
| 219 | |
---|
| 220 | /* Process Content */ |
---|
| 221 | var part = null; |
---|
| 222 | switch (arrayContent.charAt(pos)) |
---|
| 223 | { |
---|
| 224 | case 'a': |
---|
| 225 | var pos_ = matchB(arrayContent, arrayContent.indexOf('{', pos))+1; |
---|
| 226 | part = arrayContent.substring(pos, pos_); |
---|
| 227 | pos = pos_; |
---|
| 228 | data[index] = f(part); |
---|
| 229 | break; |
---|
| 230 | |
---|
| 231 | case 's': |
---|
| 232 | var pval = arrayContent.indexOf(':', pos+2); |
---|
| 233 | var val = parseInt(arrayContent.substring(pos+2, pval)); |
---|
| 234 | pos = pval + val + 4; |
---|
| 235 | data[index] = arrayContent.substr(pval+2, val); |
---|
| 236 | break; |
---|
| 237 | |
---|
| 238 | default: |
---|
| 239 | part = arrayContent.substring(pos, arrayContent.indexOf(';', pos)+1); |
---|
| 240 | pos = arrayContent.indexOf(';', pos)+1; |
---|
| 241 | data[index] = f(part); |
---|
| 242 | break; |
---|
| 243 | } |
---|
| 244 | arrayContent = arrayContent.substr(pos); |
---|
| 245 | } |
---|
| 246 | break; |
---|
| 247 | |
---|
| 248 | case 's': |
---|
| 249 | var pos = str.indexOf(':', 2); |
---|
| 250 | var val = parseInt(str.substring(2,pos)); |
---|
| 251 | var data = str.substr(pos+2, val); |
---|
| 252 | str = str.substr(pos + 4 + val); |
---|
| 253 | break; |
---|
| 254 | |
---|
| 255 | case 'i': |
---|
| 256 | case 'd': |
---|
| 257 | var pos = str.indexOf(';'); |
---|
| 258 | var data = parseInt(str.substring(2,pos)); |
---|
| 259 | str = str.substr(pos + 1); |
---|
| 260 | break; |
---|
| 261 | |
---|
| 262 | case 'N': |
---|
| 263 | var data = null; |
---|
| 264 | str = str.substr(str.indexOf(';') + 1); |
---|
| 265 | break; |
---|
| 266 | |
---|
| 267 | case 'b': |
---|
| 268 | var data = str.charAt(2) == '1' ? true : false; |
---|
| 269 | break; |
---|
| 270 | } |
---|
| 271 | return data; |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | return f(str); |
---|
| 275 | } |
---|
| 276 | |
---|
[1444] | 277 | //Unserialize Data Method |
---|
| 278 | cConnector.prototype.unserialize = function(str) |
---|
[2] | 279 | { |
---|
| 280 | _thisObject = this; |
---|
[1444] | 281 | var matchB = function (str, iniPos) |
---|
[2] | 282 | { |
---|
| 283 | var nOpen, nClose = iniPos; |
---|
[1444] | 284 | do |
---|
[2] | 285 | { |
---|
[7748] | 286 | nOpen = str.substr(nClose+1).search(/[0-9]\:\{/ ); |
---|
[2] | 287 | |
---|
[7748] | 288 | if (nOpen > 0) |
---|
| 289 | nOpen = nOpen + nClose+3; |
---|
| 290 | |
---|
| 291 | nClose = (str.substr(nClose+1) == '}' || str.substr(nClose+1,1) == '}') ? nClose +1 : str.substr(nClose+1).search(/[0-9\"]\;\}/ ) + nClose + 3; |
---|
[7971] | 292 | |
---|
[7748] | 293 | if (nOpen < 0) |
---|
| 294 | { |
---|
| 295 | return nClose; |
---|
| 296 | } |
---|
| 297 | if (nOpen < nClose ) |
---|
| 298 | { |
---|
| 299 | nClose = matchB(str, nOpen); |
---|
| 300 | } |
---|
[2] | 301 | } while (nOpen < nClose); |
---|
| 302 | |
---|
| 303 | return nClose; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | var f = function (str) |
---|
| 307 | { |
---|
| 308 | switch (str.charAt(0)) |
---|
| 309 | { |
---|
| 310 | case 'a': |
---|
| 311 | |
---|
| 312 | var data = new Array(); |
---|
| 313 | var n = parseInt( str.substring( str.indexOf(':')+1, str.indexOf(':',2) ) ); |
---|
| 314 | var arrayContent = str.substring(str.indexOf('{')+1, str.lastIndexOf('}')); |
---|
| 315 | |
---|
| 316 | for (var i = 0; i < n; i++) |
---|
| 317 | { |
---|
| 318 | var pos = 0; |
---|
| 319 | |
---|
| 320 | /* Process Index */ |
---|
| 321 | var indexStr = arrayContent.substr(pos, arrayContent.indexOf(';')+1); |
---|
[1444] | 322 | var index = f(indexStr); |
---|
[2] | 323 | pos = arrayContent.indexOf(';', pos)+1; |
---|
| 324 | |
---|
| 325 | /* Process Content */ |
---|
| 326 | var part = null; |
---|
| 327 | switch (arrayContent.charAt(pos)) |
---|
| 328 | { |
---|
| 329 | case 'a': |
---|
[1444] | 330 | var pos_ = matchB(arrayContent, arrayContent.indexOf('{', pos))+1; |
---|
[2] | 331 | part = arrayContent.substring(pos, pos_); |
---|
| 332 | pos = pos_; |
---|
[1444] | 333 | data[index] = f(part); |
---|
[2] | 334 | break; |
---|
| 335 | |
---|
| 336 | case 's': |
---|
| 337 | var pval = arrayContent.indexOf(':', pos+2); |
---|
| 338 | var val = parseInt(arrayContent.substring(pos+2, pval)); |
---|
| 339 | pos = pval + val + 4; |
---|
| 340 | data[index] = arrayContent.substr(pval+2, val); |
---|
| 341 | break; |
---|
| 342 | |
---|
| 343 | default: |
---|
| 344 | part = arrayContent.substring(pos, arrayContent.indexOf(';', pos)+1); |
---|
| 345 | pos = arrayContent.indexOf(';', pos)+1; |
---|
[1444] | 346 | data[index] = f(part); |
---|
[2] | 347 | break; |
---|
| 348 | } |
---|
| 349 | arrayContent = arrayContent.substr(pos); |
---|
| 350 | } |
---|
| 351 | break; |
---|
| 352 | |
---|
| 353 | case 's': |
---|
| 354 | var pos = str.indexOf(':', 2); |
---|
| 355 | var val = parseInt(str.substring(2,pos)); |
---|
| 356 | var data = str.substr(pos+2, val); |
---|
| 357 | str = str.substr(pos + 4 + val); |
---|
| 358 | break; |
---|
| 359 | |
---|
| 360 | case 'i': |
---|
| 361 | case 'd': |
---|
| 362 | var pos = str.indexOf(';'); |
---|
| 363 | var data = parseInt(str.substring(2,pos)); |
---|
| 364 | str = str.substr(pos + 1); |
---|
| 365 | break; |
---|
| 366 | |
---|
| 367 | case 'N': |
---|
| 368 | var data = null; |
---|
| 369 | str = str.substr(str.indexOf(';') + 1); |
---|
| 370 | break; |
---|
| 371 | |
---|
| 372 | case 'b': |
---|
| 373 | var data = str.charAt(2) == '1' ? true : false; |
---|
| 374 | break; |
---|
| 375 | } |
---|
| 376 | return data; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | return f(str); |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | //Create XMLHTTP object Method |
---|
| 383 | cConnector.prototype.createXMLHTTP = function () |
---|
| 384 | { |
---|
| 385 | try |
---|
[4760] | 386 | { |
---|
[2] | 387 | this.oxmlhttp = new XMLHttpRequest(); |
---|
| 388 | this.oxmlhttp.overrideMimeType('text/xml'); |
---|
| 389 | } |
---|
| 390 | catch (e) |
---|
[4760] | 391 | { |
---|
[2] | 392 | try |
---|
| 393 | { |
---|
| 394 | this.oxmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); |
---|
| 395 | } |
---|
| 396 | catch (e1) |
---|
[4760] | 397 | { |
---|
[2] | 398 | try |
---|
| 399 | { |
---|
| 400 | this.oxmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); |
---|
| 401 | } |
---|
| 402 | catch (e2) |
---|
| 403 | { |
---|
| 404 | this.oxmlhttp = null; |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | // Request Constructor Connector |
---|
| 412 | cConnector.prototype.newRequest = function (id, target, method, handler, data) |
---|
[802] | 413 | { |
---|
[1857] | 414 | |
---|
[802] | 415 | var params = data; |
---|
[2] | 416 | this.tid = id; |
---|
[1857] | 417 | |
---|
[2] | 418 | if (this.requests[id]) { |
---|
| 419 | return false; |
---|
| 420 | } |
---|
[1857] | 421 | |
---|
[2] | 422 | this.createXMLHTTP(); |
---|
| 423 | var oxmlhttp = this.oxmlhttp; |
---|
| 424 | var _thisObject = this; |
---|
[1857] | 425 | |
---|
[2] | 426 | if (! oxmlhttp) |
---|
| 427 | return false; |
---|
| 428 | |
---|
| 429 | this.requests[id] = oxmlhttp; |
---|
| 430 | this.buildBar(); |
---|
| 431 | this.showProgressBar(); |
---|
[1857] | 432 | |
---|
[2] | 433 | var sub_handler = function () |
---|
| 434 | { |
---|
| 435 | var progressBar = _thisObject.progressBar; |
---|
| 436 | |
---|
| 437 | try |
---|
| 438 | { |
---|
| 439 | if (oxmlhttp.readyState == 4 ) |
---|
| 440 | { |
---|
| 441 | switch (oxmlhttp.status) |
---|
| 442 | { |
---|
[1857] | 443 | |
---|
[2] | 444 | case 200: |
---|
| 445 | if (typeof(handler) == 'function') |
---|
[7748] | 446 | { |
---|
| 447 | _thisObject.hideProgressBar(); |
---|
[2] | 448 | var data = _thisObject.unserialize(oxmlhttp.responseText); |
---|
[446] | 449 | if ( typeof data == 'undefined' ) |
---|
| 450 | data = oxmlhttp.responseText; |
---|
[7748] | 451 | // Verify user session |
---|
| 452 | if(data && data.nosession){ |
---|
| 453 | // If hold session is setted, dont reload the page ... |
---|
| 454 | if(hold_session) { |
---|
| 455 | if(typeof(write_msg) == "function" && typeof(get_lang) == "function") |
---|
| 456 | write_msg(get_lang("your session could not be verified.")); |
---|
| 457 | else |
---|
| 458 | alert("your session could not be verified."); |
---|
| 459 | } |
---|
| 460 | else |
---|
| 461 | window.location.reload(); |
---|
[3018] | 462 | |
---|
[7748] | 463 | delete _thisObject.requests[id]; |
---|
| 464 | _thisObject.requests[id] = null; |
---|
| 465 | return false; |
---|
| 466 | } |
---|
[2] | 467 | if(debug_controller) { |
---|
| 468 | document.getElementById("debug_controller").innerHTML += oxmlhttp.responseText; |
---|
| 469 | document.getElementById("debug_controller").innerHTML += "<br>-------------------------------------------------------------------------------------<br>"; |
---|
[569] | 470 | } |
---|
[1857] | 471 | |
---|
[1443] | 472 | _thisObject.addToCache(params?id+"&"+params:id,data); |
---|
[7748] | 473 | delete _thisObject.requests[id]; |
---|
[2] | 474 | _thisObject.requests[id] = null; |
---|
[1857] | 475 | handler(data); |
---|
[2] | 476 | } |
---|
| 477 | |
---|
| 478 | break; |
---|
| 479 | |
---|
| 480 | case 404: |
---|
[7748] | 481 | |
---|
[197] | 482 | alert(get_lang('Page Not Found!')); |
---|
[2] | 483 | break; |
---|
| 484 | |
---|
[7748] | 485 | default: |
---|
[2] | 486 | } |
---|
| 487 | } |
---|
| 488 | } |
---|
| 489 | catch (e) |
---|
[7748] | 490 | { |
---|
[2] | 491 | _thisObject.hideProgressBar(); |
---|
| 492 | if(debug_controller) |
---|
| 493 | alert(e+"\n"+oxmlhttp.responseText); |
---|
| 494 | // View Exception in Javascript Console |
---|
| 495 | throw(e); |
---|
| 496 | } |
---|
[7748] | 497 | |
---|
[2] | 498 | } |
---|
| 499 | |
---|
| 500 | try |
---|
[7748] | 501 | { |
---|
[2] | 502 | if (method == '' || method == 'GET') |
---|
| 503 | { |
---|
| 504 | oxmlhttp.open("GET",target,true); |
---|
| 505 | if (typeof(handler) == 'function') |
---|
| 506 | { |
---|
| 507 | oxmlhttp.onreadystatechange = sub_handler; |
---|
| 508 | oxmlhttp.send(null); |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | } |
---|
| 512 | else if (method == 'POST') |
---|
| 513 | { |
---|
| 514 | oxmlhttp.open("POST",target, true); |
---|
| 515 | oxmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); |
---|
| 516 | if (typeof(handler) == 'function') |
---|
| 517 | { |
---|
| 518 | oxmlhttp.onreadystatechange = sub_handler; |
---|
| 519 | oxmlhttp.send(data); |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | } |
---|
| 523 | } |
---|
| 524 | catch(e) |
---|
[7748] | 525 | { |
---|
[2] | 526 | _thisObject.hideProgressBar(); |
---|
| 527 | if(debug_controller) |
---|
| 528 | alert(e); |
---|
[7748] | 529 | // View Exception in Javascript Console |
---|
[2] | 530 | throw(e); |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | return true; |
---|
| 534 | } |
---|
| 535 | // Cancel Request Connector |
---|
[5134] | 536 | cConnector.prototype.cancelRequest = function (id){ |
---|
[4760] | 537 | |
---|
[5134] | 538 | id = id || this.tid; |
---|
| 539 | |
---|
| 540 | if (!this.requests[id]){ |
---|
[2] | 541 | return false; |
---|
| 542 | } |
---|
[4760] | 543 | //this.oxmlhttp.onreadystatechange = null; |
---|
[5134] | 544 | this.requests[id].abort(); |
---|
| 545 | delete this.requests[id]; |
---|
| 546 | this.requests[id] = null; |
---|
[4760] | 547 | |
---|
[2] | 548 | this.hideProgressBar(); |
---|
| 549 | } |
---|
| 550 | //------------------------------------ END: Functions for Connector HTTPRequest -------------------------------------------------// |
---|
| 551 | |
---|
| 552 | // ----------------------------------- BEGIN: Functions for build Bar Progress ---------------------------------------------------------// |
---|
| 553 | cConnector.prototype.hideProgressBar = function () |
---|
| 554 | { |
---|
| 555 | var div = document.getElementById('divProgressBar'); |
---|
[7915] | 556 | |
---|
| 557 | if(div) |
---|
| 558 | { |
---|
| 559 | div.style.visibility = 'hidden'; |
---|
| 560 | this.isVisibleBar = false; |
---|
| 561 | } |
---|
[2] | 562 | } |
---|
| 563 | |
---|
| 564 | cConnector.prototype.showProgressBar = function(){ |
---|
[7915] | 565 | |
---|
[2] | 566 | var div = document.getElementById('divProgressBar'); |
---|
[7915] | 567 | if(div) |
---|
| 568 | { |
---|
| 569 | div.style.visibility = 'visible'; |
---|
| 570 | this.isVisibleBar = true; |
---|
| 571 | } |
---|
[2] | 572 | } |
---|
| 573 | |
---|
| 574 | cConnector.prototype.loadAllScripts = function(scripts) { |
---|
[3068] | 575 | for(var i = 0; i < scripts.length; i++){ |
---|
| 576 | this.loadScript(scripts[i]); |
---|
[2] | 577 | } |
---|
| 578 | } |
---|
| 579 | |
---|
[4476] | 580 | cConnector.prototype.loadScript = function(scriptPath, basePath) |
---|
| 581 | { |
---|
| 582 | if (document.getElementById('uploadscript_'+scriptPath)) { |
---|
| 583 | return; |
---|
| 584 | } |
---|
[2] | 585 | |
---|
[4476] | 586 | if( basePath == null ) |
---|
| 587 | basePath = "js/"; |
---|
| 588 | |
---|
| 589 | var path = basePath+scriptPath+".js?"+this.updateVersion; |
---|
| 590 | |
---|
| 591 | var head = document.getElementsByTagName("head")[0]; |
---|
| 592 | var script = document.createElement("SCRIPT"); |
---|
| 593 | script.id = 'uploadscript_'+scriptPath; |
---|
| 594 | script.type = 'text/javascript'; |
---|
| 595 | if(is_ie) { |
---|
| 596 | this.oxmlhttp.open("GET", path, false); |
---|
| 597 | this.oxmlhttp.setRequestHeader('Content-Type','text/plain'); |
---|
| 598 | this.oxmlhttp.send(null); |
---|
| 599 | if(this.oxmlhttp.status != 0 && this.oxmlhttp.status != 200 || this.oxmlhttp.status == 0 && this.oxmlhttp.responseText.length == 0) |
---|
| 600 | throw new Error("Error " + this.oxmlhttp.status + "("+this.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'"); |
---|
| 601 | script.text = this.oxmlhttp.responseText; |
---|
| 602 | } |
---|
| 603 | else { |
---|
| 604 | script.src = path; |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | head.appendChild(script); |
---|
| 608 | return; |
---|
[2] | 609 | } |
---|
| 610 | //------------------------------------ END: Functions for Progress Bar -------------------------------------------------// |
---|
| 611 | // Default Controller File |
---|
| 612 | var DEFAULT_URL = 'controller.php?action='; |
---|
| 613 | // connector object |
---|
| 614 | var connector = new cConnector(); |
---|
| 615 | var _onmouseup = document.onmouseup; |
---|
| 616 | var isExecuteForm = false; |
---|
| 617 | var id = null; |
---|
| 618 | |
---|
[1443] | 619 | cConnector.prototype.queryConnectorCache = function(url,handler){ |
---|
| 620 | if (this.connectorCache.valid[url]) |
---|
[569] | 621 | { |
---|
[1443] | 622 | handler(this.connectorCache.result[url]); |
---|
[569] | 623 | return true; |
---|
| 624 | } |
---|
| 625 | else |
---|
| 626 | return false; |
---|
| 627 | } |
---|
[1443] | 628 | cConnector.prototype.purgeCache= function(){ |
---|
[802] | 629 | if (typeof(preferences) == "undefined" || preferences.use_cache != 'True') |
---|
| 630 | return false; |
---|
[569] | 631 | var i; |
---|
[1443] | 632 | for (i=0; i<= this.expurgatedCache.length; i++) |
---|
[569] | 633 | { |
---|
[1443] | 634 | this.connectorCache.valid[this.expurgatedCache[i]] = false; |
---|
[802] | 635 | try { |
---|
[1443] | 636 | delete this.connectorCache.result[this.expurgatedCache[i]]; |
---|
[802] | 637 | } |
---|
| 638 | catch (e) { }; |
---|
[569] | 639 | } |
---|
| 640 | } |
---|
[1443] | 641 | cConnector.prototype.addToCache = function(id,data){ |
---|
[605] | 642 | if (typeof(preferences) == "undefined" || preferences.use_cache != 'True') |
---|
[569] | 643 | return false; |
---|
| 644 | var func = id.substr(id.lastIndexOf('.')+1); |
---|
| 645 | if (func.indexOf('&') > 0) |
---|
| 646 | func = func.substr(0,func.indexOf('&')); |
---|
| 647 | switch (func){ |
---|
| 648 | // functions that enters in cache |
---|
[605] | 649 | case 'get_info_msg': |
---|
| 650 | data.cacheHit = true; |
---|
[569] | 651 | case 'get_preferences': |
---|
| 652 | case 'getSharedUsersFrom': |
---|
| 653 | case 'get_organizations': |
---|
| 654 | case 'get_catalogs': |
---|
| 655 | case 'get_dropdown_contacts': |
---|
| 656 | case 'get_cc_contacts': |
---|
| 657 | case 'get_cc_groups': |
---|
| 658 | case 'getUsersByEmail': |
---|
[1443] | 659 | this.connectorCache.valid[id] = true; |
---|
| 660 | this.connectorCache.result[id] = data; |
---|
[569] | 661 | break; |
---|
| 662 | // function that needs expire |
---|
| 663 | case 'get_range_msgs2': |
---|
[630] | 664 | case 'quicksearch': |
---|
[569] | 665 | case 'get_folders_list': |
---|
[802] | 666 | case 'search_msg': |
---|
| 667 | case 'search_for': |
---|
[1443] | 668 | this.connectorCache.valid[id] = true; |
---|
| 669 | this.connectorCache.result[id] = data; |
---|
| 670 | var i = this.expurgatedCache.length; |
---|
| 671 | this.expurgatedCache[i+1] = id; |
---|
[569] | 672 | break; |
---|
| 673 | //functions that expires the cache |
---|
| 674 | case 'move_messages': |
---|
[605] | 675 | case 'delete_msgs': |
---|
[569] | 676 | case 'getReturnExecuteForm': |
---|
| 677 | case 'set_messages_flag': |
---|
[1965] | 678 | case 'empty_folder': |
---|
[1443] | 679 | this.purgeCache(); |
---|
[569] | 680 | default: // no cache |
---|
| 681 | break; |
---|
| 682 | } |
---|
| 683 | } |
---|
| 684 | |
---|
[2] | 685 | // Function executes AJAX |
---|
| 686 | // cExecute (url, handler, params) |
---|
| 687 | // url: 'module.class.method' |
---|
| 688 | // handle: function handle() receive response. |
---|
| 689 | // params: parameters for POST method |
---|
| 690 | // form: form element (for upload files) |
---|
| 691 | function cExecute(url, handler, params, form) { |
---|
| 692 | if(isExecuteForm){ |
---|
| 693 | isExecuteForm = false; |
---|
| 694 | document.onmouseup = _onmouseup; |
---|
| 695 | } |
---|
| 696 | if(form) { |
---|
| 697 | cExecuteForm(url, form); |
---|
| 698 | return; |
---|
| 699 | } |
---|
[569] | 700 | |
---|
[2] | 701 | url = DEFAULT_URL + url; |
---|
[569] | 702 | |
---|
[1443] | 703 | if (connector.queryConnectorCache(params?url+"&"+params:url,handler)) |
---|
[569] | 704 | return; |
---|
| 705 | |
---|
| 706 | if(params) |
---|
[2] | 707 | method = "POST"; |
---|
[569] | 708 | else |
---|
[2] | 709 | method = "GET"; |
---|
[569] | 710 | |
---|
| 711 | id = url; |
---|
[2] | 712 | connector.newRequest(id, url, method, handler, params); |
---|
| 713 | } |
---|
[569] | 714 | |
---|
| 715 | // This function executes submit values to Controller (POST) |
---|
[2] | 716 | // The return is void. |
---|
| 717 | // cExecuteForm (url, form) |
---|
| 718 | // url: 'module.class.method' |
---|
| 719 | // form: form element (for upload files) |
---|
[271] | 720 | function cExecuteForm(url, form, handler,id){ |
---|
[2] | 721 | connector.buildBar(); |
---|
[1369] | 722 | isExecuteForm = true; |
---|
| 723 | |
---|
[2] | 724 | document.onmouseup = alertBut; |
---|
[1369] | 725 | |
---|
[2] | 726 | connector.showProgressBar(); |
---|
| 727 | if(! (divUpload = document.getElementById('divUpload'))) { |
---|
| 728 | divUpload = document.createElement('DIV'); |
---|
| 729 | divUpload.id = 'divUpload'; |
---|
| 730 | document.body.appendChild(divUpload); |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | if(! (el = document.getElementById('_action'))) { |
---|
| 734 | el = document.createElement('input'); |
---|
| 735 | el.type = 'hidden'; |
---|
| 736 | el.id = '_action'; |
---|
| 737 | el.name = '_action'; |
---|
| 738 | form.appendChild(el); |
---|
| 739 | } |
---|
| 740 | |
---|
[271] | 741 | var divFiles = Element("divFiles_"+id); |
---|
[660] | 742 | if (divFiles && divFiles.firstChild) { |
---|
[2] | 743 | el = document.createElement('input'); |
---|
| 744 | el.type = 'hidden'; |
---|
| 745 | el.name = 'countFiles'; |
---|
[271] | 746 | var countDivFiles = 0; |
---|
| 747 | try{ |
---|
| 748 | countDivFiles = parseInt(divFiles.lastChild.firstChild.id.split('_')[2]) + 1; // The id of last file |
---|
| 749 | } |
---|
| 750 | catch (e) { var countDivFiles = 0; }; |
---|
| 751 | el.value = countDivFiles ; |
---|
[2] | 752 | form.appendChild(el); |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | form._action.value = url; |
---|
[1369] | 756 | // Connector Bug fixing: Encapsulating returned handler function |
---|
| 757 | handlerExecuteForm = handler; |
---|
| 758 | var form_handler = function (data){ |
---|
| 759 | handlerExecuteForm(data); |
---|
[3792] | 760 | document.getElementById('uploadFile').parentNode.removeChild(document.getElementById('uploadFile')); |
---|
[1369] | 761 | handlerExecuteForm = null; |
---|
| 762 | } |
---|
[1926] | 763 | if (is_ie) |
---|
| 764 | divUpload.innerHTML= "<iframe onload=\"cExecute('$this.functions.getReturnExecuteForm',"+form_handler+");\" style='display:"+(debug_controller ? "" : "none")+";width:"+(debug_controller ? 400 : 0)+";height:"+(debug_controller ? 400 : 0)+";' name='uploadFile'></iframe>"; |
---|
| 765 | else{ |
---|
| 766 | var iframe = document.createElement('iframe'); |
---|
| 767 | iframe.name="uploadFile"; |
---|
[3746] | 768 | iframe.id="uploadFile"; |
---|
[5210] | 769 | divUpload.appendChild(iframe); |
---|
[1926] | 770 | iframe.onload = function(){cExecute('$this.functions.getReturnExecuteForm', form_handler);} |
---|
| 771 | iframe.style.display = (debug_controller ? "" : "none"); |
---|
| 772 | iframe.style.width = (debug_controller ? 400 : 0) + "px"; |
---|
| 773 | iframe.style.height = (debug_controller ? 400 : 0) + "px"; |
---|
[5210] | 774 | |
---|
[1926] | 775 | } |
---|
| 776 | |
---|
[2] | 777 | form.action ="controller.php"; |
---|
[1247] | 778 | form.target ="uploadFile"; |
---|
[2] | 779 | form.submit(); |
---|
[1364] | 780 | // Connector Bug fixing: Exclude '_action' element after cExecuteForm execution |
---|
| 781 | if(el && el.id == '_action'){ |
---|
| 782 | el.parentNode.removeChild(el); |
---|
| 783 | } |
---|
[2] | 784 | } |
---|
| 785 | |
---|
| 786 | |
---|
| 787 | function alertBut(e) { |
---|
| 788 | if(!e) |
---|
| 789 | e = window.event; |
---|
| 790 | |
---|
| 791 | if(_onmouseup) |
---|
| 792 | _onmouseup(e); |
---|
| 793 | |
---|
| 794 | if(isExecuteForm) { |
---|
| 795 | if(confirm(get_lang("There's an action processing. Do you want abort it?"))) { |
---|
| 796 | connector.hideProgressBar(); |
---|
| 797 | isExecuteForm = false; |
---|
| 798 | delete connector.requests[id]; |
---|
| 799 | connector.requests[id] = null; |
---|
| 800 | stop(); |
---|
| 801 | return; |
---|
| 802 | } |
---|
| 803 | else |
---|
| 804 | return false; |
---|
| 805 | } |
---|
[446] | 806 | } |
---|