112 var DesktopContent = DesktopContent || {};
114 if (typeof Debug ==
'undefined')
115 alert(
'ERROR: Debug is undefined! Must include Debug.js before DesktopWindowContentCode.js');
116 if (typeof Globals ==
'undefined')
117 alert(
'ERROR: Globals is undefined! Must include Globals.js before DesktopWindowContentCode.js');
164 DesktopContent._isFocused =
false;
165 DesktopContent._theWindow = 0;
166 DesktopContent._myDesktopFrame = 0;
167 DesktopContent._zMailbox = 0;
168 DesktopContent._mouseOverXmailbox = 0;
169 DesktopContent._mouseOverYmailbox = 0;
170 DesktopContent._windowMouseX = -1;
171 DesktopContent._windowMouseY = -1;
173 DesktopContent._serverOrigin =
"";
174 DesktopContent._localOrigin =
"";
175 DesktopContent._serverUrnLid = 0;
176 DesktopContent._localUrnLid = 0;
178 DesktopContent._cookieCodeMailbox = 0;
179 DesktopContent._updateTimeMailbox = 0;
180 DesktopContent._needToLoginMailbox = 0;
181 DesktopContent._openWindowMailbox = 0;
182 DesktopContent._blockSystemCheckMailbox = 0;
184 DesktopContent._lastCookieCode = 0;
185 DesktopContent._lastCookieTime = 0;
188 DesktopContent._verifyPopUp = 0;
189 DesktopContent._verifyPopUpId =
"DesktopContent-verifyPopUp";
191 DesktopContent._windowColorPostbox = 0;
192 DesktopContent._dashboardColorPostbox = 0;
193 DesktopContent._desktopColor = 0;
195 DesktopContent._sequence = 0;
197 DesktopContent._mouseMoveSubscribers = [];
205 DesktopContent.init =
function() {
207 if(typeof Desktop !==
'undefined')
return;
210 DesktopContent._theWindow =
self;
211 while(tmpCnt++ < 5 && DesktopContent._theWindow &&
212 DesktopContent._theWindow.window.name.search(
"DesktopWindowFrame") < 0)
213 DesktopContent._theWindow = DesktopContent._theWindow.parent;
214 DesktopContent._theWindow = DesktopContent._theWindow.window;
216 DesktopContent._myDesktopFrame = DesktopContent._theWindow.parent.document.getElementById(DesktopContent._theWindow.name);
217 DesktopContent._zMailbox = DesktopContent._theWindow.parent.document.getElementById(
"Desktop-windowZmailbox");
218 DesktopContent._mouseOverXmailbox = DesktopContent._theWindow.parent.document.getElementById(
"Desktop-mouseOverXmailbox");
219 DesktopContent._mouseOverYmailbox = DesktopContent._theWindow.parent.document.getElementById(
"Desktop-mouseOverYmailbox");
221 DesktopContent._cookieCodeMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-cookieCodeMailbox");
222 DesktopContent._updateTimeMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-updateTimeMailbox");
223 DesktopContent._needToLoginMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-needToLoginMailbox");
224 DesktopContent._openWindowMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-openWindowMailbox");
225 DesktopContent._blockSystemCheckMailbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-blockSystemCheckMailbox");
227 DesktopContent._windowColorPostbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-windowColorPostbox");
228 DesktopContent._dashboardColorPostbox = DesktopContent._theWindow.parent.document.getElementById(
"DesktopContent-dashboardColorPostbox");
230 if(DesktopContent._theWindow.parent.document.body)
231 DesktopContent._desktopColor = DesktopContent._theWindow.parent.document.body.style.backgroundColor;
233 window.onfocus = DesktopContent.handleFocus;
234 window.onmousedown = DesktopContent.handleFocus;
235 window.onscroll = DesktopContent.handleScroll;
236 window.onblur = DesktopContent.handleBlur;
237 window.onmousemove = DesktopContent.mouseMove;
240 DesktopContent._serverUrnLid = DesktopContent.getDesktopWindowParameter(0,
"urn");
241 if(typeof DesktopContent._serverUrnLid ==
'undefined')
242 Debug.log(
"ERROR -- Supervisor Application URN-LID not found",Debug.HIGH_PRIORITY);
243 Debug.log(
"Supervisor Application URN-LID #" + DesktopContent._serverUrnLid);
244 DesktopContent._serverOrigin = DesktopContent._theWindow.parent.window.location.origin;
245 Debug.log(
"Supervisor Application Origin = " + DesktopContent._serverOrigin);
247 DesktopContent._localUrnLid = DesktopContent.getParameter(0,
"urn");
248 if(typeof DesktopContent._localUrnLid ==
'undefined')
249 DesktopContent._localUrnLid = 0;
250 Debug.log(
"Local Application URN-LID #" + DesktopContent._localUrnLid);
251 DesktopContent._localOrigin = window.location.origin;
252 Debug.log(
"Local Application Origin = " + DesktopContent._localOrigin);
255 DesktopContent._sequence = DesktopContent.getDesktopParameter(0,
"code");
256 if(!DesktopContent._sequence || DesktopContent._sequence ==
"")
257 DesktopContent._sequence = 0;
259 Debug.log(
"In Wizard Mode with Sequence=" + DesktopContent._sequence);
266 DesktopContent.getParameter =
function(index,name) {
268 var params = (window.location.search.substr(1)).split(
'&');
273 for(index=0;index<params.length;++index)
275 spliti = params[index].indexOf(
'=');
276 if(spliti < 0)
continue;
277 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
278 if(decodeURIComponent(vs[0]) == name)
279 return decodeURIComponent(vs[1]);
285 if(index >= params.length)
return;
287 spliti = params[index].indexOf(
'=');
288 if(spliti < 0)
return;
289 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
290 return decodeURIComponent(vs[1]);
296 DesktopContent.getDesktopParameter =
function(index, name) {
299 var win = DesktopContent._theWindow;
301 win = window.parent.window;
303 win = win.parent.parent.window;
304 var params = (win.location.search.substr(1)).split(
'&');
305 if(index >= params.length)
return;
310 for(var index=0;index<params.length;++index)
312 spliti = params[index].indexOf(
'=');
313 if(spliti < 0)
continue;
314 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
316 return decodeURIComponent(vs[1]);
321 spliti = params[index].indexOf(
'=');
322 if(spliti < 0)
return;
323 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
324 return decodeURIComponent(vs[1]);
330 DesktopContent.getDesktopWindowParameter =
function(index, name) {
333 var win = DesktopContent._theWindow;
337 win = win.parent.window;
340 var searchStr = win.location.search.substr(1);
341 var i = searchStr.indexOf(
"=securityType");
342 if(i > 0) searchStr = searchStr.substr(0,i) +
'&' + searchStr.substr(i+1);
344 var params = ((searchStr)).split(
'&');
345 if(index >= params.length)
return;
350 for(var index=0;index<params.length;++index)
352 spliti = params[index].indexOf(
'=');
353 if(spliti < 0)
continue;
354 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
356 return decodeURIComponent(vs[1]);
361 spliti = params[index].indexOf(
'=');
362 if(spliti < 0)
return;
363 vs = [params[index].substr(0,spliti),params[index].substr(spliti+1)];
364 return decodeURIComponent(vs[1]);
368 DesktopContent.handleFocus =
function(e) {
370 if(!DesktopContent._myDesktopFrame)
return;
374 DesktopContent._isFocused =
true;
375 DesktopContent._myDesktopFrame.parentNode.parentNode.style.zIndex = DesktopContent._zMailbox.innerHTML;
376 DesktopContent._zMailbox.innerHTML = parseInt(DesktopContent._zMailbox.innerHTML) + 1;
379 DesktopContent.handleBlur =
function(e) {
380 DesktopContent._isFocused =
false;
382 DesktopContent.handleScroll =
function(e) {
385 DesktopContent.mouseMove =
function(mouseEvent) {
387 for(var i=0; i<DesktopContent._mouseMoveSubscribers.length; ++i)
388 DesktopContent._mouseMoveSubscribers[i](mouseEvent);
390 if(!DesktopContent._myDesktopFrame)
return;
392 DesktopContent._windowMouseX = parseInt(mouseEvent.clientX);
393 DesktopContent._windowMouseY = parseInt(mouseEvent.clientY);
396 DesktopContent._mouseOverXmailbox.innerHTML = parseInt(DesktopContent._myDesktopFrame.parentNode.parentNode.offsetLeft) +
397 parseInt(DesktopContent._myDesktopFrame.offsetLeft) + DesktopContent._windowMouseX;
398 DesktopContent._mouseOverYmailbox.innerHTML = parseInt(DesktopContent._myDesktopFrame.parentNode.parentNode.offsetTop) +
399 parseInt(DesktopContent._myDesktopFrame.offsetTop) + DesktopContent._windowMouseY;
402 DesktopContent.mouseMoveSubscriber =
function(newHandler) {
403 DesktopContent._mouseMoveSubscribers.push(newHandler);
407 DesktopContent.init();
416 DesktopContent._arrayOfFailedHandlers =
new Array();
421 DesktopContent._loadBox = 0;
422 DesktopContent._loadBoxId =
"DesktopContent-load-box";
423 DesktopContent._loadBoxTimer = 0;
424 DesktopContent._loadBoxRequestStack = 0;
430 DesktopContent.showLoading =
function(nextFunction) {
435 window.setTimeout(
function()
438 DesktopContent.hideLoading();
446 Debug.log(
"DesktopContent.showLoading " + DesktopContent._loadBoxRequestStack);
448 if(DesktopContent._loadBoxRequestStack++)
452 if(!DesktopContent._loadBox)
455 var el = document.getElementById(DesktopContent._loadBoxId);
458 var body = document.getElementsByTagName(
"BODY")[0];
462 window.setTimeout(
function() { Debug.errorPop(err,severity)}, 1000);
467 el = document.createElement(
"div");
468 el.setAttribute(
"id", DesktopContent._loadBoxId);
469 el.style.display =
"none";
472 str +=
"<table height='100%' width='100%'><td id='" +
473 DesktopContent._loadBoxId +
"-td'>Loading...</td></table>";
475 body.appendChild(el);
483 css +=
"#" + DesktopContent._loadBoxId +
485 "position: absolute; display: none; border: 2px solid gray;" +
486 "background-color: rgba(0,0,0,0.8); overflow-y: auto;" +
487 "overflow-x: auto; padding: 5px; -moz-border-radius: 2px;" +
488 "-webkit-border-radius: 2px; border-radius: 2px;" +
489 "font-size: 18px; z-index: 2147483647;" +
491 "font-family: 'Comfortaa', arial; text-align: left;" +
492 "left: 8px; top: 8px; margin-right: 8px; height:400px; " +
494 css +=
"#" + DesktopContent._loadBoxId +
" table" +
496 "background-color: rgba(0,0,0,0.8);" +
509 var style = document.createElement(
'style');
511 if (style.styleSheet) {
512 style.styleSheet.cssText = css;
514 style.appendChild(document.createTextNode(css));
517 document.getElementsByTagName(
'head')[0].appendChild(style);
519 DesktopContent._loadBox = el;
529 if(typeof DesktopContent !=
'undefined')
531 WW = DesktopContent.getWindowWidth();
532 WH = DesktopContent.getWindowHeight();
534 else if(typeof Desktop !=
'undefined' && Desktop.desktop)
536 WW = DesktopContent.getDesktopWidth();
537 WH = DesktopContent.getDesktopHeight();
540 var X = DesktopContent.getWindowScrollLeft() + (WW - W - 4)/2;
541 var Y = DesktopContent.getWindowScrollTop() + (WH - H -4)/2;
544 DesktopContent._loadBox.style.left = (X) +
"px";
545 DesktopContent._loadBox.style.top = (Y) +
"px";
546 DesktopContent._loadBox.style.width = (W) +
"px";
547 DesktopContent._loadBox.style.height = (H) +
"px";
549 DesktopContent._loadBox.style.display =
"block";
553 var loadBoxStr =
"..";
554 var el = document.getElementById(DesktopContent._loadBoxId +
"-td");
555 el.innerHTML =
"Loading" + loadBoxStr;
558 var loadBoxAnimationFunction =
function() {
559 if(loadBoxStr.length > 3) loadBoxStr =
"";
562 el.innerHTML =
"Loading" + loadBoxStr;
565 window.clearInterval(DesktopContent._loadBoxTimer);
566 DesktopContent._loadBoxTimer = window.setInterval(loadBoxAnimationFunction, 300);
570 DesktopContent._loadBoxHideTimer = 0;
571 DesktopContent.hideLoading =
function() {
592 window.setTimeout(localHideLoadBox, 300);
594 function localHideLoadBox()
596 if(--DesktopContent._loadBoxRequestStack)
599 window.clearInterval(DesktopContent._loadBoxTimer);
600 Debug.log(
"DesktopContent.hideLoading");
601 document.getElementById(DesktopContent._loadBoxId).style.display =
"none";
628 DesktopContent.XMLHttpRequest =
function(requestURL, data, returnHandler,
629 reqParam, progressHandler, callHandlerOnErr, doNotShowLoadingOverlay,
630 targetSupervisor, ignoreSystemBlock) {
633 var sequence = DesktopContent._sequence;
637 var callerLocation =
"";
640 callerLocation = (
new Error).stack.split(
"\n")[2];
641 var tmpCallerLocation = callerLocation.slice(0,callerLocation.indexOf(
' ('));
642 callerLocation = callerLocation.slice(tmpCallerLocation.length+2,
643 callerLocation.length-1);
648 if((!ignoreSystemBlock && DesktopContent._blockSystemCheckMailbox &&
649 DesktopContent._blockSystemCheckMailbox.innerHTML !=
"") ||
650 (DesktopContent._needToLoginMailbox &&
651 DesktopContent._needToLoginMailbox.innerHTML ==
"1"))
655 errStr =
"The system appears to be down.";
656 errStr +=
" (Try reconnecting/reloading the page, or alert ots admins if problem persists.)";
657 Debug.log(
"Error: " + errStr,Debug.HIGH_PRIORITY);
660 if(DesktopContent._arrayOfFailedHandlers.length < 2)
662 for(var rh in DesktopContent._arrayOfFailedHandlers)
663 if(DesktopContent._arrayOfFailedHandlers[rh] == returnHandler)
665 errStr =
"Blocking multiple error responses to same handler. \nRecurring error should be handled by returnHandler: " + returnHandler;
666 Debug.log(errStr.substr(0,200) +
"...",Debug.HIGH_PRIORITY);
672 errStr =
"Quiet Mode. Blocking multiple error responses to ALL handlers. \nRecurring error should be handled by returnHandler:" + returnHandler;
673 Debug.log(errStr.substr(0,200) +
"...",Debug.HIGH_PRIORITY);
677 if(!found) DesktopContent._arrayOfFailedHandlers.push(returnHandler);
680 if(returnHandler && !found && callHandlerOnErr) returnHandler(req, reqParam, errStr);
684 req =
new XMLHttpRequest();
686 if(progressHandler) req.upload.addEventListener(
"progress", progressHandler,
false);
690 var timeoutFunction =
function()
692 Debug.log(
"It has been 60 seconds.. still waiting for a response. " +
693 "Is there an infinite loop occuring at the server? " +
694 "Or is this just a really long request..",
695 Debug.HIGH_PRIORITY);
696 timeoutTimer = window.setTimeout(timeoutFunction, 60000);
698 timeoutTimer = window.setTimeout(timeoutFunction, 60000);
701 req.onreadystatechange =
function() {
703 if (req.readyState==4)
705 window.clearTimeout(timeoutTimer);
707 if(!doNotShowLoadingOverlay)
708 DesktopContent.hideLoading();
714 DesktopContent._lastCookieTime = parseInt((
new Date()).getTime());
717 if(req.responseText == Globals.REQ_NO_PERMISSION_RESPONSE)
719 errStr =
"Request failed do to insufficient account permissions.";
722 else if(req.responseText == Globals.REQ_USER_LOCKOUT_RESPONSE)
724 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.";
727 else if(req.responseText == Globals.REQ_NO_LOGIN_RESPONSE)
729 errStr =
"Login has expired.";
731 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
732 DesktopContent._blockSystemCheckMailbox.innerHTML ==
"")) &&
733 DesktopContent._needToLoginMailbox)
734 DesktopContent._needToLoginMailbox.innerHTML =
"1";
737 else if(req.responseText == Globals.REQ_LOCK_REQUIRED_RESPONSE)
739 errStr =
"Request failed because the request requires the user to lockout the system. Please take over the lock in the Settings area to proceed.";
746 errStr =
"Request response is invalid XML!";
752 DesktopContent._lastCookieCode = DesktopContent.getXMLValue(req,
'CookieCode');
753 if (typeof DesktopContent._lastCookieCode ==
'undefined')
755 errStr =
"Request Failed - Missing Cookie in Response.";
757 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
758 DesktopContent._blockSystemCheckMailbox.innerHTML ==
"")) &&
759 DesktopContent._needToLoginMailbox)
760 DesktopContent._needToLoginMailbox.innerHTML =
"1";
763 else if(DesktopContent._lastCookieCode !=
"AllowNoUser")
767 if(parseInt(DesktopContent._updateTimeMailbox.innerHTML) < DesktopContent._lastCookieTime)
769 DesktopContent._updateTimeMailbox.innerHTML = DesktopContent._lastCookieTime;
770 DesktopContent._cookieCodeMailbox.innerHTML = DesktopContent._lastCookieCode;
772 setTimeout(DesktopContent.checkCookieCodeRace, Math.random()*1000|0+500);
778 else if(req.status == 0)
782 errStr =
"Request was interrupted (Status=0). " +
783 "Likely this means the server crashed (or the desktop window making the request was closed), " +
784 " in the middle of a request. " +
785 "\n(It also could mean 'potential security risk' like a cross-domain request) ";
791 errStr =
"Request Failed (code: " + req.status +
") - Bad Address:\n" + requestURL;
793 if((ignoreSystemBlock || (DesktopContent._blockSystemCheckMailbox &&
794 DesktopContent._blockSystemCheckMailbox.innerHTML ==
"")) &&
795 DesktopContent._needToLoginMailbox)
796 DesktopContent._needToLoginMailbox.innerHTML =
"1";
800 if(DesktopContent._arrayOfFailedHandlers.length < 2)
802 for(var rh in DesktopContent._arrayOfFailedHandlers)
803 if(DesktopContent._arrayOfFailedHandlers[rh] == returnHandler)
805 errStr =
"Blocking multiple error responses to same handle. \nPoor error handling (Developer should fix) by returnHandler: " + returnHandler;
806 Debug.log(errStr.substr(0,200) +
"...",Debug.HIGH_PRIORITY);
812 errStr =
"Quiet Mode. Blocking multiple error responses to ALL handles. \nPoor error handling (Developer should fix) by returnHandler: " + returnHandler;
813 Debug.log(errStr.substr(0,200) +
"...",Debug.HIGH_PRIORITY);
817 if(!found) DesktopContent._arrayOfFailedHandlers.push(returnHandler);
822 var errArr = (callHandlerOnErr || !req.responseXML)?[]:DesktopContent.getXMLRequestErrors(req);
823 if(errArr.length && !callHandlerOnErr)
825 for(var i=0;i<errArr.length;++i)
827 errStr += (i?
"\n\n":
"") + errArr[i];
829 console.log(
"Initial request location: \n" + callerLocation);
830 Debug.log(
"Error: " + errArr[i],
831 (ignoreSystemBlock || requestURL.indexOf(
"TooltipRequest?") >= 0)?
833 Debug.HIGH_PRIORITY);
836 else if(errStr !=
"")
838 errStr +=
"\n\n(Try refreshing the page, or alert ots admins if problem persists.)";
840 console.log(
"Initial request location: \n" + callerLocation);
841 Debug.log(
"Error: " + errStr,
844 requestURL.indexOf(
"TooltipRequest?") >= 0)?
846 Debug.HIGH_PRIORITY);
852 if(returnHandler && (errStr==
"" || callHandlerOnErr))
854 returnHandler(req, reqParam, errStr);
874 if(!DesktopContent._cookieCodeMailbox)
875 DesktopContent._cookieCodeMailbox = document.getElementById(
"DesktopContent-cookieCodeMailbox");
876 var cc = DesktopContent._cookieCodeMailbox?DesktopContent._cookieCodeMailbox.innerHTML:
"";
877 data =
"CookieCode="+cc+((data===undefined)?
"":(
"&"+data));
881 data =
"sequence="+sequence+
"&"+((data===undefined)?
"":(
"&"+data));
885 var urn = DesktopContent._localUrnLid;
886 var origin = DesktopContent._localOrigin;
888 if(!urn || targetSupervisor)
890 urn = DesktopContent._serverUrnLid;
891 origin = DesktopContent._serverOrigin;
895 if(!doNotShowLoadingOverlay)
896 DesktopContent.showLoading();
899 requestURL = origin+
"/urn:xdaq-application:lid="+urn+
"/"+requestURL;
901 req.open(
"POST",requestURL,
true);
902 req.setRequestHeader(
"Content-Type",
"text/plain;charset=UTF-8");
907 DesktopContent.checkCookieCodeRace =
function() {
909 if(parseInt(DesktopContent._updateTimeMailbox.innerHTML) < DesktopContent._lastCookieTime)
911 Debug.log(
"Cookie race occured!");
913 DesktopContent._updateTimeMailbox.innerHTML = DesktopContent._lastCookieTime;
914 DesktopContent._cookieCodeMailbox.innerHTML = DesktopContent._lastCookieCode;
920 DesktopContent.getXMLRequestErrors =
function(req) {
922 if(!req || !req.responseXML)
923 return [
"Unknown error occured " +
924 "(XML response may have been illegal)!"];
926 var errNodes = DesktopContent.getXMLChildren(req,
"Error");
928 for(var i=0;i<errNodes.length;++i)
929 errArr.push(errNodes[i].getAttribute(
"value"));
935 DesktopContent.getXMLAttributeValue =
function(req, name, attribute) {
937 if(el = DesktopContent.getXMLNode(req,name))
938 return el.getAttribute(attribute);
939 else if(name ==
"Error" &&
940 (!req || !req.responseXML))
941 return "Unknown error occured " +
942 "(XML response may have been illegal)!";
950 DesktopContent.getXMLValue =
function(req, name) {
952 return req.getAttribute(
"value");
953 return DesktopContent.getXMLAttributeValue(req,name,
"value");
959 DesktopContent.getXMLChildren =
function(req, nodeName) {
961 if(req && req.responseXML)
962 req = req.responseXML;
963 return req.getElementsByTagName(nodeName);
970 DesktopContent.getXMLNode =
function(req, name) {
972 if(req && req.responseXML)
973 req = req.responseXML;
978 els = req.getElementsByTagName(name);
1001 DesktopContent.getXMLDataNode =
function(req, name) {
1002 return DesktopContent.getXMLNode(
"DATA");
1014 DesktopContent.tooltipConditionString =
function(str) {
1015 return str.replace(/<INDENT>/g,
1016 "<div style='margin-left:60px;'>").replace(/<\/INDENT>/g,
1020 DesktopContent.tooltip =
function(id,tip) {
1022 if(typeof Desktop !==
'undefined')
1024 DesktopContent._serverUrnLid = urnLid;
1025 DesktopContent._serverOrigin =
"";
1027 DesktopContent._sequence = DesktopContent.getDesktopParameter(0,
"code");
1028 if(!DesktopContent._sequence || DesktopContent._sequence ==
"")
1029 DesktopContent._sequence = 0;
1031 Debug.log(
"In Wizard Mode with Sequence=" + DesktopContent._sequence);
1035 var srcStackString,srcFunc,srcFile;
1037 if(Debug.BROWSER_TYPE == 1)
1039 srcStackString = (
new Error).stack.split(
"\n")[2];
1040 srcFunc = srcStackString.trim().split(
' ')[1];
1042 else if(Debug.BROWSER_TYPE == 2)
1044 srcStackString = (
new Error).stack.split(
"\n")[1];
1045 srcFunc = srcStackString.trim().split(
'@')[0];
1048 srcFile = srcStackString.substr(srcStackString.lastIndexOf(
'/')+1);
1049 if(srcFile.indexOf(
'?') >= 0)
1050 srcFile = srcFile.substr(0,srcFile.indexOf(
'?'));
1051 if(srcFile.indexOf(
':') >= 0)
1052 srcFile.substr(0,srcFile.indexOf(
':'));
1055 if(tip === undefined)
1057 Debug.log(
"Undefined tooltip string at " + srcStackString +
"\n" +
1058 srcFunc +
"\n" + srcFile +
".\n\n Tooltip Usage: <id> <tip>", Debug.HIGH_PRIORITY);
1066 for(var i=0;i<oldId.length;++i)
1067 if((oldId[i] >=
'a' && oldId[i] <=
'z') ||
1068 (oldId[i] >=
'A' && oldId[i] <=
'Z') ||
1069 (oldId[i] >=
'0' && oldId[i] <=
'9'))
1072 DesktopContent.XMLHttpRequest(
1073 "TooltipRequest?RequestType=check" +
1074 "&srcFunc=" + srcFunc +
1075 "&srcFile=" + srcFile +
1080 var showTooltip = DesktopContent.getXMLValue(req,
"ShowTooltip");
1090 str +=
"<input type='checkbox' " +
1091 "id='DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
1094 "DesktopContent.tooltipSetAlwaysShow(\"" +
1097 id +
"\", this.checked);" +
"'>";
1099 str +=
"<a onclick='" +
1100 "var el = document.getElementById(\"" +
1101 "DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
1103 "el.checked = !el.checked;" +
1104 "DesktopContent.tooltipSetAlwaysShow(\"" +
1107 id +
"\", el.checked);" +
1109 str +=
"Never show the Tooltip below, or...";
1115 str +=
"<input type='checkbox' " +
1116 "id='DesktopContent-tooltip-SetNeverShowCheckbox-hour-" +
1119 "DesktopContent.tooltipSetAlwaysShow(\"" +
1122 id +
"\", 0 /*neverShow*/, this.checked);" +
"'>";
1124 str +=
"<a onclick='" +
1125 "var el = document.getElementById(\"" +
1126 "DesktopContent-tooltip-SetNeverShowCheckbox-hour-" +
1128 "el.checked = !el.checked;" +
1129 "DesktopContent.tooltipSetAlwaysShow(\"" +
1132 id +
"\", 0 /*neverShow*/, el.checked);" +
1134 str +=
"Silence this Tooltip for a week (can be reset in Settings):";
1143 str +=
"<center><b>'" + oldId +
"' Tooltip</b></center><br>";
1148 str += DesktopContent.tooltipConditionString(tip);
1155 str +=
"<input type='checkbox' " +
1156 "id='DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
1159 "DesktopContent.tooltipSetAlwaysShow(\"" +
1162 id +
"\", this.checked);" +
"'>";
1164 str +=
"<a onclick='" +
1165 "var el = document.getElementById(\"" +
1166 "DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
1168 "el.checked = !el.checked;" +
1169 "DesktopContent.tooltipSetAlwaysShow(\"" +
1172 id +
"\", el.checked);" +
1174 str +=
"Never show the Tooltip above.";
1179 Debug.log(
"srcStackString " + srcStackString);
1180 Debug.log(str,Debug.TIP_PRIORITY);
1189 DesktopContent.setSecurityOn =
function(on) {
1190 console.log(
"Reached");
1191 DesktopContent.XMLHttpRequest(
1192 "ToggleSecurityCodeGeneration?RequestType=TurnGenerationOn" +
1195 ,DesktopContent.toggleSecurityCodeGenerationHandler
1201 DesktopContent.toggleSecurityCodeGenerationHandler =
function(req) {
1202 var status = DesktopContent.getXMLValue(req,
"Status");
1203 Debug.log(
"Status: " + status);
1204 if (status ==
"Generation_Success") {
1205 Debug.log(
"Successfully switched to using authentication sequence!");
1206 Debug.closeErrorPop();
1207 Debug.log(
"If you wish to return to the default security generation, you can use the 'Reset User Information' in the " +
1208 "'Edit User Data' app.");
1209 Debug.log(
"Plase refer to the console for the new link!", Debug.INFO_PRIORITY);
1216 DesktopContent.tooltipSetAlwaysShow =
function(srcFunc,srcFile,id,neverShow,temporarySilence) {
1217 Debug.log(
"neverShow = " + neverShow +
" tempSilence = " + temporarySilence);
1219 if(temporarySilence)
1221 DesktopContent.XMLHttpRequest(
1222 "TooltipRequest?RequestType=setNeverShow" +
1223 "&srcFunc=" + srcFunc +
1224 "&srcFile=" + srcFile +
1226 "&doNeverShow=" + (neverShow?1:0) +
1227 "&temporarySilence=" + (temporarySilence?1:0)
1229 ,0,0,0,0,
true,
true);
1231 if(temporarySilence)
return;
1234 document.getElementById(
"DesktopContent-tooltip-SetNeverShowCheckbox-below-" +
1235 id).checked = neverShow;
1236 document.getElementById(
"DesktopContent-tooltip-SetNeverShowCheckbox-above-" +
1237 id).checked = neverShow;
1248 DesktopContent.popUpVerification =
function(prompt, func, val, bgColor, textColor, borderColor, getUserInput,
1249 dialogWidth, cancelFunc, yesButtonText) {
1258 if(DesktopContent._verifyPopUp)
1259 DesktopContent._verifyPopUp.parentNode.removeChild(DesktopContent._verifyPopUp);
1262 if(val != undefined)
1263 prompt = prompt.replace(/REPLACE/g, val);
1270 if(!bgColor) bgColor =
"rgb(255,241,189)";
1271 if(!textColor) textColor =
"black";
1272 if(!borderColor) borderColor =
"black";
1273 if(!dialogWidth) dialogWidth = 200;
1278 css +=
"#" + DesktopContent._verifyPopUpId +
" " +
1279 "{position: absolute; z-index: 2000; border-radius: 5px; padding: 10px;" +
1280 "background-color: " + bgColor +
"; border: 2px solid " + borderColor +
";" +
1281 "color: " + textColor +
";text-align: center; overflow: auto;" +
1284 css +=
"#" + DesktopContent._verifyPopUpId +
"-text " +
1286 "color: " + textColor +
";width: " + dialogWidth +
"px; padding-bottom: 10px;" +
1289 css +=
"#" + DesktopContent._verifyPopUpId +
" *" +
1291 "color: " + textColor +
";" +
1295 var style = document.createElement(
'style');
1297 if (style.styleSheet) {
1298 style.styleSheet.cssText = css;
1300 style.appendChild(document.createTextNode(css));
1303 document.getElementsByTagName(
'head')[0].appendChild(style);
1306 var body = document.getElementsByTagName(
"BODY")[0];
1308 var el = document.createElement(
"div");
1309 el.setAttribute(
"id", DesktopContent._verifyPopUpId);
1311 var userInputStr =
"";
1314 "<input type='text' id='DesktopContent_popUpUserInput' " +
1315 "onclick='event.stopPropagation(); '" +
1318 var str =
"<div id='" + DesktopContent._verifyPopUpId +
"-text'>" +
1319 prompt +
"<br>" + userInputStr +
"</div>" +
1320 "<input type='submit' value='" +
1321 (yesButtonText?yesButtonText:
"Yes") +
1323 "onclick='event.stopPropagation();' " +
1325 " " +
1326 "<input type='submit' " +
1327 "onclick='event.stopPropagation();' " +
1332 el.getElementsByTagName(
'input')[0 + (getUserInput?1:0)].onmouseup =
1333 function(event){
event.stopPropagation(); DesktopContent.clearPopUpVerification(func);};
1335 el.getElementsByTagName(
'input')[1 + (getUserInput?1:0)].onmouseup =
1336 function(event){
event.stopPropagation(); DesktopContent.clearPopUpVerification(cancelFunc);};
1340 DesktopContent._verifyPopUp = el;
1341 el.style.left =
"-1000px";
1342 body.appendChild(el);
1347 el.getElementsByTagName(
'input')[0].focus();
1348 el.getElementsByTagName(
'input')[0].setSelectionRange(0,0);
1351 el.getElementsByTagName(
'input')[0].onkeydown =
1354 if(event.keyCode == 13)
1356 Debug.log(
"Accepting enter key");
1357 event.preventDefault();
1358 event.stopPropagation();
1359 DesktopContent.clearPopUpVerification(func);
1361 else if(event.keyCode == 27)
1363 Debug.log(
"Accepting escape key");
1364 event.preventDefault();
1365 event.stopPropagation();
1366 DesktopContent.clearPopUpVerification(cancelFunc);
1371 el.getElementsByTagName(
'input')[0].focus();
1377 if(event.keyCode == 13)
1379 Debug.log(
"Accepting enter key");
1380 event.preventDefault();
1381 event.stopPropagation();
1382 DesktopContent.clearPopUpVerification(func);
1384 else if(event.keyCode == 27)
1386 Debug.log(
"Accepting escape key");
1387 event.preventDefault();
1388 event.stopPropagation();
1389 DesktopContent.clearPopUpVerification(cancelFunc);
1394 var w = el.offsetWidth;
1395 var h = el.offsetHeight;
1396 var x = DesktopContent.getMouseX();
1397 var y = DesktopContent.getMouseY();
1399 Debug.log(
"X: " + x +
1404 while(x+w > DesktopContent.getWindowWidth())
1406 if(y > DesktopContent.getWindowHeight()/2 + h/2)
1408 while(y+h > DesktopContent.getWindowHeight())
1414 Debug.log(
"X: " + x +
1419 el.style.left = (DesktopContent.getWindowScrollLeft() + x) +
"px";
1420 el.style.top = (DesktopContent.getWindowScrollTop() + y) +
"px";
1425 DesktopContent.clearPopUpVerification =
function(func) {
1429 var userEl = document.getElementById(
"DesktopContent_popUpUserInput");
1430 var param = userEl?userEl.value:undefined;
1433 if(DesktopContent._verifyPopUp) DesktopContent._verifyPopUp.parentNode.removeChild(DesktopContent._verifyPopUp);
1434 DesktopContent._verifyPopUp = 0;
1457 DesktopContent.setPopUpPosition =
function(el,w,h,padding,border,
1458 margin,doNotResize,offsetUp) {
1460 Debug.log(
"DesktopContent.setPopUpPosition");
1462 if(padding === undefined) padding = 10;
1463 if(border === undefined) border = 1;
1464 if(margin === undefined) margin = 0;
1471 DesktopContent.setPopUpPosition.stopPropagation =
function(event) {
1473 event.stopPropagation();
1479 DesktopContent.setPopUpPosition.popupResize =
function() {
1485 window.removeEventListener(
"resize",DesktopContent.setPopUpPosition.popupResize);
1486 window.removeEventListener(
"scroll",DesktopContent.setPopUpPosition.popupResize);
1490 catch(err) {
return;}
1496 var ww = DesktopContent.getWindowWidth()-(padding+border)*2;
1497 var wh = DesktopContent.getWindowHeight()-(padding+border)*2;
1501 var ah = el.offsetHeight;
1503 if(w === undefined || h === undefined)
1505 w = ww - (margin)*2;
1506 h = wh - (margin)*2;
1510 x = (DesktopContent.getWindowScrollLeft() + ((ww-w)/2));
1511 y = (DesktopContent.getWindowScrollTop() + ((wh-h)/2)) - (offsetUp|0) - 100;
1513 if(y < DesktopContent.getWindowScrollTop() +
1515 y = DesktopContent.getWindowScrollTop() + margin +
1519 if(w > ww-margin-padding)
1520 x = -DesktopContent.getWindowScrollLeft();
1521 if(ah > wh-margin-padding)
1522 y = -DesktopContent.getWindowScrollTop();
1524 el.style.left = x +
"px";
1525 el.style.top = y +
"px";
1527 DesktopContent.setPopUpPosition.popupResize();
1530 el.style.width = w +
"px";
1531 el.style.height = h +
"px";
1543 el.style.position =
"absolute";
1544 el.style.zIndex =
"10000";
1545 el.style.border =
"1px solid #770000";
1546 el.style.backgroundColor =
"#efeaea";
1547 el.style.textAlign =
"center";
1548 el.style.padding =
"10px";
1549 el.style.color =
"black";
1553 window.addEventListener(
"resize",DesktopContent.setPopUpPosition.popupResize);
1554 window.addEventListener(
"scroll",DesktopContent.setPopUpPosition.popupResize);
1556 el.addEventListener(
"keydown",DesktopContent.setPopUpPosition.stopPropagation);
1557 el.addEventListener(
"mousemove",DesktopContent.setPopUpPosition.stopPropagation);
1558 el.addEventListener(
"mousemove",DesktopContent.mouseMove);
1560 el.style.overflow =
"auto";
1562 return {
"w" : w,
"h" : h,
"x" : x,
"y" : y};
1568 DesktopContent.parseColor =
function(colorStr) {
1572 var m = colorStr.split(
"(")[1].split(
")")[0].split(
",");
1573 if( m)
return "rgb("+m[0]+
","+m[1]+
","+m[2]+
")";
1574 else throw new Error(
"Color "+colorStr+
" could not be parsed.");
1581 DesktopContent.getColorAsRGBA =
function(colorStr) {
1584 var div = document.createElement(
'div');
1587 div.style.color = colorStr;
1588 div.style.display =
"none";
1589 document.body.appendChild(div);
1591 m = getComputedStyle(div).color.split(
"(")[1].split(
")")[0].split(
",");
1593 document.body.removeChild(div);
1595 if(m && m.length == 3)
return "rgba("+m[0]+
","+m[1]+
","+m[2]+
",255)";
1596 else if(m && m.length == 4)
return "rgba("+m[0]+
","+m[1]+
","+m[2]+
","+m[3]+
")";
1597 else throw new Error(
"Color "+colorStr+
" could not be parsed.");
1603 DesktopContent.getWindowWidth =
function() {
return window.innerWidth; }
1604 DesktopContent.getWindowHeight =
function() {
return window.innerHeight; }
1605 DesktopContent.getBodyWidth =
function() {
return document.body.offsetWidth; }
1606 DesktopContent.getBodyHeight =
function() {
return document.body.offsetHeight; }
1607 DesktopContent.getWindowScrollLeft =
function() {
return document.documentElement.scrollLeft || document.body.scrollLeft || 0; }
1608 DesktopContent.getWindowScrollTop =
function() {
return document.documentElement.scrollTop || document.body.scrollTop || 0; }
1609 DesktopContent.getMouseX =
function() {
return DesktopContent._windowMouseX | 0; }
1610 DesktopContent.getMouseY =
function() {
return DesktopContent._windowMouseY | 0; }
1611 DesktopContent.getDefaultWindowColor =
function() {
1613 if(!DesktopContent._windowColorPostbox || !DesktopContent._desktopColor)
1616 Debug.log(
"Color post boxes not setup! So giving default.",Debug.MED_PRIORITY);
1617 return "rgb(178,210,240)";
1620 wrgba = DesktopContent._windowColorPostbox.innerHTML.split(
"(")[1].split(
")")[0].split(
",");
1621 drgb = DesktopContent._desktopColor.split(
"(")[1].split(
")")[0].split(
",");
1623 drgb[i] = (drgb[i]*(1-wrgba[3]) + wrgba[i]*wrgba[3])|0;
1624 return "rgb("+drgb[0]+
","+drgb[1]+
","+drgb[2]+
")";
1629 DesktopContent.getDefaultDashboardColor =
function() {
return DesktopContent.parseColor(DesktopContent._dashboardColorPostbox.innerHTML); }
1630 DesktopContent.getDefaultDesktopColor =
function() {
1631 if(!DesktopContent._desktopColor)
1634 Debug.log(
"Color post boxes not setup! So giving default.",Debug.MED_PRIORITY);
1635 return "rgb(15,34,105)";
1637 return DesktopContent._desktopColor;
1642 DesktopContent.getUsername =
function() {
1643 var dispName = DesktopContent._theWindow.parent.document.getElementById(
"DesktopDashboard-user-displayName").innerHTML
1644 return dispName.substr(dispName.indexOf(
",")+2);
1652 DesktopContent.openNewWindow =
function(name,subname,windowPath,unique,completeHandler) {
1654 Debug.log(
"DesktopContent.openNewWindow= " + windowPath);
1655 Debug.log(
"name= " + name);
1656 Debug.log(
"subname= " + subname);
1657 Debug.log(
"unique= " + unique);
1661 var paramsStr = DesktopContent._openWindowMailbox.innerHTML;
1664 var tryAgainCount = 0;
1669 Debug.log(
"Window creation is busy, trying again soon!");
1673 if(tryAgainCount > 50)
1675 Debug.log(
"It looks like the window failed to open. Perhaps the Desktop is disconnected from the server; " +
1676 "please reconnect and try again.", Debug.WARN_PRIORITY);
1680 setTimeout(
function(){ DesktopContent.openNewWindow(windowPath); }, 100);
1685 var str =
"requestingWindowId=" + DesktopContent._myDesktopFrame.id.split(
'-')[1];
1686 str +=
"&windowName=" + name;
1687 str +=
"&windowSubname=" + subname;
1688 str +=
"&windowUnique=" + unique;
1689 str +=
"&windowPath=" + windowPath;
1690 DesktopContent._openWindowMailbox.innerHTML = str;
1692 Debug.log(
"Waiting for complete...");
1695 var timeoutHandler =
function() {
1696 Debug.log(
"Checking for complete...");
1700 if(tryAgainCount > 50)
1702 Debug.log(
"It looks like the window failed to open. Perhaps the Desktop is disconnected from the server; " +
1703 "please reconnect and try again.", Debug.WARN_PRIORITY);
1709 var paramsStr = DesktopContent._openWindowMailbox.innerHTML;
1710 var spliti = paramsStr.indexOf(
'&');
1711 params = [paramsStr.substr(0,spliti),paramsStr.substr(spliti+5)];
1713 var requestingWindowId =
"", done =
"";
1714 for(var i=0;i<params.length;++i)
1716 spliti = params[i].indexOf(
'=');
1717 varPair = [params[i].substr(0,spliti),params[i].substr(spliti+1)];
1718 if(varPair[0] ==
"requestingWindowId")
1719 requestingWindowId = varPair[1];
1720 else if(varPair[0] ==
"done")
1724 if(paramsStr =
"" || (requestingWindowId !=
"" && done !=
""))
1727 Debug.log(
"requestingWindowId=" + requestingWindowId);
1728 Debug.log(
"done=" + done);
1729 if(requestingWindowId != DesktopContent._myDesktopFrame.id.split(
'-')[1])
1730 Debug.log(
"There was a mismatch in window id!",Debug.MED_PRIORITY);
1733 DesktopContent._openWindowMailbox.innerHTML =
"";
1740 setTimeout(timeoutHandler, 100);
1744 setTimeout(timeoutHandler,
1756 DesktopContent.openNewBrowserTab =
function(name,subname,windowPath,unique) {
1758 if(windowPath !== undefined)
1761 if(windowPath[0] ==
'?')
1762 windowPath = windowPath.substr(1);
1768 var i = windowPath.indexOf(
"urn:xdaq-application:lid=") + (
"urn:xdaq-application:lid=").length;
1769 var isAllNumbers =
true;
1770 for(i;i<windowPath.length;++i)
1774 if(windowPath[i] <
"0" || windowPath[i] >
"9")
1776 isAllNumbers =
false;
1785 Debug.log(
"An error occurred while trying to open the window. " +
1786 "The window path seems to be invalid: " + e, Debug.HIGH_PRIORITY);
1790 Debug.log(
"DesktopWindow= " + windowPath);
1792 Debug.log(
"name= " + name);
1793 Debug.log(
"subname= " + subname);
1794 Debug.log(
"unique= " + unique);
1796 var search = DesktopContent._theWindow.parent.parent.window.location.search;
1797 url = DesktopContent._theWindow.parent.parent.window.location.pathname;
1799 var str =
"requestingWindowId=" + DesktopContent._myDesktopFrame.id.split(
'-')[1];
1800 str +=
"&windowName=" + name;
1801 str +=
"&windowSubname=" + subname;
1802 str +=
"&windowUnique=" + unique;
1803 str +=
"&windowPath=" + windowPath;
1810 var i = url.indexOf(
"urn:xdaq-application:lid=") + (
"urn:xdaq-application:lid=").length;
1811 var isAllNumbers =
true;
1812 for(i;i<url.length;++i)
1816 if(url[i] <
"0" || url[i] >
"9")
1818 isAllNumbers =
false;
1829 var i = search.indexOf(
"requestingWindowId");
1831 search = search.substr(0,i);
1833 if(search.length && search[search.length-1] !=
'?'
1834 && search[search.length-1] !=
'&')
1836 url += search + str;
1839 Debug.log(
"DesktopContent.openNewBrowserTab= " + url);
1841 window.open(url,
'_blank');
1846 DesktopContent.getDesktopWindowTitle =
function() {
1847 return DesktopContent._theWindow.parent.document.getElementById(
1848 "DesktopWindowHeader-" +
1849 DesktopContent._theWindow.name.split(
'-')[1]).innerHTML;