[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 | |
---|
| 173 | //Unserialize Data Method |
---|
| 174 | cConnector.prototype.unserialize = function(str) |
---|
[2] | 175 | { |
---|
[1444] | 176 | |
---|
[2] | 177 | _thisObject = this; |
---|
[1444] | 178 | var matchB = function (str, iniPos) |
---|
[2] | 179 | { |
---|
| 180 | var nOpen, nClose = iniPos; |
---|
[1444] | 181 | do |
---|
[2] | 182 | { |
---|
[7748] | 183 | nOpen = str.substr(nClose+1).search(/[0-9]\:\{/ ); |
---|
[2] | 184 | |
---|
[7748] | 185 | if (nOpen > 0) |
---|
| 186 | nOpen = nOpen + nClose+3; |
---|
| 187 | |
---|
| 188 | nClose = (str.substr(nClose+1) == '}' || str.substr(nClose+1,1) == '}') ? nClose +1 : str.substr(nClose+1).search(/[0-9\"]\;\}/ ) + nClose + 3; |
---|
| 189 | |
---|
| 190 | if (nOpen < 0) |
---|
| 191 | { |
---|
| 192 | return nClose; |
---|
| 193 | } |
---|
| 194 | if (nOpen < nClose ) |
---|
| 195 | { |
---|
| 196 | nClose = matchB(str, nOpen); |
---|
| 197 | } |
---|
[2] | 198 | } while (nOpen < nClose); |
---|
| 199 | |
---|
| 200 | return nClose; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | var f = function (str) |
---|
| 204 | { |
---|
| 205 | switch (str.charAt(0)) |
---|
| 206 | { |
---|
| 207 | case 'a': |
---|
| 208 | |
---|
| 209 | var data = new Array(); |
---|
| 210 | var n = parseInt( str.substring( str.indexOf(':')+1, str.indexOf(':',2) ) ); |
---|
| 211 | var arrayContent = str.substring(str.indexOf('{')+1, str.lastIndexOf('}')); |
---|
| 212 | |
---|
| 213 | for (var i = 0; i < n; i++) |
---|
| 214 | { |
---|
| 215 | var pos = 0; |
---|
| 216 | |
---|
| 217 | /* Process Index */ |
---|
| 218 | var indexStr = arrayContent.substr(pos, arrayContent.indexOf(';')+1); |
---|
[1444] | 219 | var index = f(indexStr); |
---|
[2] | 220 | pos = arrayContent.indexOf(';', pos)+1; |
---|
| 221 | |
---|
| 222 | /* Process Content */ |
---|
| 223 | var part = null; |
---|
| 224 | switch (arrayContent.charAt(pos)) |
---|
| 225 | { |
---|
| 226 | case 'a': |
---|
[1444] | 227 | var pos_ = matchB(arrayContent, arrayContent.indexOf('{', pos))+1; |
---|
[2] | 228 | part = arrayContent.substring(pos, pos_); |
---|
| 229 | pos = pos_; |
---|
[1444] | 230 | data[index] = f(part); |
---|
[2] | 231 | break; |
---|
| 232 | |
---|
| 233 | case 's': |
---|
| 234 | var pval = arrayContent.indexOf(':', pos+2); |
---|
| 235 | var val = parseInt(arrayContent.substring(pos+2, pval)); |
---|
| 236 | pos = pval + val + 4; |
---|
| 237 | data[index] = arrayContent.substr(pval+2, val); |
---|
| 238 | break; |
---|
| 239 | |
---|
| 240 | default: |
---|
| 241 | part = arrayContent.substring(pos, arrayContent.indexOf(';', pos)+1); |
---|
| 242 | pos = arrayContent.indexOf(';', pos)+1; |
---|
[1444] | 243 | data[index] = f(part); |
---|
[2] | 244 | break; |
---|
| 245 | } |
---|
| 246 | arrayContent = arrayContent.substr(pos); |
---|
| 247 | } |
---|
| 248 | break; |
---|
| 249 | |
---|
| 250 | case 's': |
---|
| 251 | var pos = str.indexOf(':', 2); |
---|
| 252 | var val = parseInt(str.substring(2,pos)); |
---|
| 253 | var data = str.substr(pos+2, val); |
---|
| 254 | str = str.substr(pos + 4 + val); |
---|
| 255 | break; |
---|
| 256 | |
---|
| 257 | case 'i': |
---|
| 258 | case 'd': |
---|
| 259 | var pos = str.indexOf(';'); |
---|
| 260 | var data = parseInt(str.substring(2,pos)); |
---|
| 261 | str = str.substr(pos + 1); |
---|
| 262 | break; |
---|
| 263 | |
---|
| 264 | case 'N': |
---|
| 265 | var data = null; |
---|
| 266 | str = str.substr(str.indexOf(';') + 1); |
---|
| 267 | break; |
---|
| 268 | |
---|
| 269 | case 'b': |
---|
| 270 | var data = str.charAt(2) == '1' ? true : false; |
---|
| 271 | break; |
---|
| 272 | } |
---|
| 273 | return data; |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | return f(str); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | //Create XMLHTTP object Method |
---|
| 280 | cConnector.prototype.createXMLHTTP = function () |
---|
| 281 | { |
---|
| 282 | try |
---|
[4760] | 283 | { |
---|
[2] | 284 | this.oxmlhttp = new XMLHttpRequest(); |
---|
| 285 | this.oxmlhttp.overrideMimeType('text/xml'); |
---|
| 286 | } |
---|
| 287 | catch (e) |
---|
[4760] | 288 | { |
---|
[2] | 289 | try |
---|
| 290 | { |
---|
| 291 | this.oxmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); |
---|
| 292 | } |
---|
| 293 | catch (e1) |
---|
[4760] | 294 | { |
---|
[2] | 295 | try |
---|
| 296 | { |
---|
| 297 | this.oxmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); |
---|
| 298 | } |
---|
| 299 | catch (e2) |
---|
| 300 | { |
---|
| 301 | this.oxmlhttp = null; |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | // Request Constructor Connector |
---|
| 309 | cConnector.prototype.newRequest = function (id, target, method, handler, data) |
---|
[802] | 310 | { |
---|
[1857] | 311 | |
---|
[802] | 312 | var params = data; |
---|
[2] | 313 | this.tid = id; |
---|
[1857] | 314 | |
---|
[2] | 315 | if (this.requests[id]) { |
---|
| 316 | return false; |
---|
| 317 | } |
---|
[1857] | 318 | |
---|
[2] | 319 | this.createXMLHTTP(); |
---|
| 320 | var oxmlhttp = this.oxmlhttp; |
---|
| 321 | var _thisObject = this; |
---|
[1857] | 322 | |
---|
[2] | 323 | if (! oxmlhttp) |
---|
| 324 | return false; |
---|
| 325 | |
---|
| 326 | this.requests[id] = oxmlhttp; |
---|
| 327 | this.buildBar(); |
---|
| 328 | this.showProgressBar(); |
---|
[1857] | 329 | |
---|
[2] | 330 | var sub_handler = function () |
---|
| 331 | { |
---|
| 332 | var progressBar = _thisObject.progressBar; |
---|
| 333 | |
---|
| 334 | try |
---|
| 335 | { |
---|
| 336 | if (oxmlhttp.readyState == 4 ) |
---|
| 337 | { |
---|
| 338 | switch (oxmlhttp.status) |
---|
| 339 | { |
---|
[1857] | 340 | |
---|
[2] | 341 | case 200: |
---|
| 342 | if (typeof(handler) == 'function') |
---|
[7748] | 343 | { |
---|
| 344 | _thisObject.hideProgressBar(); |
---|
[2] | 345 | var data = _thisObject.unserialize(oxmlhttp.responseText); |
---|
[446] | 346 | if ( typeof data == 'undefined' ) |
---|
| 347 | data = oxmlhttp.responseText; |
---|
[7748] | 348 | // Verify user session |
---|
| 349 | if(data && data.nosession){ |
---|
| 350 | // If hold session is setted, dont reload the page ... |
---|
| 351 | if(hold_session) { |
---|
| 352 | if(typeof(write_msg) == "function" && typeof(get_lang) == "function") |
---|
| 353 | write_msg(get_lang("your session could not be verified.")); |
---|
| 354 | else |
---|
| 355 | alert("your session could not be verified."); |
---|
| 356 | } |
---|
| 357 | else |
---|
| 358 | window.location.reload(); |
---|
[3018] | 359 | |
---|
[7748] | 360 | delete _thisObject.requests[id]; |
---|
| 361 | _thisObject.requests[id] = null; |
---|
| 362 | return false; |
---|
| 363 | } |
---|
[2] | 364 | if(debug_controller) { |
---|
| 365 | document.getElementById("debug_controller").innerHTML += oxmlhttp.responseText; |
---|
| 366 | document.getElementById("debug_controller").innerHTML += "<br>-------------------------------------------------------------------------------------<br>"; |
---|
[569] | 367 | } |
---|
[1857] | 368 | |
---|
[1443] | 369 | _thisObject.addToCache(params?id+"&"+params:id,data); |
---|
[7748] | 370 | delete _thisObject.requests[id]; |
---|
[2] | 371 | _thisObject.requests[id] = null; |
---|
[1857] | 372 | handler(data); |
---|
[2] | 373 | } |
---|
| 374 | |
---|
| 375 | break; |
---|
| 376 | |
---|
| 377 | case 404: |
---|
[7748] | 378 | |
---|
[197] | 379 | alert(get_lang('Page Not Found!')); |
---|
[2] | 380 | break; |
---|
| 381 | |
---|
[7748] | 382 | default: |
---|
[2] | 383 | } |
---|
| 384 | } |
---|
| 385 | } |
---|
| 386 | catch (e) |
---|
[7748] | 387 | { |
---|
[2] | 388 | _thisObject.hideProgressBar(); |
---|
| 389 | if(debug_controller) |
---|
| 390 | alert(e+"\n"+oxmlhttp.responseText); |
---|
| 391 | // View Exception in Javascript Console |
---|
| 392 | throw(e); |
---|
| 393 | } |
---|
[7748] | 394 | |
---|
[2] | 395 | } |
---|
| 396 | |
---|
| 397 | try |
---|
[7748] | 398 | { |
---|
[2] | 399 | if (method == '' || method == 'GET') |
---|
| 400 | { |
---|
| 401 | oxmlhttp.open("GET",target,true); |
---|
| 402 | if (typeof(handler) == 'function') |
---|
| 403 | { |
---|
| 404 | oxmlhttp.onreadystatechange = sub_handler; |
---|
| 405 | oxmlhttp.send(null); |
---|
| 406 | } |
---|
| 407 | |
---|
| 408 | } |
---|
| 409 | else if (method == 'POST') |
---|
| 410 | { |
---|
| 411 | oxmlhttp.open("POST",target, true); |
---|
| 412 | oxmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); |
---|
| 413 | if (typeof(handler) == 'function') |
---|
| 414 | { |
---|
| 415 | oxmlhttp.onreadystatechange = sub_handler; |
---|
| 416 | oxmlhttp.send(data); |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | } |
---|
| 420 | } |
---|
| 421 | catch(e) |
---|
[7748] | 422 | { |
---|
[2] | 423 | _thisObject.hideProgressBar(); |
---|
| 424 | if(debug_controller) |
---|
| 425 | alert(e); |
---|
[7748] | 426 | // View Exception in Javascript Console |
---|
[2] | 427 | throw(e); |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | return true; |
---|
| 431 | } |
---|
| 432 | // Cancel Request Connector |
---|
[5134] | 433 | cConnector.prototype.cancelRequest = function (id){ |
---|
[4760] | 434 | |
---|
[5134] | 435 | id = id || this.tid; |
---|
| 436 | |
---|
| 437 | if (!this.requests[id]){ |
---|
[2] | 438 | return false; |
---|
| 439 | } |
---|
[4760] | 440 | //this.oxmlhttp.onreadystatechange = null; |
---|
[5134] | 441 | this.requests[id].abort(); |
---|
| 442 | delete this.requests[id]; |
---|
| 443 | this.requests[id] = null; |
---|
[4760] | 444 | |
---|
[2] | 445 | this.hideProgressBar(); |
---|
| 446 | } |
---|
| 447 | //------------------------------------ END: Functions for Connector HTTPRequest -------------------------------------------------// |
---|
| 448 | |
---|
| 449 | // ----------------------------------- BEGIN: Functions for build Bar Progress ---------------------------------------------------------// |
---|
| 450 | cConnector.prototype.hideProgressBar = function () |
---|
| 451 | { |
---|
| 452 | var div = document.getElementById('divProgressBar'); |
---|
| 453 | div.style.visibility = 'hidden'; |
---|
| 454 | this.isVisibleBar = false; |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | cConnector.prototype.showProgressBar = function(){ |
---|
| 458 | var div = document.getElementById('divProgressBar'); |
---|
| 459 | div.style.visibility = 'visible'; |
---|
| 460 | |
---|
| 461 | this.isVisibleBar = true; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | cConnector.prototype.loadAllScripts = function(scripts) { |
---|
[3068] | 465 | for(var i = 0; i < scripts.length; i++){ |
---|
| 466 | this.loadScript(scripts[i]); |
---|
[2] | 467 | } |
---|
| 468 | } |
---|
| 469 | |
---|
[4476] | 470 | cConnector.prototype.loadScript = function(scriptPath, basePath) |
---|
| 471 | { |
---|
| 472 | if (document.getElementById('uploadscript_'+scriptPath)) { |
---|
| 473 | return; |
---|
| 474 | } |
---|
[2] | 475 | |
---|
[4476] | 476 | if( basePath == null ) |
---|
| 477 | basePath = "js/"; |
---|
| 478 | |
---|
| 479 | var path = basePath+scriptPath+".js?"+this.updateVersion; |
---|
| 480 | |
---|
| 481 | var head = document.getElementsByTagName("head")[0]; |
---|
| 482 | var script = document.createElement("SCRIPT"); |
---|
| 483 | script.id = 'uploadscript_'+scriptPath; |
---|
| 484 | script.type = 'text/javascript'; |
---|
| 485 | if(is_ie) { |
---|
| 486 | this.oxmlhttp.open("GET", path, false); |
---|
| 487 | this.oxmlhttp.setRequestHeader('Content-Type','text/plain'); |
---|
| 488 | this.oxmlhttp.send(null); |
---|
| 489 | if(this.oxmlhttp.status != 0 && this.oxmlhttp.status != 200 || this.oxmlhttp.status == 0 && this.oxmlhttp.responseText.length == 0) |
---|
| 490 | throw new Error("Error " + this.oxmlhttp.status + "("+this.oxmlhttp.statusText+") when loading script file '"+scriptPath+"'"); |
---|
| 491 | script.text = this.oxmlhttp.responseText; |
---|
| 492 | } |
---|
| 493 | else { |
---|
| 494 | script.src = path; |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | head.appendChild(script); |
---|
| 498 | return; |
---|
[2] | 499 | } |
---|
| 500 | //------------------------------------ END: Functions for Progress Bar -------------------------------------------------// |
---|
| 501 | // Default Controller File |
---|
| 502 | var DEFAULT_URL = 'controller.php?action='; |
---|
| 503 | // connector object |
---|
| 504 | var connector = new cConnector(); |
---|
| 505 | var _onmouseup = document.onmouseup; |
---|
| 506 | var isExecuteForm = false; |
---|
| 507 | var id = null; |
---|
| 508 | |
---|
[1443] | 509 | cConnector.prototype.queryConnectorCache = function(url,handler){ |
---|
| 510 | if (this.connectorCache.valid[url]) |
---|
[569] | 511 | { |
---|
[1443] | 512 | handler(this.connectorCache.result[url]); |
---|
[569] | 513 | return true; |
---|
| 514 | } |
---|
| 515 | else |
---|
| 516 | return false; |
---|
| 517 | } |
---|
[1443] | 518 | cConnector.prototype.purgeCache= function(){ |
---|
[802] | 519 | if (typeof(preferences) == "undefined" || preferences.use_cache != 'True') |
---|
| 520 | return false; |
---|
[569] | 521 | var i; |
---|
[1443] | 522 | for (i=0; i<= this.expurgatedCache.length; i++) |
---|
[569] | 523 | { |
---|
[1443] | 524 | this.connectorCache.valid[this.expurgatedCache[i]] = false; |
---|
[802] | 525 | try { |
---|
[1443] | 526 | delete this.connectorCache.result[this.expurgatedCache[i]]; |
---|
[802] | 527 | } |
---|
| 528 | catch (e) { }; |
---|
[569] | 529 | } |
---|
| 530 | } |
---|
[1443] | 531 | cConnector.prototype.addToCache = function(id,data){ |
---|
[605] | 532 | if (typeof(preferences) == "undefined" || preferences.use_cache != 'True') |
---|
[569] | 533 | return false; |
---|
| 534 | var func = id.substr(id.lastIndexOf('.')+1); |
---|
| 535 | if (func.indexOf('&') > 0) |
---|
| 536 | func = func.substr(0,func.indexOf('&')); |
---|
| 537 | switch (func){ |
---|
| 538 | // functions that enters in cache |
---|
[605] | 539 | case 'get_info_msg': |
---|
| 540 | data.cacheHit = true; |
---|
[569] | 541 | case 'get_preferences': |
---|
| 542 | case 'getSharedUsersFrom': |
---|
| 543 | case 'get_organizations': |
---|
| 544 | case 'get_catalogs': |
---|
| 545 | case 'get_dropdown_contacts': |
---|
| 546 | case 'get_cc_contacts': |
---|
| 547 | case 'get_cc_groups': |
---|
| 548 | case 'getUsersByEmail': |
---|
[1443] | 549 | this.connectorCache.valid[id] = true; |
---|
| 550 | this.connectorCache.result[id] = data; |
---|
[569] | 551 | break; |
---|
| 552 | // function that needs expire |
---|
| 553 | case 'get_range_msgs2': |
---|
[630] | 554 | case 'quicksearch': |
---|
[569] | 555 | case 'get_folders_list': |
---|
[802] | 556 | case 'search_msg': |
---|
| 557 | case 'search_for': |
---|
[1443] | 558 | this.connectorCache.valid[id] = true; |
---|
| 559 | this.connectorCache.result[id] = data; |
---|
| 560 | var i = this.expurgatedCache.length; |
---|
| 561 | this.expurgatedCache[i+1] = id; |
---|
[569] | 562 | break; |
---|
| 563 | //functions that expires the cache |
---|
| 564 | case 'move_messages': |
---|
[605] | 565 | case 'delete_msgs': |
---|
[569] | 566 | case 'getReturnExecuteForm': |
---|
| 567 | case 'set_messages_flag': |
---|
[1965] | 568 | case 'empty_folder': |
---|
[1443] | 569 | this.purgeCache(); |
---|
[569] | 570 | default: // no cache |
---|
| 571 | break; |
---|
| 572 | } |
---|
| 573 | } |
---|
| 574 | |
---|
[2] | 575 | // Function executes AJAX |
---|
| 576 | // cExecute (url, handler, params) |
---|
| 577 | // url: 'module.class.method' |
---|
| 578 | // handle: function handle() receive response. |
---|
| 579 | // params: parameters for POST method |
---|
| 580 | // form: form element (for upload files) |
---|
| 581 | function cExecute(url, handler, params, form) { |
---|
| 582 | if(isExecuteForm){ |
---|
| 583 | isExecuteForm = false; |
---|
| 584 | document.onmouseup = _onmouseup; |
---|
| 585 | } |
---|
| 586 | if(form) { |
---|
| 587 | cExecuteForm(url, form); |
---|
| 588 | return; |
---|
| 589 | } |
---|
[569] | 590 | |
---|
[2] | 591 | url = DEFAULT_URL + url; |
---|
[569] | 592 | |
---|
[1443] | 593 | if (connector.queryConnectorCache(params?url+"&"+params:url,handler)) |
---|
[569] | 594 | return; |
---|
| 595 | |
---|
| 596 | if(params) |
---|
[2] | 597 | method = "POST"; |
---|
[569] | 598 | else |
---|
[2] | 599 | method = "GET"; |
---|
[569] | 600 | |
---|
| 601 | id = url; |
---|
[2] | 602 | connector.newRequest(id, url, method, handler, params); |
---|
| 603 | } |
---|
[569] | 604 | |
---|
| 605 | // This function executes submit values to Controller (POST) |
---|
[2] | 606 | // The return is void. |
---|
| 607 | // cExecuteForm (url, form) |
---|
| 608 | // url: 'module.class.method' |
---|
| 609 | // form: form element (for upload files) |
---|
[271] | 610 | function cExecuteForm(url, form, handler,id){ |
---|
[2] | 611 | connector.buildBar(); |
---|
[1369] | 612 | isExecuteForm = true; |
---|
| 613 | |
---|
[2] | 614 | document.onmouseup = alertBut; |
---|
[1369] | 615 | |
---|
[2] | 616 | connector.showProgressBar(); |
---|
| 617 | if(! (divUpload = document.getElementById('divUpload'))) { |
---|
| 618 | divUpload = document.createElement('DIV'); |
---|
| 619 | divUpload.id = 'divUpload'; |
---|
| 620 | document.body.appendChild(divUpload); |
---|
| 621 | } |
---|
| 622 | |
---|
| 623 | if(! (el = document.getElementById('_action'))) { |
---|
| 624 | el = document.createElement('input'); |
---|
| 625 | el.type = 'hidden'; |
---|
| 626 | el.id = '_action'; |
---|
| 627 | el.name = '_action'; |
---|
| 628 | form.appendChild(el); |
---|
| 629 | } |
---|
| 630 | |
---|
[271] | 631 | var divFiles = Element("divFiles_"+id); |
---|
[660] | 632 | if (divFiles && divFiles.firstChild) { |
---|
[2] | 633 | el = document.createElement('input'); |
---|
| 634 | el.type = 'hidden'; |
---|
| 635 | el.name = 'countFiles'; |
---|
[271] | 636 | var countDivFiles = 0; |
---|
| 637 | try{ |
---|
| 638 | countDivFiles = parseInt(divFiles.lastChild.firstChild.id.split('_')[2]) + 1; // The id of last file |
---|
| 639 | } |
---|
| 640 | catch (e) { var countDivFiles = 0; }; |
---|
| 641 | el.value = countDivFiles ; |
---|
[2] | 642 | form.appendChild(el); |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | form._action.value = url; |
---|
[1369] | 646 | // Connector Bug fixing: Encapsulating returned handler function |
---|
| 647 | handlerExecuteForm = handler; |
---|
| 648 | var form_handler = function (data){ |
---|
| 649 | handlerExecuteForm(data); |
---|
[3792] | 650 | document.getElementById('uploadFile').parentNode.removeChild(document.getElementById('uploadFile')); |
---|
[1369] | 651 | handlerExecuteForm = null; |
---|
| 652 | } |
---|
[1926] | 653 | if (is_ie) |
---|
| 654 | 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>"; |
---|
| 655 | else{ |
---|
| 656 | var iframe = document.createElement('iframe'); |
---|
| 657 | iframe.name="uploadFile"; |
---|
[3746] | 658 | iframe.id="uploadFile"; |
---|
[5210] | 659 | divUpload.appendChild(iframe); |
---|
[1926] | 660 | iframe.onload = function(){cExecute('$this.functions.getReturnExecuteForm', form_handler);} |
---|
| 661 | iframe.style.display = (debug_controller ? "" : "none"); |
---|
| 662 | iframe.style.width = (debug_controller ? 400 : 0) + "px"; |
---|
| 663 | iframe.style.height = (debug_controller ? 400 : 0) + "px"; |
---|
[5210] | 664 | |
---|
[1926] | 665 | } |
---|
| 666 | |
---|
[2] | 667 | form.action ="controller.php"; |
---|
[1247] | 668 | form.target ="uploadFile"; |
---|
[2] | 669 | form.submit(); |
---|
[1364] | 670 | // Connector Bug fixing: Exclude '_action' element after cExecuteForm execution |
---|
| 671 | if(el && el.id == '_action'){ |
---|
| 672 | el.parentNode.removeChild(el); |
---|
| 673 | } |
---|
[2] | 674 | } |
---|
| 675 | |
---|
| 676 | |
---|
| 677 | function alertBut(e) { |
---|
| 678 | if(!e) |
---|
| 679 | e = window.event; |
---|
| 680 | |
---|
| 681 | if(_onmouseup) |
---|
| 682 | _onmouseup(e); |
---|
| 683 | |
---|
| 684 | if(isExecuteForm) { |
---|
| 685 | if(confirm(get_lang("There's an action processing. Do you want abort it?"))) { |
---|
| 686 | connector.hideProgressBar(); |
---|
| 687 | isExecuteForm = false; |
---|
| 688 | delete connector.requests[id]; |
---|
| 689 | connector.requests[id] = null; |
---|
| 690 | stop(); |
---|
| 691 | return; |
---|
| 692 | } |
---|
| 693 | else |
---|
| 694 | return false; |
---|
| 695 | } |
---|
[446] | 696 | } |
---|