113 var DesktopContent = DesktopContent || {};
115 if (typeof Debug ==
'undefined')
116 alert(
'ERROR: Debug is undefined! Must include Debug.js before DesktopWindowContentCode.js');
117 if (typeof Globals ==
'undefined')
118 alert(
'ERROR: Globals is undefined! Must include Globals.js before DesktopWindowContentCode.js');
166 DesktopContent._isFocused =
false;
167 DesktopContent._theWindow = 0;
168 DesktopContent._myDesktopFrame = 0;
169 DesktopContent._zMailbox = 0;
170 DesktopContent._mouseOverXmailbox = 0;
171 DesktopContent._mouseOverYmailbox = 0;
172 DesktopContent._windowMouseX = -1;
173 DesktopContent._windowMouseY = -1;
175 DesktopContent._serverOrigin =
"";
176 DesktopContent._localOrigin =
"";
177 DesktopContent._serverUrnLid = 0;
178 DesktopContent._localUrnLid = 0;
180 DesktopContent._cookieCodeMailbox = 0;
181 DesktopContent._updateTimeMailbox = 0;
182 DesktopContent._needToLoginMailbox = 0;
183 DesktopContent._openWindowMailbox = 0;
184 DesktopContent._blockSystemCheckMailbox = 0;
186 DesktopContent._lastCookieCode = 0;
187 DesktopContent._lastCookieTime = 0;
190 DesktopContent._verifyPopUp = 0;
191 DesktopContent._verifyPopUpId =
"DesktopContent-verifyPopUp";
193 DesktopContent._windowColorPostbox = 0;
194 DesktopContent._dashboardColorPostbox = 0;
195 DesktopContent._desktopColor = 0;
197 DesktopContent._sequence = 0;
199 DesktopContent._mouseMoveSubscribers = [];
207 DesktopContent.init =
function() {
209 if(typeof Desktop !==
'undefined')
return;
212 DesktopContent._theWindow =
self;
213 while(tmpCnt++ < 5 && DesktopContent._theWindow &&
214 DesktopContent._theWindow.window.name.search(
"DesktopWindowFrame") < 0)
215 DesktopContent._theWindow = DesktopContent._theWindow.parent;
216 DesktopContent._theWindow = DesktopContent._theWindow.window;
218 DesktopContent._myDesktopFrame = DesktopContent._theWindow.parent.document.getElementById(DesktopContent._theWindow.name);
219 DesktopContent._zMailbox = DesktopContent._theWindow.parent.document.getElementById(
"Desktop-windowZmailbox");
220 DesktopContent._mouseOverXmailbox = DesktopContent._theWindow.parent.document.getElementById(
"Desktop-mouseOverXmailbox");
221 DesktopContent._mouseOverYmailbox = DesktopContent._theWindow.parent.document.getElementById(
"Desktop-mouseOverYmailbox");
223 DesktopContent._cookieCodeMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-cookieCodeMailbox");
224 DesktopContent._updateTimeMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-updateTimeMailbox");
225 DesktopContent._needToLoginMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-needToLoginMailbox");
226 DesktopContent._openWindowMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-openWindowMailbox");
227 DesktopContent._blockSystemCheckMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-blockSystemCheckMailbox");
229 DesktopContent._windowColorPostbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-windowColorPostbox");
230 DesktopContent._dashboardColorPostbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-dashboardColorPostbox");
232 if(DesktopContent._theWindow.parent.document.body)
233 DesktopContent._desktopColor = DesktopContent._theWindow.parent.document.body.style.backgroundColor;
235 window.onfocus = DesktopContent.handleFocus;
236 window.onmousedown = DesktopContent.handleFocus;
237 window.onscroll = DesktopContent.handleScroll;
238 window.onblur = DesktopContent.handleBlur;
239 window.onmousemove = DesktopContent.mouseMove;
242 Debug.log(
"Window URL " + window.location.href);
244 DesktopContent._serverUrnLid = DesktopContent.getDesktopWindowParameter(0,
"urn");
245 if(typeof DesktopContent._serverUrnLid ==
'undefined')
246 Debug.log(
"ERROR -- Supervisor Application URN-LID not found",Debug.HIGH_PRIORITY);
247 Debug.log(
"Supervisor Application URN-LID #" + DesktopContent._serverUrnLid);
248 DesktopContent._serverOrigin = DesktopContent._theWindow.parent.window.location.origin;
249 Debug.log(
"Supervisor Application Origin = " + DesktopContent._serverOrigin);
251 DesktopContent._localUrnLid = DesktopContent.getParameter(0,
"urn");
252 if(typeof DesktopContent._localUrnLid ==
'undefined')
253 DesktopContent._localUrnLid = 0;
254 Debug.log(
"Local Application URN-LID #" + DesktopContent._localUrnLid);
255 DesktopContent._localOrigin = window.location.origin;
256 Debug.log(
"Local Application Origin = " + DesktopContent._localOrigin);
259 DesktopContent._sequence = DesktopContent.getDesktopParameter(0,
"code");
260 if(!DesktopContent._sequence || DesktopContent._sequence ==
"")
261 DesktopContent._sequence = 0;
263 Debug.log(
"In Wizard Mode with Sequence=" + DesktopContent._sequence);
270 DesktopContent.getParameter =
function(index,name) {
272 var params = (window.location.search.substr(1)).split(
'&');
277 for(index=0;index<params.length;++index)
279 spliti = params[index].indexOf(
'=');
280 if(spliti < 0)
continue;
281 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
282 if(decodeURIComponent(vs[0]) == name)
283 return decodeURIComponent(vs[1]);
289 if(index >= params.length)
return;
291 spliti = params[index].indexOf(
'=');
292 if(spliti < 0)
return;
293 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
294 return decodeURIComponent(vs[1]);
300 DesktopContent.getDesktopParameter =
function(index, name) {
303 var win = DesktopContent._theWindow;
305 win = window.parent.window;
307 win = win.parent.parent.window;
308 var params = (win.location.search.substr(1)).split(
'&');
309 if(index >= params.length)
return;
314 for(var index=0;index<params.length;++index)
316 spliti = params[index].indexOf(
'=');
317 if(spliti < 0)
continue;
318 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
320 return decodeURIComponent(vs[1]);
325 spliti = params[index].indexOf(
'=');
326 if(spliti < 0)
return;
327 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
328 return decodeURIComponent(vs[1]);
334 DesktopContent.getDesktopWindowParameter =
function(index, name) {
337 var win = DesktopContent._theWindow;
341 win = win.parent.window;
344 var searchStr = win.location.search.substr(1);
345 var i = searchStr.indexOf(
"=securityType");
346 if(i > 0) searchStr = searchStr.substr(0,i) +
'&' + searchStr.substr(i+1);
348 var params = ((searchStr)).split(
'&');
349 if(index >= params.length)
return;
354 for(var index=0;index<params.length;++index)
356 spliti = params[index].indexOf(
'=');
357 if(spliti < 0)
continue;
358 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
360 return decodeURIComponent(vs[1]);
365 spliti = params[index].indexOf(
'=');
366 if(spliti < 0)
return;
367 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
368 return decodeURIComponent(vs[1]);
372 DesktopContent.handleFocus =
function(e) {
374 if(!DesktopContent._myDesktopFrame)
return;
380 DesktopContent._isFocused =
true;
381 DesktopContent._myDesktopFrame.parentNode.parentNode.style.zIndex = DesktopContent._zMailbox.innerHTML;
382 DesktopContent._zMailbox.innerHTML = parseInt(DesktopContent._zMailbox.innerHTML) + 1;
385 DesktopContent.handleBlur =
function(e) {
387 DesktopContent._isFocused =
false;
389 DesktopContent.handleScroll =
function(e) {
393 DesktopContent.mouseMove =
function(mouseEvent) {
397 for(var i=0; i<DesktopContent._mouseMoveSubscribers.length; ++i)
398 DesktopContent._mouseMoveSubscribers[i](mouseEvent);
400 if(!DesktopContent._myDesktopFrame)
return;
402 DesktopContent._windowMouseX = parseInt(mouseEvent.clientX);
403 DesktopContent._windowMouseY = parseInt(mouseEvent.clientY);
406 DesktopContent._mouseOverXmailbox.innerHTML = parseInt(DesktopContent._myDesktopFrame.parentNode.parentNode.offsetLeft) +
407 parseInt(DesktopContent._myDesktopFrame.offsetLeft) + DesktopContent._windowMouseX;
408 DesktopContent._mouseOverYmailbox.innerHTML = parseInt(DesktopContent._myDesktopFrame.parentNode.parentNode.offsetTop) +
409 parseInt(DesktopContent._myDesktopFrame.offsetTop) + DesktopContent._windowMouseY;
412 DesktopContent.mouseMoveSubscriber =
function(newHandler) {
413 DesktopContent._mouseMoveSubscribers.push(newHandler);
417 DesktopContent.init();
426 DesktopContent._arrayOfFailedHandlers =
new Array();
431 DesktopContent._loadBox = 0;
432 DesktopContent._loadBoxId =
"DesktopContent-load-box";
433 DesktopContent._loadBoxTimer = 0;
434 DesktopContent._loadBoxRequestStack = 0;
440 DesktopContent.showLoading =
function(nextFunction) {
445 window.setTimeout(
function()
448 DesktopContent.hideLoading();
456 Debug.log(
"DesktopContent.showLoading " + DesktopContent._loadBoxRequestStack);
458 if(DesktopContent._loadBoxRequestStack++)
462 if(!DesktopContent._loadBox)
465 var el = document.getElementById(DesktopContent._loadBoxId);
468 var body = document.getElementsByTagName(
"BODY")[0];
472 window.setTimeout(
function() { Debug.errorPop(err,severity)}, 1000);
477 el = document.createElement(
"div");
478 el.setAttribute(
"id", DesktopContent._loadBoxId);
479 el.style.display =
"none";
482 str +=
"<table height='100%' width='100%'><td id='" +
483 DesktopContent._loadBoxId +
"-td'>Loading...</td></table>";
485 body.appendChild(el);
493 css +=
"#" + DesktopContent._loadBoxId +
495 "position: absolute; display: none; border: 2px solid gray;" +
496 "background-color: rgba(0,0,0,0.8); overflow-y: auto;" +
497 "overflow-x: auto; padding: 5px; -moz-border-radius: 2px;" +
498 "-webkit-border-radius: 2px; border-radius: 2px;" +
499 "font-size: 18px; z-index: 2147483647;" +
501 "font-family: 'Comfortaa', arial; text-align: left;" +
502 "left: 8px; top: 8px; margin-right: 8px; height:400px; " +
504 css +=
"#" + DesktopContent._loadBoxId +
" table" +
506 "background-color: rgba(0,0,0,0.8);" +
519 var style = document.createElement(
'style');
521 if (style.styleSheet) {
522 style.styleSheet.cssText = css;
524 style.appendChild(document.createTextNode(css));
527 document.getElementsByTagName(
'head')[0].appendChild(style);
529 DesktopContent._loadBox = el;
539 if(typeof DesktopContent !=
'undefined')
541 WW = DesktopContent.getWindowWidth();
542 WH = DesktopContent.getWindowHeight();
544 else if(typeof Desktop !=
'undefined' && Desktop.desktop)
546 WW = DesktopContent.getDesktopWidth();
547 WH = DesktopContent.getDesktopHeight();
550 var X = DesktopContent.getWindowScrollLeft() + (WW - W - 4)/2;
551 var Y = DesktopContent.getWindowScrollTop() + (WH - H -4)/2;
554 DesktopContent._loadBox.style.left = (X) +
"px";
555 DesktopContent._loadBox.style.top = (Y) +
"px";
556 DesktopContent._loadBox.style.width = (W) +
"px";
557 DesktopContent._loadBox.style.height = (H) +
"px";
559 DesktopContent._loadBox.style.display =
"block";
563 var loadBoxStr =
"..";
564 var el = document.getElementById(DesktopContent._loadBoxId +
"-td");
565 el.innerHTML =
"Loading" + loadBoxStr;
568 var loadBoxAnimationFunction =
function() {
569 if(loadBoxStr.length > 3) loadBoxStr =
"";
572 el.innerHTML =
"Loading" + loadBoxStr;
575 window.clearInterval(DesktopContent._loadBoxTimer);
576 DesktopContent._loadBoxTimer = window.setInterval(loadBoxAnimationFunction, 300);
580 DesktopContent._loadBoxHideTimer = 0;
581 DesktopContent.hideLoading =
function() {
602 window.setTimeout(localHideLoadBox, 300);
604 function localHideLoadBox()
606 if(--DesktopContent._loadBoxRequestStack)
609 window.clearInterval(DesktopContent._loadBoxTimer);
610 Debug.log(
"DesktopContent.hideLoading");
611 document.getElementById(DesktopContent._loadBoxId).style.display =
"none";
638 DesktopContent.XMLHttpRequest =
function(requestURL, data, returnHandler,
639 reqParam, progressHandler, callHandlerOnErr, doNotShowLoadingOverlay,
640 targetSupervisor, ignoreSystemBlock) {
643 var sequence = DesktopContent._sequence;
647 var callerLocation =
"";
650 callerLocation = (
new Error).stack.split(
"\n")[2];
651 var tmpCallerLocation = callerLocation.slice(0,callerLocation.indexOf(
' ('));
652 callerLocation = callerLocation.slice(tmpCallerLocation.length+2,
653 callerLocation.length-1);
658 if((!ignoreSystemBlock && DesktopContent._blockSystemCheckMailbox &&
659 DesktopContent._blockSystemCheckMailbox.innerHTML !=
"") ||
660 (DesktopContent._needToLoginMailbox &&
661 DesktopContent._needToLoginMailbox.innerHTML ==
"1"))
665 errStr =
"The system appears to be down.";
666 errStr +=
" (Try reconnecting/reloading the page, or alert ots admins if problem persists.)";
667 Debug.log(
"Error: " + errStr,Debug.HIGH_PRIORITY);
670 if(DesktopContent._arrayOfFailedHandlers.length < 2)
672 for(var rh in DesktopContent._arrayOfFailedHandlers)
673 if(DesktopContent._arrayOfFailedHandlers[rh] == returnHandler)
675 errStr =
"Blocking multiple error responses to same handler. \nRecurring error should be handled by returnHandler: " + returnHandler;
676 Debug.log(errStr.substr(0,200) +
"...",Debug.HIGH_PRIORITY);
682 errStr =
"Quiet Mode. Blocking multiple error responses to ALL handlers. \nRecurring error should be handled by returnHandler:" + returnHandler;
683 Debug.log(errStr.substr(0,200) +
"...",Debug.HIGH_PRIORITY);
687 if(!found) DesktopContent._arrayOfFailedHandlers.push(returnHandler);
690 if(returnHandler && !found && callHandlerOnErr) returnHandler(req, reqParam, errStr);
694 req =
new XMLHttpRequest();
696 if(progressHandler) req.upload.addEventListener(
"progress", progressHandler,
false);
700 var timeoutFunction =
function()
702 Debug.log(
"It has been 60 seconds.. still waiting for a response. " +
703 "Is there an infinite loop occuring at the server? " +
704 "Or is this just a really long request..",
705 Debug.HIGH_PRIORITY);
706 timeoutTimer = window.setTimeout(timeoutFunction, 60000);
708 timeoutTimer = window.setTimeout(timeoutFunction, 60000);
711 req.onreadystatechange =
function() {
713 if (req.readyState==4)
715 window.clearTimeout(timeoutTimer);
717 if(!doNotShowLoadingOverlay)
718 DesktopContent.hideLoading();
724 DesktopContent._lastCookieTime = parseInt((
new Date()).getTime());
727 if(req.responseText == Globals.REQ_NO_PERMISSION_RESPONSE)
729 errStr =
"Request failed due to insufficient account permissions.";
732 else if(req.responseText == Globals.REQ_USER_LOCKOUT_RESPONSE)
734 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.";
737 else if(req.responseText == Globals.REQ_NO_LOGIN_RESPONSE)
739 errStr =
"Login has expired.";
741 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
742 DesktopContent._blockSystemCheckMailbox.innerHTML ==
"")) &&
743 DesktopContent._needToLoginMailbox)
744 DesktopContent._needToLoginMailbox.innerHTML =
"1";
747 else if(req.responseText == Globals.REQ_LOCK_REQUIRED_RESPONSE)
749 errStr =
"Request failed because the request requires the user to lockout the system. Please take over the lock in the Settings area to proceed.";
756 errStr =
"Request response is invalid XML!";
762 DesktopContent._lastCookieCode = DesktopContent.getXMLValue(req,
'CookieCode');
763 if (typeof DesktopContent._lastCookieCode ==
'undefined')
765 errStr =
"Request Failed - Missing Cookie in Response.";
767 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
768 DesktopContent._blockSystemCheckMailbox.innerHTML ==
"")) &&
769 DesktopContent._needToLoginMailbox)
770 DesktopContent._needToLoginMailbox.innerHTML =
"1";
773 else if(DesktopContent._lastCookieCode !=
"AllowNoUser")
777 if(parseInt(DesktopContent._updateTimeMailbox.innerHTML) < DesktopContent._lastCookieTime)
779 DesktopContent._updateTimeMailbox.innerHTML = DesktopContent._lastCookieTime;
780 DesktopContent._cookieCodeMailbox.innerHTML = DesktopContent._lastCookieCode;
782 setTimeout(DesktopContent.checkCookieCodeRace, Math.random()*1000|0+500);
788 else if(req.status == 0)
792 errStr =
"Request was interrupted (Status=0). " +
793 "Likely this means the server crashed (or the desktop window making the request was closed), " +
794 " in the middle of a request. " +
795 "\n(It also could mean 'potential security risk' like a cross-domain request) ";
801 errStr =
"Request Failed (code: " + req.status +
") - Bad Address:\n" + requestURL;
803 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
804 DesktopContent._blockSystemCheckMailbox.innerHTML ==
"")) &&
805 DesktopContent._needToLoginMailbox)
806 DesktopContent._needToLoginMailbox.innerHTML =
"1";
810 if(DesktopContent._arrayOfFailedHandlers.length < 2)
812 for(var rh in DesktopContent._arrayOfFailedHandlers)
813 if(DesktopContent._arrayOfFailedHandlers[rh] == returnHandler)
815 errStr =
"Blocking multiple error responses to same handle. \nPoor error handling (Developer should fix) by returnHandler: " + returnHandler;
816 Debug.log(errStr.substr(0,200) +
"...",Debug.HIGH_PRIORITY);
822 errStr =
"Quiet Mode. Blocking multiple error responses to ALL handles. \nPoor error handling (Developer should fix) by returnHandler: " + returnHandler;
823 Debug.log(errStr.substr(0,200) +
"...",Debug.HIGH_PRIORITY);
827 if(!found) DesktopContent._arrayOfFailedHandlers.push(returnHandler);
832 var errArr = (callHandlerOnErr || !req.responseXML)?[]:DesktopContent.getXMLRequestErrors(req);
833 if(errArr.length && !callHandlerOnErr)
835 for(var i=0;i<errArr.length;++i)
837 errStr += (i?
"\n\n":
"") + errArr[i];
839 console.log(
"Initial request location: \n" + callerLocation);
840 Debug.log(
"Error: " + errArr[i],
841 (ignoreSystemBlock || requestURL.indexOf(
"TooltipRequest?") >= 0)?
843 Debug.HIGH_PRIORITY);
846 else if(errStr !=
"")
848 errStr +=
"\n\n(Try refreshing the page, or alert ots admins if problem persists.)";
850 console.log(
"Initial request location: \n" + callerLocation);
851 Debug.log(
"Error: " + errStr,
854 requestURL.indexOf(
"TooltipRequest?") >= 0)?
856 Debug.HIGH_PRIORITY);
862 if(returnHandler && (errStr==
"" || callHandlerOnErr))
864 returnHandler(req, reqParam, errStr);
884 if(!DesktopContent._cookieCodeMailbox)
885 DesktopContent._cookieCodeMailbox = document.getElementById(
"DesktopContent-cookieCodeMailbox");
886 var cc = DesktopContent._cookieCodeMailbox?DesktopContent._cookieCodeMailbox.innerHTML:
"";
887 data =
"CookieCode="+cc+((data===undefined)?
"":(
"&"+data));
891 data =
"sequence="+sequence+
"&"+((data===undefined)?
"":(
"&"+data));
895 var urn = DesktopContent._localUrnLid;
896 var origin = DesktopContent._localOrigin;
898 if(!urn || targetSupervisor)
900 urn = DesktopContent._serverUrnLid;
901 origin = DesktopContent._serverOrigin;
905 if(!doNotShowLoadingOverlay)
906 DesktopContent.showLoading();
909 requestURL = origin+
"/urn:xdaq-application:lid="+urn+
"/"+requestURL;
911 req.open(
"POST",requestURL,
true);
912 req.setRequestHeader(
"Content-Type",
"text/plain;charset=UTF-8");
917 DesktopContent.checkCookieCodeRace =
function() {
919 if(parseInt(DesktopContent._updateTimeMailbox.innerHTML) < DesktopContent._lastCookieTime)
921 Debug.log(
"Cookie race occured!");
923 DesktopContent._updateTimeMailbox.innerHTML = DesktopContent._lastCookieTime;
924 DesktopContent._cookieCodeMailbox.innerHTML = DesktopContent._lastCookieCode;
930 DesktopContent.getXMLRequestErrors =
function(req) {
932 if(!req || !req.responseXML)
933 return [
"Unknown error occured " +
934 "(XML response may have been illegal)!"];
936 var errNodes = DesktopContent.getXMLChildren(req,
"Error");
938 for(var i=0;i<errNodes.length;++i)
939 errArr.push(errNodes[i].getAttribute(
"value"));
945 DesktopContent.getXMLAttributeValue =
function(req, name, attribute) {
947 if(el = DesktopContent.getXMLNode(req,name))
948 return el.getAttribute(attribute);
949 else if(name ==
"Error" &&
950 (!req || !req.responseXML))
951 return "Unknown error occured " +
952 "(XML response may have been illegal)!";
960 DesktopContent.getXMLValue =
function(req, name) {
962 return req.getAttribute(
"value");
963 return DesktopContent.getXMLAttributeValue(req,name,
"value");
969 DesktopContent.getXMLChildren =
function(req, nodeName) {
971 if(req && req.responseXML)
972 req = req.responseXML;
973 return req.getElementsByTagName(nodeName);
980 DesktopContent.getXMLNode =
function(req, name) {
982 if(req && req.responseXML)
983 req = req.responseXML;
988 els = req.getElementsByTagName(name);
1011 DesktopContent.getXMLDataNode =
function(req, name) {
1012 return DesktopContent.getXMLNode(
"DATA");
1024 DesktopContent.tooltipConditionString =
function(str) {
1025 return str.replace(/<INDENT>/g,
1026 "<div style='margin-left:60px;'>").replace(/<\/INDENT>/g,
1030 DesktopContent.tooltip =
function(id,tip) {
1032 if(typeof Desktop !==
'undefined')
1034 DesktopContent._serverUrnLid = urnLid;
1035 DesktopContent._serverOrigin =
"";
1037 DesktopContent._sequence = DesktopContent.getDesktopParameter(0,
"code");
1038 if(!DesktopContent._sequence || DesktopContent._sequence ==
"")
1039 DesktopContent._sequence = 0;
1041 Debug.log(
"In Wizard Mode with Sequence=" + DesktopContent._sequence);
1045 var srcStackString,srcFunc,srcFile;
1047 if(Debug.BROWSER_TYPE == 1)
1049 srcStackString = (
new Error).stack.split(
"\n")[2];
1050 srcFunc = srcStackString.trim().split(
' ')[1];
1052 else if(Debug.BROWSER_TYPE == 2)
1054 srcStackString = (
new Error).stack.split(
"\n")[1];
1055 srcFunc = srcStackString.trim().split(
'@')[0];
1058 srcFile = srcStackString.substr(srcStackString.lastIndexOf(
'/')+1);
1059 if(srcFile.indexOf(
'?') >= 0)
1060 srcFile = srcFile.substr(0,srcFile.indexOf(
'?'));
1061 if(srcFile.indexOf(
':') >= 0)
1062 srcFile.substr(0,srcFile.indexOf(
':'));
1065 if(tip === undefined)
1067 Debug.log(
"Undefined tooltip string at " + srcStackString +
"\n" +
1068 srcFunc +
"\n" + srcFile +
".\n\n Tooltip Usage: <id> <tip>", Debug.HIGH_PRIORITY);
1076 for(var i=0;i<oldId.length;++i)
1077 if((oldId[i] >=
'a' && oldId[i] <=
'z') ||
1078 (oldId[i] >=
'A' && oldId[i] <=
'Z') ||
1079 (oldId[i] >=
'0' && oldId[i] <=
'9'))
1082 DesktopContent.XMLHttpRequest(
1083 "TooltipRequest?RequestType=check" +
1084 "&srcFunc=" + srcFunc +
1085 "&srcFile=" + srcFile +
1090 var showTooltip = DesktopContent.getXMLValue(req,
"ShowTooltip");
1100 str +=
"<input type='checkbox' " +
1101 "id='DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
1104 "DesktopContent.tooltipSetAlwaysShow(\"" +
1107 id +
"\", this.checked);" +
"'>";
1109 str +=
"<a onclick='" +
1110 "var el = document.getElementById(\"" +
1111 "DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
1113 "el.checked = !el.checked;" +
1114 "DesktopContent.tooltipSetAlwaysShow(\"" +
1117 id +
"\", el.checked);" +
1119 str +=
"Never show the Tooltip below, or...";
1125 str +=
"<input type='checkbox' " +
1126 "id='DesktopContent-tooltip-SetNeverShowCheckbox-hour-" +
1129 "DesktopContent.tooltipSetAlwaysShow(\"" +
1132 id +
"\", 0 /*neverShow*/, this.checked);" +
"'>";
1134 str +=
"<a onclick='" +
1135 "var el = document.getElementById(\"" +
1136 "DesktopContent-tooltip-SetNeverShowCheckbox-hour-" +
1138 "el.checked = !el.checked;" +
1139 "DesktopContent.tooltipSetAlwaysShow(\"" +
1142 id +
"\", 0 /*neverShow*/, el.checked);" +
1144 str +=
"Silence this Tooltip for a week (can be reset in Settings):";
1153 str +=
"<center><b>'" + oldId +
"' Tooltip</b></center><br>";
1158 str += DesktopContent.tooltipConditionString(tip);
1165 str +=
"<input type='checkbox' " +
1166 "id='DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
1169 "DesktopContent.tooltipSetAlwaysShow(\"" +
1172 id +
"\", this.checked);" +
"'>";
1174 str +=
"<a onclick='" +
1175 "var el = document.getElementById(\"" +
1176 "DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
1178 "el.checked = !el.checked;" +
1179 "DesktopContent.tooltipSetAlwaysShow(\"" +
1182 id +
"\", el.checked);" +
1184 str +=
"Never show the Tooltip above.";
1189 Debug.log(
"srcStackString " + srcStackString);
1190 Debug.log(str,Debug.TIP_PRIORITY);
1197 DesktopContent.setWindowTooltip =
function(tip)
1199 var windowTooltipElement = document.createElement(
"div");
1200 windowTooltipElement.setAttribute(
"id",
"otsDesktopWindowTooltipElement");
1201 windowTooltipElement.setAttribute(
"style",
"display:none");
1203 windowTooltipElement.innerText = encodeURIComponent(tip);
1204 document.body.appendChild(windowTooltipElement);
1210 DesktopContent.setSecurityOn =
function(on) {
1211 console.log(
"Reached");
1212 DesktopContent.XMLHttpRequest(
1213 "ToggleSecurityCodeGeneration?RequestType=TurnGenerationOn" +
1216 ,DesktopContent.toggleSecurityCodeGenerationHandler
1222 DesktopContent.toggleSecurityCodeGenerationHandler =
function(req) {
1223 var status = DesktopContent.getXMLValue(req,
"Status");
1224 Debug.log(
"Status: " + status);
1225 if (status ==
"Generation_Success") {
1226 Debug.log(
"Successfully switched to using authentication sequence!");
1227 Debug.closeErrorPop();
1228 Debug.log(
"If you wish to return to the default security generation, you can use the 'Reset User Information' in the " +
1229 "'Edit User Data' app.");
1230 Debug.log(
"Plase refer to the console for the new link!", Debug.INFO_PRIORITY);
1237 DesktopContent.tooltipSetAlwaysShow =
function(srcFunc,srcFile,id,neverShow,temporarySilence) {
1238 Debug.log(
"neverShow = " + neverShow +
" tempSilence = " + temporarySilence);
1240 if(temporarySilence)
1242 DesktopContent.XMLHttpRequest(
1243 "TooltipRequest?RequestType=setNeverShow" +
1244 "&srcFunc=" + srcFunc +
1245 "&srcFile=" + srcFile +
1247 "&doNeverShow=" + (neverShow?1:0) +
1248 "&temporarySilence=" + (temporarySilence?1:0)
1250 ,0,0,0,0,
true,
true);
1252 if(temporarySilence)
return;
1255 document.getElementById(
"DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
1256 id).checked = neverShow;
1257 document.getElementById(
"DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
1258 id).checked = neverShow;
1269 DesktopContent.popUpVerification =
function(prompt, func, val, bgColor, textColor, borderColor, getUserInput,
1270 dialogWidth, cancelFunc, yesButtonText) {
1279 if(DesktopContent._verifyPopUp)
1280 DesktopContent._verifyPopUp.parentNode.removeChild(DesktopContent._verifyPopUp);
1283 if(val != undefined)
1284 prompt = prompt.replace(/REPLACE/g, val);
1291 if(!bgColor) bgColor =
"rgb(255,241,189)";
1292 if(!textColor) textColor =
"black";
1293 if(!borderColor) borderColor =
"black";
1294 if(!dialogWidth) dialogWidth = 200;
1299 css +=
"#" + DesktopContent._verifyPopUpId +
" " +
1300 "{position: absolute; z-index: 2000; border-radius: 5px; padding: 10px;" +
1301 "background-color: " + bgColor +
"; border: 2px solid " + borderColor +
";" +
1302 "color: " + textColor +
";text-align: center; overflow: auto;" +
1305 css +=
"#" + DesktopContent._verifyPopUpId +
"-text " +
1307 "color: " + textColor +
";width: " + dialogWidth +
"px; padding-bottom: 10px;" +
1310 css +=
"#" + DesktopContent._verifyPopUpId +
" *" +
1312 "color: " + textColor +
";" +
1316 var style = document.createElement(
'style');
1318 if (style.styleSheet) {
1319 style.styleSheet.cssText = css;
1321 style.appendChild(document.createTextNode(css));
1324 document.getElementsByTagName(
'head')[0].appendChild(style);
1327 var body = document.getElementsByTagName(
"BODY")[0];
1329 var el = document.createElement(
"div");
1330 el.setAttribute(
"id", DesktopContent._verifyPopUpId);
1332 var userInputStr =
"";
1335 "<input type='text' id='DesktopContent_popUpUserInput' " +
1336 "onclick='event.stopPropagation(); '" +
1339 var str =
"<div id='" + DesktopContent._verifyPopUpId +
"-text'>" +
1340 prompt +
"<br>" + userInputStr +
"</div>" +
1341 "<input type='submit' value='" +
1342 (yesButtonText?yesButtonText:
"Yes") +
1344 "onclick='event.stopPropagation();' " +
1346 " " +
1347 "<input type='submit' " +
1348 "onclick='event.stopPropagation();' " +
1353 el.getElementsByTagName(
'input')[0 + (getUserInput?1:0)].onmouseup =
1354 function(event){
event.stopPropagation(); DesktopContent.clearPopUpVerification(func);};
1356 el.getElementsByTagName(
'input')[1 + (getUserInput?1:0)].onmouseup =
1357 function(event){
event.stopPropagation(); DesktopContent.clearPopUpVerification(cancelFunc);};
1361 DesktopContent._verifyPopUp = el;
1362 el.style.left =
"-1000px";
1363 body.appendChild(el);
1368 el.getElementsByTagName(
'input')[0].focus();
1369 el.getElementsByTagName(
'input')[0].setSelectionRange(0,0);
1372 el.getElementsByTagName(
'input')[0].onkeydown =
1375 if(event.keyCode == 13)
1377 Debug.log(
"Accepting enter key");
1378 event.preventDefault();
1379 event.stopPropagation();
1380 DesktopContent.clearPopUpVerification(func);
1382 else if(event.keyCode == 27)
1384 Debug.log(
"Accepting escape key");
1385 event.preventDefault();
1386 event.stopPropagation();
1387 DesktopContent.clearPopUpVerification(cancelFunc);
1392 el.getElementsByTagName(
'input')[0].focus();
1398 if(event.keyCode == 13)
1400 Debug.log(
"Accepting enter key");
1401 event.preventDefault();
1402 event.stopPropagation();
1403 DesktopContent.clearPopUpVerification(func);
1405 else if(event.keyCode == 27)
1407 Debug.log(
"Accepting escape key");
1408 event.preventDefault();
1409 event.stopPropagation();
1410 DesktopContent.clearPopUpVerification(cancelFunc);
1415 var w = el.offsetWidth;
1416 var h = el.offsetHeight;
1417 var x = DesktopContent.getMouseX();
1418 var y = DesktopContent.getMouseY();
1420 Debug.log(
"X: " + x +
1425 while(x+w > DesktopContent.getWindowWidth())
1427 if(y > DesktopContent.getWindowHeight()/2 + h/2)
1429 while(y+h > DesktopContent.getWindowHeight())
1435 Debug.log(
"X: " + x +
1440 el.style.left = (DesktopContent.getWindowScrollLeft() + x) +
"px";
1441 el.style.top = (DesktopContent.getWindowScrollTop() + y) +
"px";
1446 DesktopContent.clearPopUpVerification =
function(func) {
1450 var userEl = document.getElementById(
"DesktopContent_popUpUserInput");
1451 var param = userEl?userEl.value:undefined;
1454 if(DesktopContent._verifyPopUp) DesktopContent._verifyPopUp.parentNode.removeChild(DesktopContent._verifyPopUp);
1455 DesktopContent._verifyPopUp = 0;
1478 DesktopContent.setPopUpPosition =
function(el,w,h,padding,border,
1479 margin,doNotResize,offsetUp) {
1481 Debug.log(
"DesktopContent.setPopUpPosition");
1483 if(padding === undefined) padding = 10;
1484 if(border === undefined) border = 1;
1485 if(margin === undefined) margin = 0;
1492 DesktopContent.setPopUpPosition.stopPropagation =
function(event) {
1494 event.stopPropagation();
1500 DesktopContent.setPopUpPosition.popupResize =
function() {
1506 window.removeEventListener(
"resize",DesktopContent.setPopUpPosition.popupResize);
1507 window.removeEventListener(
"scroll",DesktopContent.setPopUpPosition.popupResize);
1511 catch(err) {
return;}
1517 var ww = DesktopContent.getWindowWidth()-(padding+border)*2;
1518 var wh = DesktopContent.getWindowHeight()-(padding+border)*2;
1522 var ah = el.offsetHeight;
1524 if(w === undefined || h === undefined)
1526 w = ww - (margin)*2;
1527 h = wh - (margin)*2;
1531 x = (DesktopContent.getWindowScrollLeft() + ((ww-w)/2));
1532 y = (DesktopContent.getWindowScrollTop() + ((wh-h)/2)) - (offsetUp|0) - 100;
1534 if(y < DesktopContent.getWindowScrollTop() +
1536 y = DesktopContent.getWindowScrollTop() + margin +
1540 if(w > ww-margin-padding)
1541 x = -DesktopContent.getWindowScrollLeft();
1542 if(ah > wh-margin-padding)
1543 y = -DesktopContent.getWindowScrollTop();
1545 el.style.left = x +
"px";
1546 el.style.top = y +
"px";
1548 DesktopContent.setPopUpPosition.popupResize();
1551 el.style.width = w +
"px";
1552 el.style.height = h +
"px";
1564 el.style.position =
"absolute";
1565 el.style.zIndex =
"10000";
1566 el.style.border =
"1px solid #770000";
1567 el.style.backgroundColor =
"#efeaea";
1568 el.style.textAlign =
"center";
1569 el.style.padding =
"10px";
1570 el.style.color =
"black";
1574 window.addEventListener(
"resize",DesktopContent.setPopUpPosition.popupResize);
1575 window.addEventListener(
"scroll",DesktopContent.setPopUpPosition.popupResize);
1577 el.addEventListener(
"keydown",DesktopContent.setPopUpPosition.stopPropagation);
1578 el.addEventListener(
"mousemove",DesktopContent.setPopUpPosition.stopPropagation);
1579 el.addEventListener(
"mousemove",DesktopContent.mouseMove);
1581 el.style.overflow =
"auto";
1583 return {
"w" : w,
"h" : h,
"x" : x,
"y" : y};
1589 DesktopContent.parseColor =
function(colorStr) {
1593 var m = colorStr.split(
"(")[1].split(
")")[0].split(
",");
1594 if( m)
return "rgb("+m[0]+
","+m[1]+
","+m[2]+
")";
1595 else throw new Error(
"Color "+colorStr+
" could not be parsed.");
1602 DesktopContent.getColorAsRGBA =
function(colorStr) {
1605 var div = document.createElement(
'div');
1608 div.style.color = colorStr;
1609 div.style.display =
"none";
1610 document.body.appendChild(div);
1612 m = getComputedStyle(div).color.split(
"(")[1].split(
")")[0].split(
",");
1614 document.body.removeChild(div);
1616 if(m && m.length == 3)
return "rgba("+m[0]+
","+m[1]+
","+m[2]+
",255)";
1617 else if(m && m.length == 4)
return "rgba("+m[0]+
","+m[1]+
","+m[2]+
","+m[3]+
")";
1618 else throw new Error(
"Color "+colorStr+
" could not be parsed.");
1624 DesktopContent.getWindowWidth =
function() {
return window.innerWidth; }
1625 DesktopContent.getWindowHeight =
function() {
return window.innerHeight; }
1626 DesktopContent.getBodyWidth =
function() {
return document.body.offsetWidth; }
1627 DesktopContent.getBodyHeight =
function() {
return document.body.offsetHeight; }
1628 DesktopContent.getWindowScrollLeft =
function() {
return document.documentElement.scrollLeft || document.body.scrollLeft || 0; }
1629 DesktopContent.getWindowScrollTop =
function() {
return document.documentElement.scrollTop || document.body.scrollTop || 0; }
1630 DesktopContent.getMouseX =
function() {
return DesktopContent._windowMouseX | 0; }
1631 DesktopContent.getMouseY =
function() {
return DesktopContent._windowMouseY | 0; }
1632 DesktopContent.getDefaultWindowColor =
function() {
1634 if(!DesktopContent._windowColorPostbox || !DesktopContent._desktopColor)
1637 Debug.log(
"Color post boxes not setup! So giving default.",Debug.MED_PRIORITY);
1638 return "rgb(178,210,240)";
1641 wrgba = DesktopContent._windowColorPostbox.innerHTML.split(
"(")[1].split(
")")[0].split(
",");
1642 drgb = DesktopContent._desktopColor.split(
"(")[1].split(
")")[0].split(
",");
1644 drgb[i] = (drgb[i]*(1-wrgba[3]) + wrgba[i]*wrgba[3])|0;
1645 return "rgb("+drgb[0]+
","+drgb[1]+
","+drgb[2]+
")";
1650 DesktopContent.getDefaultDashboardColor =
function() {
return DesktopContent.parseColor(DesktopContent._dashboardColorPostbox.innerHTML); }
1651 DesktopContent.getDefaultDesktopColor =
function() {
1652 if(!DesktopContent._desktopColor)
1655 Debug.log(
"Color post boxes not setup! So giving default.",Debug.MED_PRIORITY);
1656 return "rgb(15,34,105)";
1658 return DesktopContent._desktopColor;
1663 DesktopContent.getUsername =
function() {
1664 var dispName = DesktopContent._theWindow.parent.document.getElementById(
"DesktopDashboard-user-displayName").innerHTML
1665 return dispName.substr(dispName.indexOf(
",")+2);
1673 DesktopContent.openNewWindow =
function(name,subname,windowPath,unique,completeHandler) {
1675 Debug.log(
"DesktopContent.openNewWindow= " + windowPath);
1676 Debug.log(
"name= " + name);
1677 Debug.log(
"subname= " + subname);
1678 Debug.log(
"unique= " + unique);
1682 var paramsStr = DesktopContent._openWindowMailbox.innerHTML;
1685 var tryAgainCount = 0;
1690 Debug.log(
"Window creation is busy, trying again soon!");
1694 if(tryAgainCount > 50)
1696 Debug.log(
"It looks like the window failed to open. Perhaps the Desktop is disconnected from the server; " +
1697 "please reconnect and try again.", Debug.WARN_PRIORITY);
1701 setTimeout(
function(){ DesktopContent.openNewWindow(windowPath); }, 100);
1706 var str =
"requestingWindowId=" + DesktopContent._myDesktopFrame.id.split(
'-')[1];
1707 str +=
"&windowName=" + name;
1708 str +=
"&windowSubname=" + subname;
1709 str +=
"&windowUnique=" + unique;
1710 str +=
"&windowPath=" + windowPath;
1711 DesktopContent._openWindowMailbox.innerHTML = str;
1713 Debug.log(
"Waiting for complete...");
1716 var timeoutHandler =
function() {
1717 Debug.log(
"Checking for complete...");
1721 if(tryAgainCount > 50)
1723 Debug.log(
"It looks like the window failed to open. Perhaps the Desktop is disconnected from the server; " +
1724 "please reconnect and try again.", Debug.WARN_PRIORITY);
1730 var paramsStr = DesktopContent._openWindowMailbox.innerHTML;
1731 var spliti = paramsStr.indexOf(
'&');
1732 params = [paramsStr.substr(0,spliti),paramsStr.substr(spliti+5)];
1734 var requestingWindowId =
"", done =
"";
1735 for(var i=0;i<params.length;++i)
1737 spliti = params[i].indexOf(
'=');
1738 varPair = [params[i].substr(0,spliti),params[i].substr(spliti+1)];
1739 if(varPair[0] ==
"requestingWindowId")
1740 requestingWindowId = varPair[1];
1741 else if(varPair[0] ==
"done")
1745 if(paramsStr =
"" || (requestingWindowId !=
"" && done !=
""))
1748 Debug.log(
"requestingWindowId=" + requestingWindowId);
1749 Debug.log(
"done=" + done);
1750 if(requestingWindowId != DesktopContent._myDesktopFrame.id.split(
'-')[1])
1751 Debug.log(
"There was a mismatch in window id!",Debug.MED_PRIORITY);
1754 DesktopContent._openWindowMailbox.innerHTML =
"";
1761 setTimeout(timeoutHandler, 100);
1765 setTimeout(timeoutHandler,
1777 DesktopContent.openNewBrowserTab =
function(name,subname,windowPath,unique) {
1779 if(windowPath !== undefined)
1782 if(windowPath[0] ==
'?')
1783 windowPath = windowPath.substr(1);
1789 var i = windowPath.indexOf(
"urn:xdaq-application:lid=") + (
"urn:xdaq-application:lid=").length;
1790 var isAllNumbers =
true;
1791 for(i;i<windowPath.length;++i)
1795 if(windowPath[i] <
"0" || windowPath[i] >
"9")
1797 isAllNumbers =
false;
1806 Debug.log(
"An error occurred while trying to open the window. " +
1807 "The window path seems to be invalid: " + e, Debug.HIGH_PRIORITY);
1811 Debug.log(
"DesktopWindow= " + windowPath);
1813 Debug.log(
"name= " + name);
1814 Debug.log(
"subname= " + subname);
1815 Debug.log(
"unique= " + unique);
1817 var search = DesktopContent._theWindow.parent.parent.window.location.search;
1818 url = DesktopContent._theWindow.parent.parent.window.location.pathname;
1820 var str =
"requestingWindowId=" + DesktopContent._myDesktopFrame.id.split(
'-')[1];
1821 str +=
"&windowName=" + name;
1822 str +=
"&windowSubname=" + subname;
1823 str +=
"&windowUnique=" + unique;
1824 str +=
"&windowPath=" + windowPath;
1831 var i = url.indexOf(
"urn:xdaq-application:lid=") + (
"urn:xdaq-application:lid=").length;
1832 var isAllNumbers =
true;
1833 for(i;i<url.length;++i)
1837 if(url[i] <
"0" || url[i] >
"9")
1839 isAllNumbers =
false;
1850 var i = search.indexOf(
"requestingWindowId");
1852 search = search.substr(0,i);
1854 if(search.length && search[search.length-1] !=
'?'
1855 && search[search.length-1] !=
'&')
1857 url += search + str;
1860 Debug.log(
"DesktopContent.openNewBrowserTab= " + url);
1862 window.open(url,
'_blank');
1871 DesktopContent.addDesktopIcon =
function(caption, altText,
1872 folderPath, unique, permissionString,
1873 imageURL, windowContentURL, linkedApp, parameters) {
1875 var iconParameters =
"";
1876 if(parameters && parameters.length && (typeof parameters ===
"string"))
1877 iconParameters = parameters;
1879 for(var i in parametersObject)
1881 iconParameters += encodeURIComponent(i) +
"=" +
1882 encodeURIComponent(iconParameters[i]) +
"&";
1885 Debug.log(
"iconParameters = " + iconParameters);
1887 var iconLinkedApp =
"";
1888 var iconLinkedAppLID = 0;
1891 if((linkedApp|0) > 0)
1892 iconLinkedAppLID = linkedApp|0;
1894 iconLinkedApp = linkedApp;
1897 var req =
"Request?RequestType=addDesktopIcon"
1899 +
"&iconCaption=" + encodeURIComponent(caption)
1900 +
"&iconAltText=" + encodeURIComponent(altText)
1901 +
"&iconFolderPath=" + encodeURIComponent(folderPath)
1902 +
"&iconPermissions=" + encodeURIComponent(permissionString)
1903 +
"&iconImageURL=" + encodeURIComponent(imageURL)
1904 +
"&iconWindowURL=" + encodeURIComponent(windowContentURL)
1905 +
"&iconEnforceOneWindowInstance=" + (unique?
"1":
"0")
1906 + (iconLinkedAppLID?
1907 (
"&iconLinkedAppLID=" + iconLinkedAppLID):
1908 (
"&iconLinkedApp=" + iconLinkedApp)
1911 Debug.log(
"Create Icon req = " + req);
1913 DesktopContent.XMLHttpRequest(req,
1915 "iconParameters=" + encodeURIComponent(iconParameters)
1919 Debug.log(
"Successfully added icon '" +
1921 "!'",Debug.INFO_PRIORITY);
1924 if(activateSystemConfigHandler)
1926 activateSystemConfigHandler(req);
1938 DesktopContent.getDesktopWindowTitle =
function() {
1939 return DesktopContent._theWindow.parent.document.getElementById(
1940 "DesktopWindowHeader-" +
1941 DesktopContent._theWindow.name.split(
'-')[1]).innerHTML;