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