00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 var DesktopContent = DesktopContent || {};
00113
00114 if (typeof Debug == 'undefined')
00115 alert('ERROR: Debug is undefined! Must include Debug.js before DesktopWindowContentCode.js');
00116 if (typeof Globals == 'undefined')
00117 alert('ERROR: Globals is undefined! Must include Globals.js before DesktopWindowContentCode.js');
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 DesktopContent._isFocused = false;
00165 DesktopContent._theWindow = 0;
00166 DesktopContent._myDesktopFrame = 0;
00167 DesktopContent._zMailbox = 0;
00168 DesktopContent._mouseOverXmailbox = 0;
00169 DesktopContent._mouseOverYmailbox = 0;
00170 DesktopContent._windowMouseX = -1;
00171 DesktopContent._windowMouseY = -1;
00172
00173 DesktopContent._serverOrigin = "";
00174 DesktopContent._localOrigin = "";
00175 DesktopContent._serverUrnLid = 0;
00176 DesktopContent._localUrnLid = 0;
00177
00178 DesktopContent._cookieCodeMailbox = 0;
00179 DesktopContent._updateTimeMailbox = 0;
00180 DesktopContent._needToLoginMailbox = 0;
00181 DesktopContent._openWindowMailbox = 0;
00182 DesktopContent._blockSystemCheckMailbox = 0;
00183
00184 DesktopContent._lastCookieCode = 0;
00185 DesktopContent._lastCookieTime = 0;
00186
00187
00188 DesktopContent._verifyPopUp = 0;
00189 DesktopContent._verifyPopUpId = "DesktopContent-verifyPopUp";
00190
00191 DesktopContent._windowColorPostbox = 0;
00192 DesktopContent._dashboardColorPostbox = 0;
00193 DesktopContent._desktopColor = 0;
00194
00195 DesktopContent._sequence = 0;
00196
00197 DesktopContent._mouseMoveSubscribers = [];
00198
00199
00200
00201
00202
00203
00204
00205 DesktopContent.init = function() {
00206
00207 if(typeof Desktop !== 'undefined') return;
00208
00209 var tmpCnt = 0;
00210 DesktopContent._theWindow = self;
00211 while(tmpCnt++ < 5 && DesktopContent._theWindow &&
00212 DesktopContent._theWindow.window.name.search("DesktopWindowFrame") < 0)
00213 DesktopContent._theWindow = DesktopContent._theWindow.parent;
00214 DesktopContent._theWindow = DesktopContent._theWindow.window;
00215
00216 DesktopContent._myDesktopFrame = DesktopContent._theWindow.parent.document.getElementById(DesktopContent._theWindow.name);
00217 DesktopContent._zMailbox = DesktopContent._theWindow.parent.document.getElementById("Desktop-windowZmailbox");
00218 DesktopContent._mouseOverXmailbox = DesktopContent._theWindow.parent.document.getElementById("Desktop-mouseOverXmailbox");
00219 DesktopContent._mouseOverYmailbox = DesktopContent._theWindow.parent.document.getElementById("Desktop-mouseOverYmailbox");
00220
00221 DesktopContent._cookieCodeMailbox = DesktopContent._theWindow.parent.document.getElementById("DesktopContent-cookieCodeMailbox");
00222 DesktopContent._updateTimeMailbox = DesktopContent._theWindow.parent.document.getElementById("DesktopContent-updateTimeMailbox");
00223 DesktopContent._needToLoginMailbox = DesktopContent._theWindow.parent.document.getElementById("DesktopContent-needToLoginMailbox");
00224 DesktopContent._openWindowMailbox = DesktopContent._theWindow.parent.document.getElementById("DesktopContent-openWindowMailbox");
00225 DesktopContent._blockSystemCheckMailbox = DesktopContent._theWindow.parent.document.getElementById("DesktopContent-blockSystemCheckMailbox");
00226
00227 DesktopContent._windowColorPostbox = DesktopContent._theWindow.parent.document.getElementById("DesktopContent-windowColorPostbox");
00228 DesktopContent._dashboardColorPostbox = DesktopContent._theWindow.parent.document.getElementById("DesktopContent-dashboardColorPostbox");
00229
00230 if(DesktopContent._theWindow.parent.document.body)
00231 DesktopContent._desktopColor = DesktopContent._theWindow.parent.document.body.style.backgroundColor;
00232
00233 window.onfocus = DesktopContent.handleFocus;
00234 window.onmousedown = DesktopContent.handleFocus;
00235 window.onscroll = DesktopContent.handleScroll;
00236 window.onblur = DesktopContent.handleBlur;
00237 window.onmousemove = DesktopContent.mouseMove;
00238 window.focus();
00239
00240 DesktopContent._serverUrnLid = DesktopContent.getDesktopWindowParameter(0,"urn");
00241 if(typeof DesktopContent._serverUrnLid == 'undefined')
00242 Debug.log("ERROR -- Supervisor Application URN-LID not found",Debug.HIGH_PRIORITY);
00243 Debug.log("Supervisor Application URN-LID #" + DesktopContent._serverUrnLid);
00244 DesktopContent._serverOrigin = DesktopContent._theWindow.parent.window.location.origin;
00245 Debug.log("Supervisor Application Origin = " + DesktopContent._serverOrigin);
00246
00247 DesktopContent._localUrnLid = DesktopContent.getParameter(0,"urn");
00248 if(typeof DesktopContent._localUrnLid == 'undefined')
00249 DesktopContent._localUrnLid = 0;
00250 Debug.log("Local Application URN-LID #" + DesktopContent._localUrnLid);
00251 DesktopContent._localOrigin = window.location.origin;
00252 Debug.log("Local Application Origin = " + DesktopContent._localOrigin);
00253
00254
00255 DesktopContent._sequence = DesktopContent.getDesktopParameter(0,"code");
00256 if(!DesktopContent._sequence || DesktopContent._sequence == "")
00257 DesktopContent._sequence = 0;
00258 else
00259 Debug.log("In Wizard Mode with Sequence=" + DesktopContent._sequence);
00260 }
00261
00262
00263
00264
00265
00266 DesktopContent.getParameter = function(index,name) {
00267
00268 var params = (window.location.search.substr(1)).split('&');
00269 var spliti, vs;
00270
00271 if(name)
00272 {
00273 for(index=0;index<params.length;++index)
00274 {
00275 spliti = params[index].indexOf('=');
00276 if(spliti < 0) continue;
00277 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
00278 if(vs[0] == name)
00279 return decodeURIComponent(vs[1]);
00280 }
00281 return;
00282 }
00283
00284
00285 if(index >= params.length) return;
00286
00287 spliti = params[index].indexOf('=');
00288 if(spliti < 0) return;
00289 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
00290 return decodeURIComponent(vs[1]);
00291 }
00292
00293
00294
00295
00296 DesktopContent.getDesktopParameter = function(index, name) {
00297
00298
00299 var win = DesktopContent._theWindow;
00300 if(!win)
00301 win = window.parent.window;
00302 else
00303 win = win.parent.parent.window;
00304 var params = (win.location.search.substr(1)).split('&');
00305 if(index >= params.length) return;
00306 var spliti, vs;
00307
00308 if(name)
00309 {
00310 for(var index=0;index<params.length;++index)
00311 {
00312 spliti = params[index].indexOf('=');
00313 if(spliti < 0) continue;
00314 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
00315 if(vs[0] == name)
00316 return decodeURIComponent(vs[1]);
00317 }
00318 return;
00319 }
00320
00321 spliti = params[index].indexOf('=');
00322 if(spliti < 0) return;
00323 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
00324 return decodeURIComponent(vs[1]);
00325 }
00326
00327
00328
00329
00330 DesktopContent.getDesktopWindowParameter = function(index, name) {
00331
00332
00333 var win = DesktopContent._theWindow;
00334 if(!win)
00335 win = window;
00336 else
00337 win = win.parent.window;
00338
00339
00340 var searchStr = win.location.search.substr(1);
00341 var i = searchStr.indexOf("=securityType");
00342 if(i > 0) searchStr = searchStr.substr(0,i) + '&' + searchStr.substr(i+1);
00343
00344 var params = ((searchStr)).split('&');
00345 if(index >= params.length) return;
00346 var spliti, vs;
00347
00348 if(name)
00349 {
00350 for(var index=0;index<params.length;++index)
00351 {
00352 spliti = params[index].indexOf('=');
00353 if(spliti < 0) continue;
00354 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
00355 if(vs[0] == name)
00356 return decodeURIComponent(vs[1]);
00357 }
00358 return;
00359 }
00360
00361 spliti = params[index].indexOf('=');
00362 if(spliti < 0) return;
00363 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
00364 return decodeURIComponent(vs[1]);
00365 }
00366
00367
00368 DesktopContent.handleFocus = function(e) {
00369
00370 if(!DesktopContent._myDesktopFrame) return;
00371
00372
00373
00374 DesktopContent._isFocused = true;
00375 DesktopContent._myDesktopFrame.parentNode.parentNode.style.zIndex = DesktopContent._zMailbox.innerHTML;
00376 DesktopContent._zMailbox.innerHTML = parseInt(DesktopContent._zMailbox.innerHTML) + 1;
00377 return true;
00378 }
00379 DesktopContent.handleBlur = function(e) {
00380 DesktopContent._isFocused = false;
00381 }
00382 DesktopContent.handleScroll = function(e) {
00383 window.focus();
00384 }
00385 DesktopContent.mouseMove = function(mouseEvent) {
00386
00387 for(var i=0; i<DesktopContent._mouseMoveSubscribers.length; ++i)
00388 DesktopContent._mouseMoveSubscribers[i](mouseEvent);
00389
00390 if(!DesktopContent._myDesktopFrame) return;
00391
00392 DesktopContent._windowMouseX = parseInt(mouseEvent.clientX);
00393 DesktopContent._windowMouseY = parseInt(mouseEvent.clientY);
00394
00395
00396 DesktopContent._mouseOverXmailbox.innerHTML = parseInt(DesktopContent._myDesktopFrame.parentNode.parentNode.offsetLeft) +
00397 parseInt(DesktopContent._myDesktopFrame.offsetLeft) + DesktopContent._windowMouseX;
00398 DesktopContent._mouseOverYmailbox.innerHTML = parseInt(DesktopContent._myDesktopFrame.parentNode.parentNode.offsetTop) +
00399 parseInt(DesktopContent._myDesktopFrame.offsetTop) + DesktopContent._windowMouseY;
00400 }
00401
00402 DesktopContent.mouseMoveSubscriber = function(newHandler) {
00403 DesktopContent._mouseMoveSubscribers.push(newHandler);
00404 }
00405
00406
00407 DesktopContent.init();
00408
00409
00410
00411
00412
00413
00414
00415
00416 DesktopContent._arrayOfFailedHandlers = new Array();
00417
00418
00419
00420
00421 DesktopContent._loadBox = 0;
00422 DesktopContent._loadBoxId = "DesktopContent-load-box";
00423 DesktopContent._loadBoxTimer = 0;
00424 DesktopContent._loadBoxRequestStack = 0;
00425
00426
00427
00428
00429
00430 DesktopContent.showLoading = function(nextFunction) {
00431
00432 localDoIt();
00433 if(nextFunction)
00434 {
00435 window.setTimeout(function()
00436 {
00437 nextFunction();
00438 DesktopContent.hideLoading();
00439 },10);
00440 }
00441 return;
00442
00444 function localDoIt()
00445 {
00446 Debug.log("DesktopContent.showLoading " + DesktopContent._loadBoxRequestStack);
00447
00448 if(DesktopContent._loadBoxRequestStack++)
00449 return;
00450
00451
00452 if(!DesktopContent._loadBox)
00453 {
00454
00455 var el = document.getElementById(DesktopContent._loadBoxId);
00456 if(!el)
00457 {
00458 var body = document.getElementsByTagName("BODY")[0];
00459 if(!body)
00460 {
00461
00462 window.setTimeout(function() { Debug.errorPop(err,severity)}, 1000);
00463 return;
00464 }
00465
00466
00467 el = document.createElement("div");
00468 el.setAttribute("id", DesktopContent._loadBoxId);
00469 el.style.display = "none";
00470 var str = "";
00471
00472 str += "<table height='100%' width='100%'><td id='" +
00473 DesktopContent._loadBoxId + "-td'>Loading...</td></table>";
00474 el.innerHTML = str;
00475 body.appendChild(el);
00476
00477
00478
00479 var css = "";
00480
00481
00482
00483 css += "#" + DesktopContent._loadBoxId +
00484 "{" +
00485 "position: absolute; display: none; border: 2px solid gray;" +
00486 "background-color: rgba(0,0,0,0.8); overflow-y: auto;" +
00487 "overflow-x: auto; padding: 5px; -moz-border-radius: 2px;" +
00488 "-webkit-border-radius: 2px; border-radius: 2px;" +
00489 "font-size: 18px; z-index: 2147483647;" +
00490 "color: white; " +
00491 "font-family: 'Comfortaa', arial; text-align: left;" +
00492 "left: 8px; top: 8px; margin-right: 8px; height:400px; " +
00493 "}\n\n";
00494 css += "#" + DesktopContent._loadBoxId + " table" +
00495 "{" +
00496 "background-color: rgba(0,0,0,0.8);" +
00497 "border: 0;" +
00498 "}\n\n";
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 var style = document.createElement('style');
00510
00511 if (style.styleSheet) {
00512 style.styleSheet.cssText = css;
00513 } else {
00514 style.appendChild(document.createTextNode(css));
00515 }
00516
00517 document.getElementsByTagName('head')[0].appendChild(style);
00518 }
00519 DesktopContent._loadBox = el;
00520 }
00521
00522
00523
00524 var W = 100;
00525 var H = 60;
00526
00527 var WW,WH;
00528
00529 if(typeof DesktopContent != 'undefined')
00530 {
00531 WW = DesktopContent.getWindowWidth();
00532 WH = DesktopContent.getWindowHeight();
00533 }
00534 else if(typeof Desktop != 'undefined' && Desktop.desktop)
00535 {
00536 WW = DesktopContent.getDesktopWidth();
00537 WH = DesktopContent.getDesktopHeight();
00538 }
00539
00540 var X = DesktopContent.getWindowScrollLeft() + (WW - W - 4)/2;
00541 var Y = DesktopContent.getWindowScrollTop() + (WH - H -4)/2;
00542
00543
00544 DesktopContent._loadBox.style.left = (X) + "px";
00545 DesktopContent._loadBox.style.top = (Y) + "px";
00546 DesktopContent._loadBox.style.width = (W) + "px";
00547 DesktopContent._loadBox.style.height = (H) + "px";
00548
00549 DesktopContent._loadBox.style.display = "block";
00550
00551
00552
00553 var loadBoxStr = "..";
00554 var el = document.getElementById(DesktopContent._loadBoxId + "-td");
00555 el.innerHTML = "Loading" + loadBoxStr;
00556
00558 var loadBoxAnimationFunction = function() {
00559 if(loadBoxStr.length > 3) loadBoxStr = "";
00560 else
00561 loadBoxStr += ".";
00562 el.innerHTML = "Loading" + loadBoxStr;
00563 };
00564
00565 window.clearInterval(DesktopContent._loadBoxTimer);
00566 DesktopContent._loadBoxTimer = window.setInterval(loadBoxAnimationFunction, 300);
00567 }
00568 }
00569
00570 DesktopContent._loadBoxHideTimer = 0;
00571 DesktopContent.hideLoading = function() {
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592 window.setTimeout(localHideLoadBox, 300);
00594 function localHideLoadBox()
00595 {
00596 if(--DesktopContent._loadBoxRequestStack)
00597 return;
00598
00599 window.clearInterval(DesktopContent._loadBoxTimer);
00600 Debug.log("DesktopContent.hideLoading");
00601 document.getElementById(DesktopContent._loadBoxId).style.display = "none";
00602
00603 }
00604
00605 }
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628 DesktopContent.XMLHttpRequest = function(requestURL, data, returnHandler,
00629 reqParam, progressHandler, callHandlerOnErr, doNoShowLoadingOverlay,
00630 targetSupervisor, ignoreSystemBlock) {
00631
00632
00633 var sequence = DesktopContent._sequence;
00634 var errStr = "";
00635 var req;
00636
00637 var callerLocation = "";
00638 try
00639 {
00640 callerLocation = (new Error).stack.split("\n")[2];
00641 var tmpCallerLocation = callerLocation.slice(0,callerLocation.indexOf(' ('));
00642 callerLocation = callerLocation.slice(tmpCallerLocation.length+2,
00643 callerLocation.length-1);
00644 }
00645 catch(e) {}
00646
00647
00648 if((!ignoreSystemBlock && DesktopContent._blockSystemCheckMailbox &&
00649 DesktopContent._blockSystemCheckMailbox.innerHTML != "") ||
00650 (DesktopContent._needToLoginMailbox &&
00651 DesktopContent._needToLoginMailbox.innerHTML == "1"))
00652 {
00653
00654
00655 errStr = "The system appears to be down.";
00656 errStr += " (Try reconnecting/reloading the page, or alert ots admins if problem persists.)";
00657 Debug.log("Error: " + errStr,Debug.HIGH_PRIORITY);
00658 req = 0;
00659 var found = false;
00660 if(DesktopContent._arrayOfFailedHandlers.length < 2)
00661 {
00662 for(var rh in DesktopContent._arrayOfFailedHandlers)
00663 if(DesktopContent._arrayOfFailedHandlers[rh] == returnHandler)
00664 {
00665 errStr = "Blocking multiple error responses to same handler. \nRecurring error should be handled by returnHandler: " + returnHandler;
00666 Debug.log(errStr.substr(0,200) + "...",Debug.HIGH_PRIORITY);
00667 found = true; break;
00668 }
00669 }
00670 else
00671 {
00672 errStr = "Quiet Mode. Blocking multiple error responses to ALL handlers. \nRecurring error should be handled by returnHandler:" + returnHandler;
00673 Debug.log(errStr.substr(0,200) + "...",Debug.HIGH_PRIORITY);
00674 found = true;
00675 }
00676
00677 if(!found) DesktopContent._arrayOfFailedHandlers.push(returnHandler);
00678
00679
00680 if(returnHandler && !found && callHandlerOnErr) returnHandler(req, reqParam, errStr);
00681 return;
00682 }
00683
00684 req = new XMLHttpRequest();
00685
00686 if(progressHandler) req.upload.addEventListener("progress", progressHandler, false);
00687
00688
00689 var timeoutTimer;
00690 var timeoutFunction = function()
00691 {
00692 Debug.log("It has been 60 seconds.. still waiting for a response. " +
00693 "Is there an infinite loop occuring at the server? " +
00694 "Or is this just a really long request..",
00695 Debug.HIGH_PRIORITY);
00696 timeoutTimer = window.setTimeout(timeoutFunction, 60000);
00697 }
00698 timeoutTimer = window.setTimeout(timeoutFunction, 60000);
00699
00700
00701 req.onreadystatechange = function() {
00702
00703 if (req.readyState==4)
00704 {
00705 window.clearTimeout(timeoutTimer);
00706
00707 if(!doNoShowLoadingOverlay)
00708 DesktopContent.hideLoading();
00709
00710 if(req.status==200)
00711 {
00712
00713
00714 DesktopContent._lastCookieTime = parseInt((new Date()).getTime());
00715
00716
00717 if(req.responseText == Globals.REQ_NO_PERMISSION_RESPONSE)
00718 {
00719 errStr = "Request failed do to insufficient account permissions.";
00720
00721 }
00722 else if(req.responseText == Globals.REQ_USER_LOCKOUT_RESPONSE)
00723 {
00724 errStr = "Request failed because another user has locked ots. Put your mouse over the lock icon at the top of the dashboard to see who.";
00725
00726 }
00727 else if(req.responseText == Globals.REQ_NO_LOGIN_RESPONSE)
00728 {
00729 errStr = "Login has expired.";
00730
00731 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
00732 DesktopContent._blockSystemCheckMailbox.innerHTML == "")) &&
00733 DesktopContent._needToLoginMailbox)
00734 DesktopContent._needToLoginMailbox.innerHTML = "1";
00735
00736 }
00737 else if(req.responseText == Globals.REQ_LOCK_REQUIRED_RESPONSE)
00738 {
00739 errStr = "Request failed because the request requires the user to lockout the system. Please take over the lock in the Settings area to proceed.";
00740 }
00741 else if(!sequence)
00742 {
00743
00744 if(!req.responseXML)
00745 {
00746 errStr = "Request response is invalid XML!";
00747
00748 }
00749 else
00750 {
00751
00752 DesktopContent._lastCookieCode = DesktopContent.getXMLValue(req,'CookieCode');
00753 if (typeof DesktopContent._lastCookieCode == 'undefined')
00754 {
00755 errStr = "Request Failed - Missing Cookie in Response.";
00756
00757 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
00758 DesktopContent._blockSystemCheckMailbox.innerHTML == "")) &&
00759 DesktopContent._needToLoginMailbox)
00760 DesktopContent._needToLoginMailbox.innerHTML = "1";
00761
00762 }
00763 else if(DesktopContent._lastCookieCode != "AllowNoUser")
00764 {
00765
00766
00767 if(parseInt(DesktopContent._updateTimeMailbox.innerHTML) < DesktopContent._lastCookieTime)
00768 {
00769 DesktopContent._updateTimeMailbox.innerHTML = DesktopContent._lastCookieTime;
00770 DesktopContent._cookieCodeMailbox.innerHTML = DesktopContent._lastCookieCode;
00771
00772 setTimeout(DesktopContent.checkCookieCodeRace, Math.random()*1000|0+500);
00773 }
00774 }
00775 }
00776 }
00777 }
00778 else if(req.status == 0)
00779 {
00780
00781
00782 errStr = "Request was interrupted (Status=0). " +
00783 "Likely this means the server crashed (or the desktop window making the request was closed), " +
00784 " in the middle of a request. " +
00785 "\n(It also could mean 'potential security risk' like a cross-domain request) ";
00786
00787 }
00788 else
00789 {
00790
00791 errStr = "Request Failed (code: " + req.status + ") - Bad Address:\n" + requestURL;
00792
00793 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
00794 DesktopContent._blockSystemCheckMailbox.innerHTML == "")) &&
00795 DesktopContent._needToLoginMailbox)
00796 DesktopContent._needToLoginMailbox.innerHTML = "1";
00797
00798
00799 var found = false;
00800 if(DesktopContent._arrayOfFailedHandlers.length < 2)
00801 {
00802 for(var rh in DesktopContent._arrayOfFailedHandlers)
00803 if(DesktopContent._arrayOfFailedHandlers[rh] == returnHandler)
00804 {
00805 errStr = "Blocking multiple error responses to same handle. \nPoor error handling (Developer should fix) by returnHandler: " + returnHandler;
00806 Debug.log(errStr.substr(0,200) + "...",Debug.HIGH_PRIORITY);
00807 found = true; break;
00808 }
00809 }
00810 else
00811 {
00812 errStr = "Quiet Mode. Blocking multiple error responses to ALL handles. \nPoor error handling (Developer should fix) by returnHandler: " + returnHandler;
00813 Debug.log(errStr.substr(0,200) + "...",Debug.HIGH_PRIORITY);
00814 found = true;
00815 }
00816
00817 if(!found) DesktopContent._arrayOfFailedHandlers.push(returnHandler);
00818 if(found) return;
00819 }
00820
00821
00822 var errArr = callHandlerOnErr?[]:DesktopContent.getXMLRequestErrors(req);
00823 if(errArr.length && !callHandlerOnErr)
00824 {
00825 for(var i=0;i<errArr.length;++i)
00826 {
00827 errStr += (i?"\n\n":"") + errArr[i];
00828
00829 console.log("Initial request location: \n" + callerLocation);
00830 Debug.log("Error: " + errArr[i],
00831 (ignoreSystemBlock || requestURL.indexOf("TooltipRequest?") >= 0)?
00832 Debug.LOW_PRIORITY:
00833 Debug.HIGH_PRIORITY);
00834 }
00835 }
00836 else if(errStr != "")
00837 {
00838 errStr += "\n\n(Try refreshing the page, or alert ots admins if problem persists.)";
00839
00840 console.log("Initial request location: \n" + callerLocation);
00841 Debug.log("Error: " + errStr,
00842 (callHandlerOnErr ||
00843 ignoreSystemBlock ||
00844 requestURL.indexOf("TooltipRequest?") >= 0)?
00845 Debug.LOW_PRIORITY:
00846 Debug.HIGH_PRIORITY);
00847
00848 req = 0;
00849 }
00850
00851
00852 if(returnHandler && (errStr=="" || callHandlerOnErr))
00853 {
00854 returnHandler(req, reqParam, errStr);
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867 }
00868
00869 }
00870 }
00871
00872 if(!sequence)
00873 {
00874 if(!DesktopContent._cookieCodeMailbox)
00875 DesktopContent._cookieCodeMailbox = document.getElementById("DesktopContent-cookieCodeMailbox");
00876 var cc = DesktopContent._cookieCodeMailbox?DesktopContent._cookieCodeMailbox.innerHTML:"";
00877 data = "CookieCode="+cc+((data===undefined)?"":("&"+data));
00878 }
00879 else
00880 {
00881 data = "sequence="+sequence+"&"+((data===undefined)?"":("&"+data));
00882 }
00883
00884
00885 var urn = DesktopContent._localUrnLid;
00886 var origin = DesktopContent._localOrigin;
00887
00888 if(!urn || targetSupervisor)
00889 {
00890 urn = DesktopContent._serverUrnLid;
00891 origin = DesktopContent._serverOrigin;
00892 }
00893
00894
00895 if(!doNoShowLoadingOverlay)
00896 DesktopContent.showLoading();
00897
00898
00899 requestURL = origin+"/urn:xdaq-application:lid="+urn+"/"+requestURL;
00900
00901 req.open("POST",requestURL,true);
00902 req.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
00903 req.send(data);
00904 }
00905
00906
00907 DesktopContent.checkCookieCodeRace = function() {
00908
00909 if(parseInt(DesktopContent._updateTimeMailbox.innerHTML) < DesktopContent._lastCookieTime)
00910 {
00911 Debug.log("Cookie race occured!");
00912
00913 DesktopContent._updateTimeMailbox.innerHTML = DesktopContent._lastCookieTime;
00914 DesktopContent._cookieCodeMailbox.innerHTML = DesktopContent._lastCookieCode;
00915 }
00916 }
00917
00918
00919
00920 DesktopContent.getXMLRequestErrors = function(req) {
00921
00922 if(!req || !req.responseXML)
00923 return ["Unknown error occured " +
00924 "(XML response may have been illegal)!"];
00925
00926 var errNodes = DesktopContent.getXMLChildren(req,"Error");
00927 var errArr = [];
00928 for(var i=0;i<errNodes.length;++i)
00929 errArr.push(errNodes[i].getAttribute("value"));
00930 return errArr;
00931 }
00932
00933
00934
00935 DesktopContent.getXMLAttributeValue = function(req, name, attribute) {
00936 var el;
00937 if(el = DesktopContent.getXMLNode(req,name))
00938 return el.getAttribute(attribute);
00939 else if(name == "Error" &&
00940 (!req || !req.responseXML))
00941 return "Unknown error occured " +
00942 "(XML response may have been illegal)!";
00943 else
00944 return undefined;
00945 }
00946
00947
00948
00949
00950 DesktopContent.getXMLValue = function(req, name) {
00951 if(!name)
00952 return req.getAttribute("value");
00953 return DesktopContent.getXMLAttributeValue(req,name,"value");
00954 }
00955
00956
00957
00958
00959 DesktopContent.getXMLChildren = function(req, nodeName) {
00960
00961 if(req && req.responseXML)
00962 req = req.responseXML;
00963 return req.getElementsByTagName(nodeName);
00964 }
00965
00966
00967
00968
00969
00970 DesktopContent.getXMLNode = function(req, name) {
00971 var els;
00972 if(req && req.responseXML)
00973 req = req.responseXML;
00974 if(req)
00975 {
00976
00977 var i;
00978 els = req.getElementsByTagName(name);
00979 if(els.length)
00980 return els[0];
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994 }
00995
00996 return undefined;
00997 }
00998
00999
01000
01001 DesktopContent.getXMLDataNode = function(req, name) {
01002 return DesktopContent.getXMLNode("DATA");
01003 }
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014 DesktopContent.tooltipConditionString = function(str) {
01015 return str.replace(/<INDENT>/g,
01016 "<div style='margin-left:60px;'>").replace(/<\/INDENT>/g,
01017 "</div>");
01018 }
01019
01020 DesktopContent.tooltip = function(id,tip) {
01021
01022 if(typeof Desktop !== 'undefined')
01023 {
01024 DesktopContent._serverUrnLid = urnLid;
01025 DesktopContent._serverOrigin = "";
01026
01027 DesktopContent._sequence = DesktopContent.getDesktopParameter(0,"code");
01028 if(!DesktopContent._sequence || DesktopContent._sequence == "")
01029 DesktopContent._sequence = 0;
01030 else
01031 Debug.log("In Wizard Mode with Sequence=" + DesktopContent._sequence);
01032 }
01033
01034
01035 var srcStackString,srcFunc,srcFile;
01036
01037 if(Debug.BROWSER_TYPE == 1)
01038 {
01039 srcStackString = (new Error).stack.split("\n")[2];
01040 srcFunc = srcStackString.trim().split(' ')[1];
01041 }
01042 else if(Debug.BROWSER_TYPE == 2)
01043 {
01044 srcStackString = (new Error).stack.split("\n")[1];
01045 srcFunc = srcStackString.trim().split('@')[0];
01046 }
01047
01048 srcFile = srcStackString.substr(srcStackString.lastIndexOf('/')+1);
01049 if(srcFile.indexOf('?') >= 0)
01050 srcFile = srcFile.substr(0,srcFile.indexOf('?'));
01051 if(srcFile.indexOf(':') >= 0)
01052 srcFile.substr(0,srcFile.indexOf(':'));
01053
01054
01055 if(tip === undefined)
01056 {
01057 Debug.log("Undefined tooltip string at " + srcStackString + "\n" +
01058 srcFunc + "\n" + srcFile +".\n\n Tooltip Usage: <id> <tip>", Debug.HIGH_PRIORITY);
01059 return;
01060 }
01061
01062
01063 var oldId = id;
01064
01065 id = "";
01066 for(var i=0;i<oldId.length;++i)
01067 if((oldId[i] >= 'a' && oldId[i] <= 'z') ||
01068 (oldId[i] >= 'A' && oldId[i] <= 'Z') ||
01069 (oldId[i] >= '0' && oldId[i] <= '9'))
01070 id += oldId[i];
01071
01072 DesktopContent.XMLHttpRequest(
01073 "TooltipRequest?RequestType=check" +
01074 "&srcFunc=" + srcFunc +
01075 "&srcFile=" + srcFile +
01076 "&srcId=" + id
01077 ,""
01078 , function(req) {
01079
01080 var showTooltip = DesktopContent.getXMLValue(req,"ShowTooltip");
01081
01082
01083 if(showTooltip|0)
01084 {
01085 var str = "";
01086
01087
01088 if(id != "ALWAYS")
01089 {
01090 str += "<input checked type='checkbox' " +
01091 "id='DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
01092 id + "' " +
01093 "onclick='" +
01094 "DesktopContent.tooltipSetAlwaysShow(\"" +
01095 srcFunc + "\",\"" +
01096 srcFile + "\",\"" +
01097 id + "\", this.checked);" + "'>";
01098 str += " ";
01099 str += "<a onclick='" +
01100 "var el = document.getElementById(\"" +
01101 "DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
01102 id + "\");" +
01103 "el.checked = !el.checked;" +
01104 "DesktopContent.tooltipSetAlwaysShow(\"" +
01105 srcFunc + "\",\"" +
01106 srcFile + "\",\"" +
01107 id + "\", el.checked);" +
01108 "'>";
01109 str += "Always show the Tooltip below, or...";
01110 str += "</a>";
01111 str +="</input>";
01112
01113
01114 str += "<br>"
01115 str += "<input type='checkbox' " +
01116 "id='DesktopContent-tooltip-SetNeverShowCheckbox-hour-" +
01117 id + "' " +
01118 "onclick='" +
01119 "DesktopContent.tooltipSetAlwaysShow(\"" +
01120 srcFunc + "\",\"" +
01121 srcFile + "\",\"" +
01122 id + "\", this.checked,1);" + "'>";
01123 str += " ";
01124 str += "<a onclick='" +
01125 "var el = document.getElementById(\"" +
01126 "DesktopContent-tooltip-SetNeverShowCheckbox-hour-" +
01127 id + "\");" +
01128 "el.checked = !el.checked;" +
01129 "DesktopContent.tooltipSetAlwaysShow(\"" +
01130 srcFunc + "\",\"" +
01131 srcFile + "\",\"" +
01132 id + "\", el.checked,1);" +
01133 "'>";
01134 str += "Silence this Tooltip for an hour:";
01135 str += "</a>";
01136 str +="</input>";
01137 }
01138
01139
01140 if(id != "ALWAYS")
01141 {
01142 str += "<br><br>";
01143 str += "<center><b>'" + oldId + "' Tooltip</b></center><br>";
01144 }
01145 else
01146 str += "<br><br>";
01147
01148 str += DesktopContent.tooltipConditionString(tip);
01149
01150 str += "<br><br>";
01151
01152
01153 if(id != "ALWAYS")
01154 {
01155 str += "<input checked type='checkbox' " +
01156 "id='DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
01157 id + "' " +
01158 "onclick='" +
01159 "DesktopContent.tooltipSetAlwaysShow(\"" +
01160 srcFunc + "\",\"" +
01161 srcFile + "\",\"" +
01162 id + "\", this.checked);" + "'>";
01163 str += " ";
01164 str += "<a onclick='" +
01165 "var el = document.getElementById(\"" +
01166 "DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
01167 id + "\");" +
01168 "el.checked = !el.checked;" +
01169 "DesktopContent.tooltipSetAlwaysShow(\"" +
01170 srcFunc + "\",\"" +
01171 srcFile + "\",\"" +
01172 id + "\", el.checked);" +
01173 "'>";
01174 str += "Always show the Tooltip above.";
01175 str += "</a>";
01176 str +="</input>";
01177 }
01178
01179 Debug.log("srcStackString " + srcStackString);
01180 Debug.log(str,Debug.TIP_PRIORITY);
01181 }
01182 },0,0,0,true,true);
01183
01184 }
01185
01186
01187
01188
01189 DesktopContent.setSecurityOn = function(on) {
01190 console.log("Reached");
01191 DesktopContent.XMLHttpRequest(
01192 "ToggleSecurityCodeGeneration?RequestType=TurnGenerationOn" +
01193 "&srcFunc=0"
01194 ,""
01195 ,DesktopContent.toggleSecurityCodeGenerationHandler
01196 ,0,0,0,true,true);
01197 }
01198
01199
01200
01201 DesktopContent.toggleSecurityCodeGenerationHandler = function(req) {
01202 var status = DesktopContent.getXMLValue(req,"Status");
01203 Debug.log("Status: " + status);
01204 if (status == "Generation_Success") {
01205 Debug.log("Successfully switched to using authentication sequence!");
01206 Debug.closeErrorPop();
01207 Debug.log("If you wish to return to the default security generation, you can use the 'Reset User Information' in the " +
01208 "'Edit User Data' app.");
01209 Debug.log("Plase refer to the console for the new link!", Debug.INFO_PRIORITY);
01210 }
01211 }
01212
01213
01214
01215
01216 DesktopContent.tooltipSetAlwaysShow = function(srcFunc,srcFile,id,alwaysShow,temporarySilence) {
01217 Debug.log("alwaysShow = " + alwaysShow);
01218 if(temporarySilence)
01219 alwaysShow = 1;
01220 DesktopContent.XMLHttpRequest(
01221 "TooltipRequest?RequestType=setNeverShow" +
01222 "&srcFunc=" + srcFunc +
01223 "&srcFile=" + srcFile +
01224 "&srcId=" + id +
01225 "&doNeverShow=" + (alwaysShow?0:1) +
01226 "&temporarySilence=" + (temporarySilence?1:0)
01227 ,""
01228 ,0,0,0,0,true,true);
01229
01230 if(temporarySilence) return;
01231
01232
01233 document.getElementById("DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
01234 id).checked = alwaysShow;
01235 document.getElementById("DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
01236 id).checked = alwaysShow;
01237 }
01238
01239
01240
01241
01242
01243
01244
01245
01246
01247 DesktopContent.popUpVerification = function(prompt, func, val, bgColor, textColor, borderColor, getUserInput,
01248 dialogWidth, cancelFunc, yesButtonText) {
01249
01250
01251
01252
01253
01254
01255
01256
01257 if(DesktopContent._verifyPopUp)
01258 DesktopContent._verifyPopUp.parentNode.removeChild(DesktopContent._verifyPopUp);
01259
01260
01261 if(val != undefined)
01262 prompt = prompt.replace(/REPLACE/g, val);
01263
01264
01265
01266
01267
01268
01269 if(!bgColor) bgColor = "rgb(255,241,189)";
01270 if(!textColor) textColor = "black";
01271 if(!borderColor) borderColor = "black";
01272 if(!dialogWidth) dialogWidth = 200;
01273
01274 var css = "";
01275
01276
01277 css += "#" + DesktopContent._verifyPopUpId + " " +
01278 "{position: absolute; z-index: 2000; border-radius: 5px; padding: 10px;" +
01279 "background-color: " + bgColor + "; border: 2px solid " + borderColor + ";" +
01280 "color: " + textColor + ";text-align: center; overflow: auto;" +
01281 "}\n\n";
01282
01283 css += "#" + DesktopContent._verifyPopUpId + "-text " +
01284 "{" +
01285 "color: " + textColor + ";width: " + dialogWidth + "px; padding-bottom: 10px;" +
01286 "}\n\n";
01287
01288 css += "#" + DesktopContent._verifyPopUpId + " *" +
01289 "{" +
01290 "color: " + textColor + ";" +
01291 "}\n\n";
01292
01293
01294 var style = document.createElement('style');
01295
01296 if (style.styleSheet) {
01297 style.styleSheet.cssText = css;
01298 } else {
01299 style.appendChild(document.createTextNode(css));
01300 }
01301
01302 document.getElementsByTagName('head')[0].appendChild(style);
01303
01304
01305 var body = document.getElementsByTagName("BODY")[0];
01306
01307 var el = document.createElement("div");
01308 el.setAttribute("id", DesktopContent._verifyPopUpId);
01309
01310 var userInputStr = "";
01311 if(getUserInput)
01312 userInputStr +=
01313 "<input type='text' id='DesktopContent_popUpUserInput' " +
01314 "onclick='event.stopPropagation(); '" +
01315 ">";
01316
01317 var str = "<div id='" + DesktopContent._verifyPopUpId + "-text'>" +
01318 prompt + "<br>" + userInputStr + "</div>" +
01319 "<input type='submit' value='" +
01320 (yesButtonText?yesButtonText:"Yes") +
01321 "' " +
01322 "onclick='event.stopPropagation();' " +
01323 "> " +
01324 " " +
01325 "<input type='submit' " +
01326 "onclick='event.stopPropagation();' " +
01327 "value='Cancel'>";
01328 el.innerHTML = str;
01329
01330
01331 el.getElementsByTagName('input')[0 + (getUserInput?1:0)].onmouseup =
01332 function(event){event.stopPropagation(); DesktopContent.clearPopUpVerification(func);};
01333
01334 el.getElementsByTagName('input')[1 + (getUserInput?1:0)].onmouseup =
01335 function(event){event.stopPropagation(); DesktopContent.clearPopUpVerification(cancelFunc);};
01336
01337
01338 Debug.log(prompt);
01339 DesktopContent._verifyPopUp = el;
01340 el.style.left = "-1000px";
01341 body.appendChild(el);
01342
01343
01344 if(getUserInput)
01345 {
01346 el.getElementsByTagName('input')[0].focus();
01347 el.getElementsByTagName('input')[0].setSelectionRange(0,0);
01348
01349
01350 el.getElementsByTagName('input')[0].onkeydown =
01351 function(event)
01352 {
01353 if(event.keyCode == 13)
01354 {
01355 Debug.log("Accepting enter key");
01356 event.preventDefault();
01357 event.stopPropagation();
01358 DesktopContent.clearPopUpVerification(func);
01359 }
01360 else if(event.keyCode == 27)
01361 {
01362 Debug.log("Accepting escape key");
01363 event.preventDefault();
01364 event.stopPropagation();
01365 DesktopContent.clearPopUpVerification(cancelFunc);
01366 }
01367 };
01368 }
01369 else
01370 el.getElementsByTagName('input')[0].focus();
01371
01372
01373 el.onkeydown =
01374 function(event)
01375 {
01376 if(event.keyCode == 13)
01377 {
01378 Debug.log("Accepting enter key");
01379 event.preventDefault();
01380 event.stopPropagation();
01381 DesktopContent.clearPopUpVerification(func);
01382 }
01383 else if(event.keyCode == 27)
01384 {
01385 Debug.log("Accepting escape key");
01386 event.preventDefault();
01387 event.stopPropagation();
01388 DesktopContent.clearPopUpVerification(cancelFunc);
01389 }
01390 };
01391
01392
01393 var w = el.offsetWidth;
01394 var h = el.offsetHeight;
01395 var x = DesktopContent.getMouseX();
01396 var y = DesktopContent.getMouseY();
01397 x -= w/2;
01398 Debug.log("X: " + x +
01399 " Y: " + y +
01400 " W: " + w +
01401 " H: " + h);
01402
01403 while(x+w > DesktopContent.getWindowWidth())
01404 x -= w;
01405 if(y > DesktopContent.getWindowHeight()/2 + h/2)
01406 y -= h;
01407 while(y+h > DesktopContent.getWindowHeight())
01408 y -= h;
01409
01410 if(x <= 0) x = 10;
01411 if(y <= 0) y = 10;
01412
01413 Debug.log("X: " + x +
01414 " Y: " + y +
01415 " W: " + w +
01416 " H: " + h);
01417
01418 el.style.left = (DesktopContent.getWindowScrollLeft() + x) + "px";
01419 el.style.top = (DesktopContent.getWindowScrollTop() + y) + "px";
01420 }
01421
01422
01423
01424 DesktopContent.clearPopUpVerification = function(func) {
01425
01426
01427
01428 var userEl = document.getElementById("DesktopContent_popUpUserInput");
01429 var param = userEl?userEl.value:undefined;
01430
01431
01432 if(DesktopContent._verifyPopUp) DesktopContent._verifyPopUp.parentNode.removeChild(DesktopContent._verifyPopUp);
01433 DesktopContent._verifyPopUp = 0;
01434
01435 if(func)
01436 func(param);
01437 }
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456 DesktopContent.setPopUpPosition = function(el,w,h,padding,border,
01457 margin,doNotResize,offsetUp) {
01458
01459 Debug.log("DesktopContent.setPopUpPosition");
01460
01461 if(padding === undefined) padding = 10;
01462 if(border === undefined) border = 1;
01463 if(margin === undefined) margin = 0;
01464
01465 var x,y;
01466
01467
01468
01469
01470 DesktopContent.setPopUpPosition.stopPropagation = function(event) {
01471
01472 event.stopPropagation();
01473 }
01474
01475
01476
01477
01478 DesktopContent.setPopUpPosition.popupResize = function() {
01479
01480 try
01481 {
01482 if(!el)
01483 {
01484 window.removeEventListener("resize",DesktopContent.setPopUpPosition.popupResize);
01485 window.removeEventListener("scroll",DesktopContent.setPopUpPosition.popupResize);
01486 return;
01487 }
01488 }
01489 catch(err) {return;}
01490
01491
01492
01493
01494
01495 var ww = DesktopContent.getWindowWidth()-(padding+border)*2;
01496 var wh = DesktopContent.getWindowHeight()-(padding+border)*2;
01497
01498
01499
01500 var ah = el.offsetHeight;
01501
01502 if(w === undefined || h === undefined)
01503 {
01504 w = ww - (margin)*2;
01505 h = wh - (margin)*2;
01506 }
01507
01508
01509 x = (DesktopContent.getWindowScrollLeft() + ((ww-w)/2));
01510 y = (DesktopContent.getWindowScrollTop() + ((wh-h)/2)) - (offsetUp|0) - 100;
01511
01512 if(y < DesktopContent.getWindowScrollTop() +
01513 margin + padding)
01514 y = DesktopContent.getWindowScrollTop() + margin +
01515 padding;
01516
01517
01518 if(w > ww-margin-padding)
01519 x = -DesktopContent.getWindowScrollLeft();
01520 if(ah > wh-margin-padding)
01521 y = -DesktopContent.getWindowScrollTop();
01522
01523 el.style.left = x + "px";
01524 el.style.top = y + "px";
01525 };
01526 DesktopContent.setPopUpPosition.popupResize();
01527
01528
01529 el.style.width = w + "px";
01530 el.style.height = h + "px";
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542 el.style.position = "absolute";
01543 el.style.zIndex = "10000";
01544 el.style.border = "1px solid #770000";
01545 el.style.backgroundColor = "#efeaea";
01546 el.style.textAlign = "center";
01547 el.style.padding = "10px";
01548 el.style.color = "black";
01549
01550 if(!doNotResize)
01551 {
01552 window.addEventListener("resize",DesktopContent.setPopUpPosition.popupResize);
01553 window.addEventListener("scroll",DesktopContent.setPopUpPosition.popupResize);
01554 }
01555 el.addEventListener("keydown",DesktopContent.setPopUpPosition.stopPropagation);
01556 el.addEventListener("mousemove",DesktopContent.setPopUpPosition.stopPropagation);
01557 el.addEventListener("mousemove",DesktopContent.mouseMove);
01558
01559 el.style.overflow = "auto";
01560
01561 return {"w" : w, "h" : h, "x" : x, "y" : y};
01562
01563 }
01564
01565
01566
01567 DesktopContent.parseColor = function(colorStr) {
01568
01569
01570
01571 var m = colorStr.split("(")[1].split(")")[0].split(",");
01572 if( m) return "rgb("+m[0]+","+m[1]+","+m[2]+")";
01573 else throw new Error("Color "+colorStr+" could not be parsed.");
01574 }
01575
01576
01577
01578
01579
01580 DesktopContent.getColorAsRGBA = function(colorStr) {
01581
01582
01583 var div = document.createElement('div');
01584 var m;
01585
01586 div.style.color = colorStr;
01587 div.style.display = "none";
01588 document.body.appendChild(div);
01589
01590 m = getComputedStyle(div).color.split("(")[1].split(")")[0].split(",");
01591
01592 document.body.removeChild(div);
01593
01594 if(m && m.length == 3) return "rgba("+m[0]+","+m[1]+","+m[2]+",255)";
01595 else if(m && m.length == 4) return "rgba("+m[0]+","+m[1]+","+m[2]+","+m[3]+")";
01596 else throw new Error("Color "+colorStr+" could not be parsed.");
01597 }
01598
01599
01600
01601
01602 DesktopContent.getWindowWidth = function() { return window.innerWidth; }
01603 DesktopContent.getWindowHeight = function() { return window.innerHeight; }
01604 DesktopContent.getBodyWidth = function() { return document.body.offsetWidth; }
01605 DesktopContent.getBodyHeight = function() { return document.body.offsetHeight; }
01606 DesktopContent.getWindowScrollLeft = function() { return document.documentElement.scrollLeft || document.body.scrollLeft || 0; }
01607 DesktopContent.getWindowScrollTop = function() { return document.documentElement.scrollTop || document.body.scrollTop || 0; }
01608 DesktopContent.getMouseX = function() { return DesktopContent._windowMouseX | 0; }
01609 DesktopContent.getMouseY = function() { return DesktopContent._windowMouseY | 0; }
01610 DesktopContent.getDefaultWindowColor = function() {
01611
01612 if(!DesktopContent._windowColorPostbox || !DesktopContent._desktopColor)
01613 {
01614
01615 Debug.log("Color post boxes not setup! So giving default.",Debug.MED_PRIORITY);
01616 return "rgb(178,210,240)";
01617 }
01618
01619 wrgba = DesktopContent._windowColorPostbox.innerHTML.split("(")[1].split(")")[0].split(",");
01620 drgb = DesktopContent._desktopColor.split("(")[1].split(")")[0].split(",");
01621 for(var i in drgb)
01622 drgb[i] = (drgb[i]*(1-wrgba[3]) + wrgba[i]*wrgba[3])|0;
01623 return "rgb("+drgb[0]+","+drgb[1]+","+drgb[2]+")";
01624 }
01625
01626
01627
01628 DesktopContent.getDefaultDashboardColor = function() { return DesktopContent.parseColor(DesktopContent._dashboardColorPostbox.innerHTML); }
01629 DesktopContent.getDefaultDesktopColor = function() {
01630 if(!DesktopContent._desktopColor)
01631 {
01632
01633 Debug.log("Color post boxes not setup! So giving default.",Debug.MED_PRIORITY);
01634 return "rgb(15,34,105)";
01635 }
01636 return DesktopContent._desktopColor;
01637 }
01638
01639
01640
01641 DesktopContent.getUsername = function() {
01642 var dispName = DesktopContent._theWindow.parent.document.getElementById("DesktopDashboard-user-displayName").innerHTML
01643 return dispName.substr(dispName.indexOf(",")+2);
01644 }
01645
01646
01647
01648
01649
01650
01651 DesktopContent.openNewWindow = function(name,subname,windowPath,unique,completeHandler) {
01652
01653 Debug.log("DesktopContent.openNewWindow= " + windowPath);
01654 Debug.log("name= " + name);
01655 Debug.log("subname= " + subname);
01656 Debug.log("unique= " + unique);
01657
01658
01659
01660 var paramsStr = DesktopContent._openWindowMailbox.innerHTML;
01661
01662
01663 var tryAgainCount = 0;
01664
01665
01666 if(paramsStr != "")
01667 {
01668 Debug.log("Window creation is busy, trying again soon!");
01669
01670 ++tryAgainCount;
01671
01672 if(tryAgainCount > 50)
01673 {
01674 Debug.log("It looks like the window failed to open. Perhaps the Desktop is disconnected from the server; " +
01675 "please reconnect and try again.", Debug.WARN_PRIORITY);
01676 return;
01677 }
01678
01679 setTimeout(function(){ DesktopContent.openNewWindow(windowPath); }, 100);
01680 return;
01681 }
01682
01683
01684 var str = "requestingWindowId=" + DesktopContent._myDesktopFrame.id.split('-')[1];
01685 str += "&windowName=" + name;
01686 str += "&windowSubname=" + subname;
01687 str += "&windowUnique=" + unique;
01688 str += "&windowPath=" + windowPath;
01689 DesktopContent._openWindowMailbox.innerHTML = str;
01690
01691 Debug.log("Waiting for complete...");
01692
01693 tryAgainCount = 0;
01694 var timeoutHandler = function() {
01695 Debug.log("Checking for complete...");
01696
01697 ++tryAgainCount;
01698
01699 if(tryAgainCount > 50)
01700 {
01701 Debug.log("It looks like the window failed to open. Perhaps the Desktop is disconnected from the server; " +
01702 "please reconnect and try again.", Debug.WARN_PRIORITY);
01703 return;
01704 }
01705
01706
01707
01708 var paramsStr = DesktopContent._openWindowMailbox.innerHTML;
01709 var spliti = paramsStr.indexOf('&');
01710 params = [paramsStr.substr(0,spliti),paramsStr.substr(spliti+5)];
01711 var varPair;
01712 var requestingWindowId = "", done = "";
01713 for(var i=0;i<params.length;++i)
01714 {
01715 spliti = params[i].indexOf('=');
01716 varPair = [params[i].substr(0,spliti),params[i].substr(spliti+1)];
01717 if(varPair[0] == "requestingWindowId")
01718 requestingWindowId = varPair[1];
01719 else if(varPair[0] == "done")
01720 done = varPair[1];
01721 }
01722
01723 if(paramsStr = "" || (requestingWindowId != "" && done != ""))
01724 {
01725
01726 Debug.log("requestingWindowId=" + requestingWindowId);
01727 Debug.log("done=" + done);
01728 if(requestingWindowId != DesktopContent._myDesktopFrame.id.split('-')[1])
01729 Debug.log("There was a mismatch in window id!",Debug.MED_PRIORITY);
01730
01731
01732 DesktopContent._openWindowMailbox.innerHTML = "";
01733
01734 if(completeHandler)
01735 completeHandler();
01736 return;
01737 }
01738 else
01739 setTimeout(timeoutHandler, 100);
01740
01741 };
01742
01743 setTimeout(timeoutHandler,
01744 100);
01745
01746 }
01747
01748
01749
01750
01751
01752
01753
01754
01755 DesktopContent.openNewBrowserTab = function(name,subname,windowPath,unique) {
01756
01757 if(windowPath !== undefined)
01758 {
01759
01760
01761 try
01762 {
01763 var i = windowPath.indexOf("urn:xdaq-application:lid=") + ("urn:xdaq-application:lid=").length;
01764 var isAllNumbers = true;
01765 for(i;i<windowPath.length;++i)
01766 {
01767
01768
01769 if(windowPath[i] < "0" || windowPath[i] > "9")
01770 {
01771 isAllNumbers = false;
01772 break;
01773 }
01774 }
01775 if(isAllNumbers)
01776 windowPath += "/";
01777 }
01778 catch(e)
01779 {
01780 Debug.log("An error occurred while trying to open the window. " +
01781 "The window path seems to be invalid: " + e, Debug.HIGH_PRIORITY);
01782 return;
01783 }
01784 }
01785 Debug.log("DesktopWindow= " + windowPath);
01786
01787 Debug.log("name= " + name);
01788 Debug.log("subname= " + subname);
01789 Debug.log("unique= " + unique);
01790
01791 var search = DesktopContent._theWindow.parent.parent.window.location.search;
01792 url = DesktopContent._theWindow.parent.parent.window.location.pathname;
01793
01794 var str = "requestingWindowId=" + DesktopContent._myDesktopFrame.id.split('-')[1];
01795 str += "&windowName=" + name;
01796 str += "&windowSubname=" + subname;
01797 str += "&windowUnique=" + unique;
01798 str += "&windowPath=" + windowPath;
01799
01800
01801
01802
01803 if(search == "")
01804 {
01805 var i = url.indexOf("urn:xdaq-application:lid=") + ("urn:xdaq-application:lid=").length;
01806 var isAllNumbers = true;
01807 for(i;i<url.length;++i)
01808 {
01809 Debug.log(url[i]);
01810
01811 if(url[i] < "0" || url[i] > "9")
01812 {
01813 isAllNumbers = false;
01814 break;
01815 }
01816 }
01817 if(isAllNumbers)
01818 url += "/";
01819 url += "?" + str;
01820 }
01821 else
01822 {
01823
01824 var i = search.indexOf("requestingWindowId");
01825 if(i >= 0)
01826 search = search.substr(0,i);
01827
01828 if(search.length && search[search.length-1] != '?'
01829 && search[search.length-1] != '&')
01830 search += '&';
01831 url += search + str;
01832 }
01833
01834 Debug.log("DesktopContent.openNewBrowserTab= " + url);
01835
01836 window.open(url,'_blank');
01837 }
01838
01839
01840
01841 DesktopContent.getDesktopWindowTitle = function() {
01842 return DesktopContent._theWindow.parent.document.getElementById(
01843 "DesktopWindowHeader-" +
01844 DesktopContent._theWindow.name.split('-')[1]).innerHTML;
01845 }
01846
01847
01848
01849
01850
01851
01852