otsdaq_utilities  v2_05_02_indev
Desktop.js
1 //=====================================================================================
2 //
3 // Created Dec, 2012
4 // by Ryan Rivera ((rrivera at fnal.gov))
5 //
6 // Desktop.js
7 //
8 // This is the desktop code for the user interface for ots. ots is the DAQ
9 // and control software for the Fermi Strips Telescope.
10 //
11 // The desktop consists of a dashboard and an arbitrary amount of windows
12 //
13 //=====================================================================================
14 
15 var Desktop = Desktop || {}; //define Desktop namespace
16 
17 if (typeof Debug == 'undefined')
18  console.log('ERROR: Debug is undefined! Must include Debug.js before Desktop.js');
19 else if (typeof Globals == 'undefined')
20  console.log('ERROR: Globals is undefined! Must include Globals.js before Desktop.js');
21 else
22  Desktop.desktop; //this is THE global desktop variable
23 
24 Desktop.init = function(security) {
25 
26  Desktop.desktop = Desktop.createDesktop(security);
27  if(Desktop.desktop)
28  Debug.log("Desktop.desktop Initalized Successfully",Debug.LOW_PRIORITY);
29 
30  // Enable navigation prompt
31  // (to prevent accidental/back/forward/nav leaving the page)
32  window.onbeforeunload = function() {
33  return true;
34  };
35 } //end init()
36 
37 Desktop.SECURITY_TYPE_NONE = "NoSecurity";
38 Desktop.SECURITY_TYPE_DIGEST_ACCESS = "DigestAccessAuthentication";
39 
42 //call createDesktop to create instance of a desktop
45 Desktop.createDesktop = function(security) {
46 
47  if (typeof Debug == 'undefined') return 0; //fail if debug not defined just to force consistent behavior
48 
49  if(false === (this instanceof Desktop.createDesktop)) {
50  //here to correct if called as "var v = Desktop.createDesktop();"
51  // instead of "var v = new Desktop.createDesktop();"
52  return new Desktop.createDesktop(security);
53  }
54 
55 
56  //------------------------------------------------------------------
57  //list of members functions ----------------------
58  //------------------------------------------------------------------
59  //
60  //public:
61  // Desktop.desktopTooltip()
62  // this.getDesktopWidth = function() { return _desktopElement.clientWidth;}
63  // this.getDesktopHeight = function() { return _desktopElement.clientHeight;}
64  // this.getDesktopX = function() { return _desktopElement.offsetLeft;}
65  // this.getDesktopY = function() { return _desktopElement.offsetTop;}
66  // this.getDesktopContentX = function() { return _desktopElement.offsetLeft+_dashboard.getDashboardWidth();}
67  // this.getDesktopContentY = function() { return _desktopElement.offsetTop+_dashboard.getDashboardHeight();}
68  // this.getDesktopContentWidth = function() { return _desktopElement.clientWidth-_dashboard.getDashboardWidth();}
69  // this.getDesktopContentHeight = function() { return _desktopElement.clientHeight-_dashboard.getDashboardHeight();}
70  // this.getNumberOfWindows = function() { return _windows.length;}
71  // this.getWindowNameByIndex = function(i) { return _windows[i].getWindowName();}
72  // this.getWindowSubNameByIndex = function(i) { return _windows[i].getWindowSubName();}
73  // this.getWindowByIndex = function(i) { return _windows[i];}
74  // this.getForeWindow = _getForeWindow;
75  // this.redrawDesktop = _handleDesktopResize;
76  // this.getLastFrameMouseX = function() { return parseInt(_mouseOverXmailbox.innerHTML);}
77  // this.getLastFrameMouseY = function() { return parseInt(_mouseOverYmailbox.innerHTML);}
78  // this.resetFrameMouse = function() { _mouseOverXmailbox.innerHTML = -1;_mouseOverYmailbox.innerHTML = -1;}
79  // this.getWindowLayoutStr = _getWindowLayoutStr;
80  // this.addWindow(name,subname,url,unique,extraStep)
81  // this.getWindowById(id)
82  // this.setForeWindow(win)
83  // this.closeWindowById(id)
84  // this.maximizeWindowById(id)
85  // this.toggleFullScreen(e)
86  // this.minimizeWindowById(id)
87  // this.toggleMinimize(e)
88  // this.clickedWindowDashboard(id)
89  // this.setDefaultWindowColor(color)
90  // this.defaultLayoutSelect(i)
91  // this.closeAllWindows()
92  // this.resetDesktop(permissions)
93  // this.actOnParameterAction()
94  // Desktop.XMLHttpRequest(requestURL, data, returnHandler, reqIndex)
95  // Desktop.getXMLAttributeValue(req, name, attribute)
96  // Desktop.getXMLValue(req, name)
97  // Desktop.logout()
98  // Desktop.formatTime(t)
99  // Desktop.closeSystemMessage(id)
100  // Desktop.isWizardMode()
101  // Desktop.openNewBrowserTab(name,subname,windowPath,unique)
102  // Desktop.desktopTooltip
103 
104  //"public" handlers:
105  // Desktop.mouseMoveSubscriber(newHandler)
106 
107  //private:
108  // _handleDesktopResize(event)
109  // _getWindowLayoutStr()
110  // _getForeWindow()
111  // _closeWindow(win)
112  // _checkMailboxes(win)
113  // _handleSystemMessages(req)
114 
115  //"private" handlers:
116  // Desktop.handleTouchStart(touchEvent)
117  // Desktop.handleBodyTouchEnd(touchEvent)
118  // Desktop.handleTouchEnd(touchEvent)
119  // Desktop.handleBodyTouchMove(touchEvent)
120  // Desktop.handleTouchMove(touchEvent)
121  // Desktop.handleWindowMouseDown(mouseEvent)
122  // Desktop.handleWindowMouseUp(mouseEvent)
123  // Desktop.handleWindowMouseMove(mouseEvent)
124  // Desktop.handleBodyMouseMove(mouseEvent)
125  // Desktop.handleWindowManipulation(delta)
126  // Desktop.handleWindowButtonDown(mouseEvent)
127  // Desktop.handleWindowMinimize(mouseEvent)
128  // Desktop.handleWindowMaximize(mouseEvent)
129  // Desktop.handleWindowClose(mouseEvent)
130 
131 
132 
133  //------------------------------------------------------------------
134  //create private members variables ----------------------
135  //------------------------------------------------------------------
136 
137  var _defaultWindowMinZindex = 10;
138  var _defaultWindowMaxZindex = 10000;
139  var _defaultDashboardZindex = 11000;
140  var _defaultWidth = 620;
141  var _defaultHeight = 580;
142  var _defaultLeft = 200;
143  var _defaultTop = 70;
144  var _defaultLeftOffset = 50;
145  var _defaultTopOffset = 25;
146  var _defaultOffsetTimes = 5;
147  var _currentLeft = _defaultLeft;
148  var _currentTop = _defaultTop;
149 
150  var _windows = new Array(); //windows are initialized to empty, array represents z-depth also
151  var _desktopElement;
152  var _dashboard, _icons, _mouseOverXmailbox, _mouseOverYmailbox;
153  //var _needToLoginMailbox;
154  //var _updateTimeMailbox,
155  var _updateSettingsMailbox,
156  _settingsLayoutMailbox;//, _openWindowMailbox;
157  //, _blockSystemCheckMailbox;
158  //var _windowColorPostbox;
159  var _MAILBOX_TIMER_PERIOD = 500; //timer period for checking mailbox and system messages: 500 ms
160  var _sysMsgId = 0; //running counter to identify system message pop-ups
161  var _SYS_MSG_SOUND_PATH = "/WebPath/sounds/fx-System-Message.wav"; // "http://www.soundjay.com/button/button-2.wav"; //must be .wav for firefox incompatibility
162  var _sysMsgSound = new Audio(_SYS_MSG_SOUND_PATH);
163 
164  var _winId = 1000; //running window id number
165 
166  var _login;
167 
168  //for system messages
169  var _sysMsgCounter = 0;
170  var _SYS_MSG_MAX_COUNT = 10; //number of check mailbox timers to count through before checking for system messages
171 
172  var _firstCheckOfMailboxes = true;
173 
174  //------------------------------------------------------------------
175  //create public members variables ----------------------
176  //------------------------------------------------------------------
177  this.dashboard;
178  this.login;
179  this.icons;
180  this.checkMailboxTimer;
181  this.serverConnected = true;
182  this.security = security;
183 
184  //this.cookieCodeMailbox = 0;
185 
186  this.defaultWindowFrameColor = "rgba(196,229,255,.9)";
187 
188  //------------------------------------------------------------------
189  //create PRIVATE members functions ----------------------
190  //------------------------------------------------------------------
191 
192  //===========================================================
193  var _handleDesktopResize = function(event) {
194  _desktopElement.style.height = (window.innerHeight-_desktopElement.offsetTop) + "px";
195  _desktopElement.style.width = (window.innerWidth-_desktopElement.offsetLeft) + "px";
196  if(!_dashboard) return; //initial calls dashboard might not be defined
197  _dashboard.redrawDashboard();
198  if(_login) _login.redrawLogin();
199  if(_icons) _icons.redrawIcons();
200 
201  //if top windows is maximized, then resize
202  if(_windows.length && _windows[_windows.length-1].isMaximized()) {
203  var w = _windows[_windows.length-1];
204  w.setWindowSizeAndPosition(w.getWindowX(),w.getWindowY(),w.getWindowWidth(),w.getWindowHeight());
205  }
206 
207  //_icons.style.left = Desktop.desktop.getDesktopContentX()+50+"px";
208  //_icons.style.top = Desktop.desktop.getDesktopContentY()+50+"px";
209  } //end _handleDesktopResize()
210 
211  //===========================================================
212  //return current window layout in string with parameters separated by commas
213  // Note: represent position in terms of 0-10000 for the entire Desktop Content area
214  // - this should allow for translation to any size Desktop Content area when loaded
215  var _getWindowLayoutStr = function() {
216  var dw = Desktop.desktop.getDesktopContentWidth()/10000.0; //to calc int % 0-10000
217  var dh = Desktop.desktop.getDesktopContentHeight()/10000.0;//to calc int % 0-10000
218  var dx = Desktop.desktop.getDesktopContentX();
219  var dy = Desktop.desktop.getDesktopContentY();
220 
221  var layout = ""; //"[";
222  for(var i=0;i<_windows.length;++i)
223  {
224  if(_windows[i].getWindowName() == "Settings") continue; //skip settings window
225 
226  layout += (i?",":"") +
227  encodeURIComponent(_windows[i].getWindowName())
228  + "," + encodeURIComponent(_windows[i].getWindowSubName())
229  + "," + encodeURIComponent(_windows[i].getWindowUrl()) //_windows[i].getWindowUrl().replace(/&/g,'%38').replace(/=/g,'%61') //global replace & and =
230  + "," + (((_windows[i].getWindowX()-dx)/dw)|0)
231  + "," + (((_windows[i].getWindowY()-dy)/dh)|0)
232  + "," + ((_windows[i].getWindowWidth()/dw)|0)
233  + "," + ((_windows[i].getWindowHeight()/dh)|0)
234  + "," + (_windows[i].isMinimized()?"0":(_windows[i].isMaximized()?"2":"1"));
235  //+ ", "; //last comma (with space for settings display)
236  }
237  //layout += "]";
238  return layout;
239  } //end _getWindowLayoutStr()
240 
241  //===========================================================
242  //for login
243  var _scrambleEggs = function(u) { return u; }
244 
245  //===========================================================
246  var _getForeWindow = function() { return _windows.length?_windows[_windows.length-1]:0; } //return last window in array as forewindow
247 
248  //===========================================================
249  var _closeWindow = function(win) {
250  Desktop.desktop.setForeWindow(win);
251  win.windiv.parentNode.removeChild(win.windiv); //remove from page!
252 
253  //delete top window from windows array
254  // Debug.log("Desktop Window closed z:" + _windows[_windows.length-1].getWindowZ(),Debug.LOW_PRIORITY);
255  _windows.splice(_windows.length-1,1);
256  // Debug.log("Desktop Windows left:" + _windows.length,Debug.LOW_PRIORITY);
257 
258  _dashboard.updateWindows();
259  } //end _closeWindow()
260 
261  //===========================================================
262  //_checkMailboxes ~~~
263  // called periodically (e.g. every _MAILBOX_TIMER_PERIODms)
264  // check div mailboxes that are shared by window content code and take action if necessary
265  // check for settings change
266  var _checkMailboxes = function(win)
267  {
268  window.clearTimeout(Desktop.desktop.checkMailboxTimer);
269  Desktop.desktop.checkMailboxTimer = window.setTimeout(_checkMailboxes,
270  _MAILBOX_TIMER_PERIOD);
271 
272  //console.log("_checkMailboxes sysMsgCounter=" +_sysMsgCounter);
273 
274  if(_firstCheckOfMailboxes)
275  {
276  console.log("First check of mailboxes!");
277 
278  console.log("Checking for any shortcut work from get parameters...");
279  _firstCheckOfMailboxes = false;
280  Desktop.desktop.actOnParameterAction(); //this should be the second running and will always work (first time is at end of Desktop instance creation.. and may fail for opening icon by name)
281 
282  }
283 
284 // //windows can request a blackout, to avoid logging out (attempt to stop all other tabs by using browser cookie)
285 // if(_blockSystemCheckMailbox.innerHTML == "1")
286 // {
287 // Desktop.desktop.login.blackout(true);
288 // }
295 // else
296 // {
297 // Desktop.desktop.login.blackout(false);
298 // }
299 
300 
301 
302 // //check _openWindowMailbox to see if a window opening is being requested by a Desktop Window
303 // // From requesting window (check that done=1):
304 // // innerHTML = requestingWindowId=<window uid>&windowPath=<window path to open>
305 // // Response when done:
306 // // innerHTML = requestingWindowId=<window uid>&done=1
307 // if(_openWindowMailbox.innerHTML != "")
308 // {
309 // console.log("_openWindowMailbox.textContent=" + _openWindowMailbox.textContent);
310 //
311 // //get parameters
312 // var paramsStr = _openWindowMailbox.textContent;
313 // var params = [];
314 // var paramCnt = 5 ;
315 // var spliti, splitiOld = 0;
316 // for(var i=0;i<paramCnt;++i)
317 // {
318 // if(i == paramCnt-1) //last one take the whole thing (this is path, and could have &'s in it)
319 // {
320 // params.push(paramsStr.substr(splitiOld));
321 // break;
322 // }
323 // //for others, handle like normal get param
324 // spliti = paramsStr.indexOf('&', splitiOld);
325 // params.push(paramsStr.substr(splitiOld,spliti-splitiOld))
326 // splitiOld = spliti+1;
327 // }
328 //
329 // var varPair;
330 // var requestingWindowId = "", windowPath = "";
331 // var windowName, windowSubname, windowUnique;
332 // for(var i=0;i<params.length;++i)
333 // {
334 // spliti = params[i].indexOf('=');
335 // varPair = [params[i].substr(0,spliti),params[i].substr(spliti+1)];
336 // if(varPair[0] == "requestingWindowId")
337 // requestingWindowId = varPair[1];
338 // else if(varPair[0] == "windowPath")
339 // windowPath = varPair[1];
340 // else if(varPair[0] == "windowName")
341 // windowName = varPair[1];
342 // else if(varPair[0] == "windowSubname")
343 // windowSubname = varPair[1];
344 // else if(varPair[0] == "windowUnique")
345 // windowUnique = varPair[1];
346 // }
347 // if(requestingWindowId != "" && windowPath != "")
348 // {
349 // //have work to do!
350 // // Note: similar to L1000 in actOnParameterAction()
351 // console.log("_openWindowMailbox.innerHTML=" + _openWindowMailbox.innerHTML);
352 // console.log("requestingWindowId=" + requestingWindowId);
353 // console.log("windowPath=" + windowPath);
354 // while(windowPath.length && windowPath[0] == '?') windowPath = windowPath.substr(1); //remove leading ?'s
355 // console.log("modified windowPath=" + windowPath);
356 // console.log("windowName=" + windowName);
357 // console.log("windowSubname=" + windowSubname);
358 // console.log("windowUnique=" + windowUnique);
359 //
360 // var newWin;
361 //
362 // //if only windowName is defined, then attempt to open the icon on the
363 // // Desktop with that name (this helps resolve supervisor LIDs, etc.)
364 // if(windowSubname == "undefined" &&
365 // windowUnique == "undefined") //the string undefined is what comes through
366 // {
367 // console.log("Opening desktop window... " + windowName);
368 //
369 // var pathUniquePair = Desktop.desktop.icons.iconNameToPathMap[windowName];
370 // console.log("Desktop.desktop.icons.iconNameToPathMap",
371 // Desktop.desktop.icons.iconNameToPathMap);
372 //
373 // if(pathUniquePair ===
374 // undefined)
375 // {
376 // Debug.log("An error occurred opening the window named '" +
377 // windowName + "' - it was not found in the Desktop icons. " +
378 // "Do you have permissions to access this window? Notify admins if the problem persists.",
379 // Debug.HIGH_PRIORITY);
380 //
381 // //respond done
382 // var str = "requestingWindowId=" + requestingWindowId;
383 // str += "&done=1";
384 // _openWindowMailbox.innerHTML = str; //indicate done
385 //
386 // return;
387 // }
388 //
389 // var pathStr = pathUniquePair[0];
390 //
391 // if(windowPath != "undefined") //add parameters if defined
392 // {
393 // Debug.log("Adding parameter path " + windowPath);
394 // if(pathStr.indexOf('?') >= 0) //then assume already parameters
395 // pathStr += "&";
396 // else if(pathStr.length) //then assume need ?
397 // pathStr += '?';
398 // windowPath = pathStr + windowPath;
399 // }
400 // else
401 // windowPath = pathStr;
402 //
403 // newWin = Desktop.desktop.addWindow( //(name,subname,url,unique)
404 // windowName,
405 // "",
406 // windowPath, //e.g. "http://rulinux03.dhcp.fnal.gov:1983/WebPath/html/ConfigurationGUI.html?urn=280",
407 // eval(pathUniquePair[1]));
408 // }
409 // else
410 // {
411 // newWin = Desktop.desktop.addWindow( //(name,subname,url,unique)
412 // windowName,
413 // windowSubname,
414 // windowPath, //e.g. "http://rulinux03.dhcp.fnal.gov:1983/WebPath/html/ConfigurationGUI.html?urn=280",
415 // eval(windowUnique));
416 // }
417 //
418 // //delay the setting of the fore window
419 // window.setTimeout(function(){ Desktop.desktop.setForeWindow(newWin); }, 200);
420 //
421 // var str = "requestingWindowId=" + requestingWindowId;
422 // str += "&done=1";
423 // _openWindowMailbox.innerHTML = str; //indicate done
424 // }
425 // }
426 
427  //==============
428  //other things besides opening windows
429  //....
430 
431  if(!Desktop.desktop.login || !Desktop.desktop.login.getCookieCode(true))
432  {
433  //if(_needToLoginMailbox.innerHTML == "1")
434  // _needToLoginMailbox.innerHTML = ""; //reset
435 
436  return; //don't do things if not logged in
437  }
438 
439 
440 // console.log("Checking iFrame z change focus");
441 // // check if a window iFrame has taken focus and tampered with z mailbox. If so 'officially' set to fore window
442 // if(_windowZmailbox > _defaultWindowMaxZindex)
443 // {
444 // Desktop.desktop.setForeWindow(); //should pass undefined window.. to just relabel Z depth
445 // //Desktop.desktop.getForeWindow()
446 // Debug.log("Desktop Foreground Window Refreshed by _checkMailboxes Timeout",Debug.LOW_PRIORITY);
447 // }
448 
449 // //check need for login mailbox
450 // if(_needToLoginMailbox.innerHTML == "1")
451 // {
452 // _needToLoginMailbox.innerHTML = ""; //reset
453 // if(!document.getElementById("Desktop-loginDiv") &&
454 // !Desktop.desktop.login.isBlackout())
455 // {
456 // //only signal logout if login div is gone (login complete)
457 // Debug.log("DesktopContent signaled new login needed!",Debug.HIGH_PRIORITY);
458 // Desktop.logout();
459 // }
460 // else
461 // Debug.log("Ignoring desktop content need for login signal due to blackout.");
462 // }
463 
464 // //check if cookie time from content is newer than cookie time in login
465 // if(parseInt(_updateTimeMailbox.innerHTML) > parseInt(Desktop.desktop.login.getCookieTime()))
466 // Desktop.desktop.login.updateCookieFromContent(parseInt(_updateTimeMailbox.innerHTML)); //update based on content value
467 //
468  //check if update settings is necessary
469  if(_updateSettingsMailbox.innerHTML != "")
470  {
471  //this mailbox defines read/write actions between settings dialog and desktop
472 
473  //Debug.log("Desktop Settings update " + _updateSettingsMailbox.innerHTML ,Debug.LOW_PRIORITY);
474 
475  if(_updateSettingsMailbox.innerHTML == "LAYOUT") //settings is reading from desktop
476  {
477  //return current window layout in mailbox with parameters separated by commas
478  var layout = _getWindowLayoutStr();
479  _settingsLayoutMailbox.innerHTML = layout;
480  Debug.log("Desktop _updateSettingsMailbox " + layout,Debug.LOW_PRIORITY);
481  }
482  else //settings is writing to destkop
483  {
484  //setup req with settings data
485  var xml = _updateSettingsMailbox.innerHTML;
486  var req = req || {};
487  req.responseXML = ( new window.DOMParser() ).parseFromString(xml, "text/xml"); //get xml object
488  _login.applyUserPreferences(req);
489  }
490 
491  _updateSettingsMailbox.innerHTML = ""; //clear to prepare for next time
492  }
493 
494  //system messages check (and submit current window layout)
495  ++_sysMsgCounter;
496  if(_sysMsgCounter == _SYS_MSG_MAX_COUNT)
497  {
498  //windows can request a blackout, to avoid logging out
499  if(//_blockSystemCheckMailbox.innerHTML == "1" ||
500  Desktop.desktop.login.isBlackout())
501  {
502  Debug.log("System blackout (likely rebooting)...");
503  _sysMsgCounter = 0; // reset since not going to handler
504  }
505  else
506  Desktop.XMLHttpRequest("Request?RequestType=getSystemMessages","",_handleSystemMessages);
507  }
508  } //end _checkMailboxes()
509 
510  //===========================================================
511  var _lastSystemMessage = ""; //prevent repeats
512  //_handleSystemMessages ~~~
513  // handles request returns periodically (ever _SYS_MSG_MAX_COUNT times through _checkMailboxes)
514  var _handleSystemMessages = function(req)
515  {
516  //Debug.log("Desktop _handleSystemMessages " + req.responseText,Debug.LOW_PRIORITY);
517 
518  _sysMsgCounter = 0; //reset system message counter to setup next request
519 
520  if(!req) return; //request failed
521 
522  var userLock; //tmp hold user with lock
523  userLock = Desktop.getXMLValue(req,"username_with_lock"); //get user with lock
524  Desktop.desktop.dashboard.displayUserLock(userLock);
525 
526  var tmp = Desktop.getXMLValue(req,"systemMessages");
527  if(!tmp) return; //did not find return string
528 
529  //disallow repeats (due to broadcast messages hanging around)
530  //if(_lastSystemMessage == tmp) return;
531  //_lastSystemMessage = tmp;
532  var tmpi;
533  if((tmpi = tmp.indexOf(_lastSystemMessage)) >= 0)
534  {
535  Debug.log("Desktop pretmp " + tmp);
536  Debug.log("Desktop _lastSystemMessage " + _lastSystemMessage);
537  Debug.log("Desktop tmp " + tmp.substr(tmpi+_lastSystemMessage.length+1));
538  tmp = tmp.substr(tmpi+_lastSystemMessage.length+1);
539  }
540 
541  //Debug.log("Desktop tmp " + tmp.substr(tmpi+_lastSystemMessage.length+1));
542 
543 
544  var msgArr = tmp.split("|");
545  Debug.log("Desktop msgArr.length " + msgArr.length);
546 
547  if(msgArr.length < 2) return; //no new messages left
548 
549  Debug.log("Desktop _handleSystemMessages ========================== " + Desktop.formatTime(msgArr[0]) +
550  " - " + msgArr[1]
551  ,Debug.LOW_PRIORITY);
552 
553  ++_sysMsgId; //increment to new ID
554  var sysMsgEl = document.createElement("div");
555  sysMsgEl.setAttribute("class", "Desktop-systemMessageBox");
556  sysMsgEl.setAttribute("id", "Desktop-systemMessageBox-" + _sysMsgId);
557  sysMsgEl.style.left = (50 + _sysMsgId % 5 * 10) + "px";
558  sysMsgEl.style.top = (50 + _sysMsgId % 5 * 10) + "px";
559  _desktopElement.appendChild(sysMsgEl);
560 
561  var str = "";
562 
563  for(var i=0;i<msgArr.length;i+=2)
564  {
565  str += "<div style='font-size:12px'>System Message Received at " + Desktop.formatTime(msgArr[i]) + "</div>";
566  str += "<div>" +
567  //first decode URI, then convert html entities
568  decodeURIComponent(msgArr[i+1]).replace(/[\u00A0-\u9999<>\&]/gim,
569  function(i) {
570  return '&#'+i.charCodeAt(0)+';';
571  }) + "</div><br>";
572  _lastSystemMessage = msgArr[i] + "|" + msgArr[i+1];
573  }
574 
575  //dismiss link
576  str += "<div style='float:right; margin-left:30px'>";
577  str += "<a href='Javascript:Desktop.closeSystemMessage(" + _sysMsgId + ");' " +
578  "title='Click here to dismiss system message'>Dismiss</a></div>";
579 
580  sysMsgEl.innerHTML = str;
581 
582  if(sysMsgEl.clientHeight > 300)
583  sysMsgEl.style.height = 300 + "px";
584 
585  //play sound alert
586  //_sysMsgSound.src = _SYS_MSG_SOUND_PATH; // buffers automatically when created
587  //_sysMsgSound.play(); //Muted for now
588  } //end _handleSystemMessages()
589 
590  //------------------------------------------------------------------
591  //create PUBLIC members functions ----------------------
592  //------------------------------------------------------------------
593  this.getDesktopWidth = function() { return _desktopElement.clientWidth;}
594  this.getDesktopHeight = function() { return _desktopElement.clientHeight;}
595  this.getDesktopX = function() { return _desktopElement.offsetLeft;}
596  this.getDesktopY = function() { return _desktopElement.offsetTop;}
597  this.getDesktopContentX = function() { return _desktopElement.offsetLeft+_dashboard.getDashboardWidth();}
598  this.getDesktopContentY = function() { return _desktopElement.offsetTop+_dashboard.getDashboardHeight();}
599  this.getDesktopContentWidth = function() { return _desktopElement.clientWidth-_dashboard.getDashboardWidth();}
600  this.getDesktopContentHeight = function() { return _desktopElement.clientHeight-_dashboard.getDashboardHeight();}
601  this.getNumberOfWindows = function() { return _windows.length;}
602  this.getWindowNameByIndex = function(i) { return _windows[i].getWindowName();}
603  this.getWindowSubNameByIndex = function(i) { return _windows[i].getWindowSubName();}
604  this.getWindowByIndex = function(i) { return _windows[i];}
605  this.getForeWindow = _getForeWindow;
606  this.redrawDesktop = _handleDesktopResize;
607  this.getLastFrameMouseX = function() { return parseInt(_mouseOverXmailbox);}
608  this.getLastFrameMouseY = function() { return parseInt(_mouseOverYmailbox);}
609  this.resetFrameMouse = function() { _mouseOverXmailbox = -1;_mouseOverYmailbox = -1;}
610  this.getWindowLayoutStr = _getWindowLayoutStr;
611 
612  //==============================================================================
613  //addWindow ~~~
614  // Adds a window to desktop at default location, with default size
615  // Window title bar will read "name - subname" and will be organized by name
616  // in dashboard. Window will display page at url.
617  // If unique, the window is not made if there already exists a window
618  // with the same "name - subname".
619  //
620  // If subname = "" it is ignored.
621  //
622  // If extraStep == 1, tile windows, if == 2, maximize
623  //
624  // returns new window
625  this.addWindow = function(name,subname,url,unique,extraStep)
626  {
627  Debug.log(name + " - " + subname + " - " + url + " - " + unique,Debug.LOW_PRIORITY);
628 
629  if(unique == 2) //open as stand-alone new tab page
630  {
631  Debug.log("Opening stand-alone new tab",Debug.LOW_PRIORITY);
632  window.open(url,'_blank');
633  return;
634  }
635 
636  if(unique)
637  {
638  Debug.log("Adding window uniquely",Debug.LOW_PRIORITY);
639  for(var i=0;i<_windows.length;++i)
640  if(_windows[i].getWindowName() == name && _windows[i].getWindowSubName() == subname)
641  {
642  Debug.log("Window creation failed. Not unique.",Debug.LOW_PRIORITY);
643  if(_windows[i].isMinimized())
644  {
645  Debug.log(_windows[i].getWindowSubName() + "was minimized but will now be restored!");
646  _windows[i].unminimize(); //restore window
647  }
648  else
649  Desktop.desktop.setForeWindow(_windows[i]); //bring window to front
650  return;
651  }
652  }
653 
654  if(_windows.length + _defaultWindowMinZindex >= _defaultWindowMaxZindex)
655  {
656  Debug.log("FAILED -- Desktop Window Added - too many windows!",Debug.HIGH_PRIORITY);
657  return;
658  }
659 
660  if(name == "Security Settings")
661  {
662  window_width = 730;
663  window_height = 410;
664  }
665  else if(name == "Edit User Data")
666  {
667  window_width = 730;
668  window_height = 730;
669  }
670  else {
671  window_width = _defaultWidth;
672  window_height = _defaultHeight;
673  }
674  //KEEP..
675  //subname += _winId; //for visual window debugging (but destroys uniqueness)
676  //end KEEP.
677  var newWin = Desktop.createWindow(_winId++,_windows.length + _defaultWindowMinZindex,name,subname,url,
678  window_width,window_height,_dashboard.getDashboardWidth() + _currentLeft,_currentTop);
679 
680  //handle initial window left,top evolution
681  if(_currentLeft > _defaultLeft+_defaultOffsetTimes*_defaultLeftOffset)
682  {
683  _currentLeft = _defaultLeft;
684  if(_currentTop > _defaultTop + (_defaultOffsetTimes+1)*_defaultTopOffset)
685  _currentTop = _defaultTop;
686  else
687  _currentTop = _defaultTop + _defaultTopOffset;
688  }
689  else
690  {
691  _currentLeft += _defaultLeftOffset;
692  _currentTop += _defaultTopOffset;
693  }
694 
695  _windows.push(newWin); //add to windows array
696 
697  _desktopElement.appendChild(newWin.windiv); //add to desktop element and show on screen!
698 
699  Debug.log("Desktop Window Added with id " + _windows[_windows.length-1].getWindowId(),Debug.LOW_PRIORITY);
700 
701  _dashboard.updateWindows();
702 
703  //usually the foreground happens automatically.. but sometimes
704  // it doesn't (?)
705  //... so delay an extra setting of the fore window
706  window.setTimeout(function()
707  {
708  Desktop.desktop.setForeWindow(newWin);
709  Debug.log("extraStep=" + extraStep);
710  switch(extraStep)
711  {
712  case 1: //tile
713  Desktop.desktop.dashboard.windowDashboardOrganize();
714  break;
715  case 2: //maximize
716  Desktop.desktop.toggleFullScreen();
717  break;
718  default:; //do nothing for default
719  }
720 
721  }, 200);
722 
723  return newWin;
724  } //end addWindow()
725 
726  //==============================================================================
727  //getWindowById ~~~
728  // Find window by id
729  this.getWindowById = function(id)
730  {
731  for(var i=0;i<_windows.length;++i)
732  if(_windows[i].getWindowId() == id)
733  return _windows[i];
734  Debug.log("Window id="+id+" not found!",Debug.MED_PRIORITY);
735  return -1;
736  } //end getWindowById()
737 
738  //==============================================================================
739  //setForeWindow ~~~
740  // handle bringing window to front
741  this.setForeWindow = function(win)
742  {
743  //console.log("setForeWindow",win?win.getWindowId():-1);
744 
745  //resort by z and renumber - windows with Z out of range of array are due to iframe onFocus solution
746  var tmp;
747  for(var i=0;i<_windows.length-1;++i)
748  {
749  var min = i;
750  for(var j=i+1;j<_windows.length;++j)
751  if(_windows[j].getWindowZ() < _windows[min].getWindowZ())
752  min = j;
753 
754  //have min, swap to i
755  tmp = _windows[i];
756  _windows[i] = _windows[min];
757  _windows[min] = tmp;
758  _windows[i].setWindowZ(i+_defaultWindowMinZindex); //done with new window i
759  }
760  _windows[_windows.length-1].setWindowZ(_windows.length-1+_defaultWindowMinZindex); // last window still needs z-fixed
761  //_windowZmailbox = _defaultWindowMaxZindex; //reset windowZmailbox for next set of foci
762  //at this point windows are in standard Z arrangement
763 
764  //find win in windows array then bring to "top"
765  var found = 0;
766  for(var i=0;win && i<=_windows.length;++i)
767  { //only search, if win is valid (if not this function was likely called by timer watchdog _checkMailboxes())
768  if(found) //copy each window down within windows array
769  {
770  var winToMov = i<_windows.length?_windows[i]:win; //if to the end, put the win in question
771  winToMov.setWindowZ(i-1 + _defaultWindowMinZindex); //standardize window Z
772  _windows[i-1] = winToMov;
773  }
774  else if(_windows[i] == win) found = 1; //found!
775  }
776 
777  if(!found && win)
778  Debug.log("Desktop Foreground window not Found!! Window: " +
779  win.getWindowSubName());
780 
781  _dashboard.updateWindows();
782 
783  //if(win) Debug.log("Desktop Window Set to Foreground named " + win.getWindowSubName(),Debug.LOW_PRIORITY);
784  //else Debug.log("Desktop Foreground Window with no parameter",Debug.LOW_PRIORITY);
785  } //end setForeWindow()
786 
787  //==============================================================================
788  //closeWindowById ~~~
789  // Find window by id
790  this.closeWindowById = function(id)
791  {
792  var win = this.getWindowById(id);
793  if(win == -1) return -1;
794  _closeWindow(win);
795  } //end closeWindowById()
796 
797  //==============================================================================
798  //maximizeWindowById ~~~
799  // Find window by id
800  this.maximizeWindowById = function(id)
801  {
802  var win = this.getWindowById(id);
803  if(win == -1) return -1;
804  this.setForeWindow(win);
805  this.toggleFullScreen();
806  } //end maximizeWindowById()
807 
808  //==============================================================================
809  //toggleFullScreen ~~~
810  // Toggle current top window full screen (can be called as event)
811  this.toggleFullScreen = function(e)
812  {
813  if(!_getForeWindow()) return;
814 
815  _getForeWindow().isMaximized() ? _getForeWindow().unmaximize(): _getForeWindow().maximize();
816 
817  Desktop.desktop.redrawDashboardWindowButtons();
818 
819  //_dashboard.redrawFullScreenButton();
820  //_dashboard.redrawRefreshButton();
821  Debug.log("Full Screen Toggled",Debug.LOW_PRIORITY);
822  } //end toggleFullScreen()
823 
824  //==============================================================================
825  this.redrawDashboardWindowButtons = function()
826  {
827  _dashboard.redrawFullScreenButton();
828  _dashboard.redrawRefreshButton();
829  _dashboard.redrawShowDesktopButton();
830  } //end redrawDashboardWindowButtons()
831 
832  //==============================================================================
833  this.refreshWindowById = function(id)
834  {
835  var win = this.getWindowById(id);
836  if(win == -1) return -1;
837 
838  this.setForeWindow(win);
839  this.refreshWindow();
840  console.log("Finished refreshWindow() " + id);
841  } //end refreshWindowById()
842 
843  //==============================================================================
844  this.windowHelpById = function (id)
845  {
846  var win = this.getWindowById(id);
847  if (win == -1) return -1;
848 
849  this.setForeWindow(win);
850  var tempwin = Desktop.desktop.getForeWindow();
851 
852  console.log(tempwin);
853  console.log(tempwin.windiv);
854 
855  var tooltipEl;
856 
857  try //try no-frameset approach (if window is not in frame)
858  {
859  tooltipEl = tempwin.windiv.childNodes[2].childNodes[0].contentWindow.document.getElementById("otsDesktopWindowTooltipElement");
860  }
861  catch(e)
862  {
863  Debug.log("Ignoring error: " + e);
864  tooltipEl = 0;
865  }
866 
867  if(!tooltipEl)
868  {
869  try //try frameset approach (if window is in frame)
870  {
871  tooltipEl = tempwin.windiv.childNodes[2].childNodes[0].contentWindow.document.getElementsByTagName("frameset")[0].childNodes[0].contentWindow.document.getElementById("otsDesktopWindowTooltipElement");
872  }
873  catch(e)
874  {
875  Debug.log("Ignoring error: " + e);
876  tooltipEl = 0;
877  }
878  }
879 
880 
881  if(!tooltipEl)
882  {
883  DesktopContent.tooltip("ALWAYS", "There is no tooltip for the " + tempwin.getWindowName() +
884  " window. Try visiting <a href='https://otsdaq.fnal.gov' target='_blank'>otsdaq.fnal.gov</a> for further assistance.");
885  }
886  else
887  {
888  DesktopContent.tooltip("ALWAYS", decodeURIComponent(tooltipEl.innerText));
889  }
890  } //end windowHelpById()
891 
892  //==============================================================================
893  this.refreshWindow = function(e)
894  {
895  if(!_getForeWindow()) return;
896  //Debug.log("Windows Length: " + _windows.length);
897 
898  var window = _getForeWindow();
899  var id = window.getWindowId();
900  var z = window.getWindowZ();
901  var name = window.getWindowName();
902  var subname = window.getWindowSubName();
903  var url = window.getWindowUrl();
904  var width = window.getWindowWidth();
905  var height = window.getWindowHeight();
906  var x = window.getWindowX();
907  var y = window.getWindowY();
908  var isMax = window.isMaximized();
909  var isMin = window.isMinimized();
910 
911  _closeWindow(window);
912  console.log(window, id, z, name, width, height);
913 
914  var newWindow = this.addWindow(name,subname,url);
915  newWindow.setWindowSizeAndPosition(x,y,width,height);
916  newWindow.setWindowZ(z);
917 
918  if(isMax)
919  newWindow.maximize();
920  if(isMin)
921  newWindow.minimize();
922 
923  //Debug.log("Windows Length: " + _windows.length);
924 
925  return newWindow;
926  } //end refreshWindow()
927 
928  //==============================================================================
929  //minimizeWindowById ~~~
930  // Find window by id
931  this.minimizeWindowById = function(id) {
932  var win = this.getWindowById(id);
933  if(win == -1) return -1;
934 
935  this.setForeWindow(win);
936  this.toggleMinimize();
937  } //end minimizeWindowById()
938 
939  //==============================================================================
940  //toggleMinimize ~~~
941  // Toggle current top window minimize functionality (can be called as event)
942  this.toggleMinimize = function(e) {
943  if(!_getForeWindow()) return;
944 
945  if(_getForeWindow().isMinimized())
946  _getForeWindow().unminimize();
947  else
948  _getForeWindow().minimize();
949  Debug.log("Minimize Toggled",Debug.LOW_PRIORITY);
950  //_dashboard.updateWindows();
951 
952  } //end toggleMinimize()
953 
954 
955  //==============================================================================
956  //clickedWindowDashboard ~~~
957  // Handle window selection using dashboard
958  this.clickedWindowDashboard = function(id) {
959  var win = this.getWindowById(id);
960  if(win == -1) return -1;
961  if(_getForeWindow() != win) { //if not currently foreground window, set as only
962  if(_getForeWindow().isMaximized()) this.toggleFullScreen(); //if old foreground is full screen, toggle
963  this.setForeWindow(win);
964  if(_getForeWindow().isMinimized()) this.toggleMinimize(); //if new foreground is minimized, toggle
965  return;
966  }
967  //else minimize
968  this.toggleMinimize();
969  } //end clickedWindowDashboard()
970 
971  //==============================================================================
972  //setDefaultWindowColor() ~~~
973  // set background color for all windows
974  this.setDefaultWindowColor = function(color) {
975  this.defaultWindowFrameColor = color;
976  //_windowColorPostbox.innerHTML = this.defaultWindowFrameColor; //set to color string
977 
978  for(var i=0;i<_windows.length;++i)
979  _windows[i].windiv.style.backgroundColor = this.defaultWindowFrameColor;
980  }
981 
982  //defaultLayoutSelect() ~~~
983  // set default layout of windows
984  // 0-1 are system defaults
985  // 3-5 are user defaults
986  // 6 is last saved layout checkpoint
987  this.defaultLayoutSelect = function(i) {
988  Debug.log("Desktop defaultLayoutSelect " + i,Debug.LOW_PRIORITY);
989 
990  var layoutStr;
991  var numOfUserLayouts = 5;
992  var numOfSystemLayouts = 5;
993  if(i >= numOfSystemLayouts+1 && //user layouts
994  i <= numOfSystemLayouts+1+numOfUserLayouts)
995  layoutStr = _login.getUserDefaultLayout(i-(numOfSystemLayouts+1));
996  else if(i >= 0 && i <= numOfSystemLayouts) //system layouts
997  layoutStr = _login.getSystemDefaultLayout(i);
998  else //invalid
999  {
1000  Debug.log("Invalid layout index: " + i, Debug.HIGH_PRIORITY);
1001  return;
1002  }
1003  var layoutArr = layoutStr.split(",");
1004 
1005  var numOfFields = 8;
1006  var numOfWins = parseInt(layoutArr.length/numOfFields);
1007 
1008  Debug.log("Desktop defaultLayoutSelect layout numOfFields=" + numOfFields);
1009  Debug.log("Desktop defaultLayoutSelect layout " + numOfWins +
1010  " windows - " + layoutStr);
1011 
1012  //clear all current windows
1013  Desktop.desktop.closeAllWindows();
1014 
1015  //open chosen default layout
1016  // Note: represent position in terms of 0-10000 for the entire Desktop Content area
1017  // - this should allow for translation to any size Desktop Content area when loaded
1018  //
1019  // layout window fields:
1020  // 0: _windows[i].getWindowName()
1021  // 1: _windows[i].getWindowSubName()
1022  // 2: _windows[i].getWindowUrl().replace(/&/g,'%38').replace(/=/g,'%61') //global replace & and =
1023  // 3: (((_windows[i].getWindowX()-dx)/dw)|0)
1024  // 4: (((_windows[i].getWindowY()-dy)/dh)|0)
1025  // 5: ((_windows[i].getWindowWidth()/dw)|0)
1026  // 6: ((_windows[i].getWindowHeight()/dh)|0)
1027  // 7: (_windows[i].isMinimized()?"0":(_windows[i].isMinimized()?"2":"1"))
1028  var dw = Desktop.desktop.getDesktopContentWidth()/10000.0; //to calc int % 0-10000
1029  var dh = Desktop.desktop.getDesktopContentHeight()/10000.0;//to calc int % 0-10000
1030  var dx = Desktop.desktop.getDesktopContentX();
1031  var dy = Desktop.desktop.getDesktopContentY();
1032  for(i=0;i<numOfWins;++i)
1033  {
1034  Debug.log("adding " + layoutArr[i*numOfFields].substr(1) + "-" + layoutArr[i*numOfFields+1],Debug.LOW_PRIORITY);
1035  this.addWindow( //(name,subname,url,unique)
1036  decodeURIComponent(layoutArr[i*numOfFields]),
1037  decodeURIComponent(layoutArr[i*numOfFields+1]),
1038  decodeURIComponent(layoutArr[i*numOfFields+2]),//.replace(/%38/g,"&").replace(/%61/g,"="), //replace back = and &
1039  false);
1040  _windows[_windows.length-1].setWindowSizeAndPosition( //(x,y,w,h)
1041  layoutArr[i*numOfFields+3]*dw + dx,
1042  layoutArr[i*numOfFields+4]*dh + dy,
1043  layoutArr[i*numOfFields+5]*dw,
1044  layoutArr[i*numOfFields+6]*dh);
1045 
1046  if((layoutArr[i*numOfFields+7]|0) == 0) //convert to integer, if 0 then minimize
1047  _windows[_windows.length-1].minimize();
1048  else if((layoutArr[i*numOfFields+7]|0) == 2) //convert to integer, if 0 then maximize
1049  _windows[_windows.length-1].maximize();
1050  }
1051  } //end defaultLayoutSelect()
1052 
1053  //==============================================================================
1054  //closeAllWindows() ~~~
1055  // close all windows is used when default layout is changed or a new user logs in
1056  this.closeAllWindows = function()
1057  {
1058  Debug.log("Desktop closeAllWindows",Debug.LOW_PRIORITY);
1059  //clear all current windows
1060  while(_windows.length) _closeWindow(_windows[_windows.length-1]);
1061  } //end closeAllWindows()
1062 
1063  //==============================================================================
1064  //resetDesktop() ~~~
1065  // called by successful login to reset desktop based on user's permissions
1066  this.resetDesktop = function(permissions)
1067  {
1068  Debug.log("reset desktop()");
1069 
1070  //_needToLoginMailbox.innerHTML = ""; //reset mailbox
1071  //_blockSystemCheckMailbox.innerHTML = ""; //reset mailbox
1072  _sysMsgCounter = 0; //reset system message counter
1073 
1074  //update icons based on permissions (if undefined, keep permissions from before)
1075  Desktop.desktop.icons.resetWithPermissions(permissions);
1076 
1077  //if not logged in -- attempt to fix it
1078  if(!Desktop.desktop.serverConnected &&
1079  (!Desktop.desktop.login ||
1080  !Desktop.desktop.login.getCookieCode(true)))
1081  {
1082  Debug.log("Reset is setting up login...");
1083  Desktop.desktop.login.setupLogin();
1084  }
1085 
1086  //re-start timer for checking foreground window changes due to iFrame content code
1087 
1088  window.clearTimeout(Desktop.desktop.checkMailboxTimer);
1089  _checkMailboxes();
1090 
1091  //setup lock the first time
1092  if(Desktop.desktop.login.getCookieCode(true))
1093  Desktop.XMLHttpRequest("Request?RequestType=getSystemMessages","",
1094  _handleSystemMessages);
1095 
1096  } //end resetDesktop()
1097 
1098  //==============================================================================
1099  //refreshDesktop() ~~~
1100  this.refreshDesktop = function()
1101  {
1102  for(var i=0; i<Desktop.desktop.getNumberOfWindows();++i)
1103  Desktop.desktop.refreshWindowById(Desktop.desktop.getWindowByIndex(i));
1104 
1105  } //end refreshDesktop()
1106 
1107  //actOnParameterAction() ~~~
1108  // called during create desktop to handle any shortcuts to windows being maximized
1109  this.actOnParameterAction = function()
1110  {
1111 
1112  //get parameters
1113  var paramsStr = window.parent.window.location.search.substr(1); //skip the '?'
1114  var params = [];
1115  var paramCnt = 5 + (Desktop.isWizardMode()?1:0); //1 extra param in wiz mode
1116  var spliti, splitiOld = 0;
1117  for(var i=0;i<paramCnt;++i)
1118  {
1119  if(i == paramCnt-1) //last one take the whole thing (this is path, and could have &'s in it)
1120  {
1121  params.push(paramsStr.substr(splitiOld));
1122  break;
1123  }
1124  //for others, handle like normal get param
1125  spliti = paramsStr.indexOf('&', splitiOld);
1126  params.push(paramsStr.substr(splitiOld,spliti-splitiOld))
1127  splitiOld = spliti+1;
1128  }
1129 
1130  var varPair;
1131  var requestingWindowId = "", windowPath = "";
1132  var windowName, windowSubname, windowUnique, newWindowOps;
1133  for(var i=0;i<params.length;++i)
1134  {
1135  spliti = params[i].indexOf('=');
1136  varPair = [params[i].substr(0,spliti),params[i].substr(spliti+1)];
1137  if(varPair[0] == "requestingWindowId")
1138  requestingWindowId = varPair[1];
1139  else if(varPair[0] == "windowPath")
1140  windowPath = decodeURIComponent(varPair[1]);
1141  else if(varPair[0] == "windowName")
1142  windowName = varPair[1];
1143  else if(varPair[0] == "windowSubname")
1144  windowSubname = varPair[1];
1145  else if(varPair[0] == "windowUnique")
1146  windowUnique = varPair[1];
1147  }
1148 
1149  if(windowPath.indexOf("newWindowOps") >= 0)
1150  {
1151  //extract newWindowOps
1152  newWindowOps = windowPath.split('&')[1].split('=')[1];
1153  windowPath = windowPath.split('&')[0];
1154  }
1155 
1156 // for(var i=0;i<params.length;++i)
1157 // {
1158 // spliti = params[i].indexOf('=');
1159 // varPair = [params[i].substr(0,spliti),params[i].substr(spliti+1)];
1160 // Debug.log(i + ": " + varPair[0] + "=" + varPair[1]);
1161 // if(varPair[0] == "requestingWindowId")
1162 // requestingWindowId = varPair[1];
1163 // else if(varPair[0] == "windowPath")
1164 // windowPath = decodeURIComponent(varPair[1]);
1165 // else if(varPair[0] == "windowName")
1166 // windowName = varPair[1];
1167 // else if(varPair[0] == "windowSubname")
1168 // windowSubname = varPair[1];
1169 // else if(varPair[0] == "windowUnique")
1170 // windowUnique = varPair[1];
1171 // else if(varPair[0] == "newWindowOps")
1172 // newWindowOps = varPair[1];
1173 // }
1174 
1175  if(requestingWindowId != "" && windowPath != "")
1176  {
1177  //have work to do!
1178  //Debug.log("_openWindowMailbox.innerHTML=" + _openWindowMailbox.innerHTML);
1179  Debug.log("requestingWindowId=" + requestingWindowId);
1180  Debug.log("windowPath=" + windowPath);
1181  if(newWindowOps) newWindowOps = newWindowOps.replace(/%22/g, "\"");
1182  Debug.log("newWindowOps=" + newWindowOps);
1183  windowName = windowName.replace(/%20/g, " ");
1184  Debug.log("windowName=" + windowName);
1185  windowSubname = windowSubname.replace(/%20/g, " ");
1186  Debug.log("windowSubname=" + windowSubname);
1187  Debug.log("windowUnique=" + windowUnique);
1188 
1189  var newWin;
1190 
1191 
1192  //check if opening layout
1193  if(windowName.indexOf("Desktop.openLayout(") == 0)
1194  {
1195  var layoutIndex = windowName.substr(("Desktop.openLayout(").length,
1196  windowName.length-1-("Desktop.openLayout(").length) | 0;
1197  Debug.log("Opening layout... " + layoutIndex);
1198 
1199  if(pathUniquePair ===
1200  undefined)
1201  {
1202 
1203  if(_firstCheckOfMailboxes)
1204  {
1205  Debug.log("Perhaps user layout preferences have not been setup yet, try again at mailbox check.");
1206  return;
1207  }
1208  }
1209 
1210 
1211  _firstCheckOfMailboxes = false; //no need to check at mailbox check time, we are good to go already!
1212 
1213  Desktop.desktop.dashboard.toggleWindowDashboard(0,false);
1214  Desktop.desktop.defaultLayoutSelect(layoutIndex);
1215  return;
1216  } //end openLayout handling
1217 
1218  //if only windowName is defined, then attempt to open the icon on the
1219  // Desktop with that name (this helps resolve supervisor LIDs, etc.)
1220  if(windowSubname == "undefined" &&
1221  windowUnique == "undefined") //the string undefined is what comes through
1222  {
1223  Debug.log("Opening desktop window... " + windowName);
1224 
1225 
1226  var pathUniquePair = Desktop.desktop.icons.iconNameToPathMap[windowName];
1227  console.log("Desktop.desktop.icons.iconNameToPathMap",
1228  Desktop.desktop.icons.iconNameToPathMap);
1229 
1230  if(pathUniquePair ===
1231  undefined)
1232  {
1233 
1234  if(_firstCheckOfMailboxes)
1235  {
1236  Debug.log("Perhaps icons have not been setup yet, try again at mailbox check.");
1237  return;
1238  }
1239 
1240  Debug.log("An error occurred opening the window named '" +
1241  windowName + "' - it was not found in the Desktop icons. " +
1242  "Do you have permissions to access this window? Notify admins if the problem persists.",
1243  Debug.HIGH_PRIORITY);
1244 
1245  //respond done
1246  //clear mailbox string since no window is listening for done when a new desktop begins
1247  //_openWindowMailbox.innerHTML = "";//str; //indicate done
1248  return;
1249  }
1250  var pathStr = pathUniquePair[0];
1251 
1252  if(windowPath != "undefined") //add parameters if defined
1253  {
1254  Debug.log("Adding parameter path " + windowPath);
1255 
1256  if(pathStr.indexOf('&amp;') > 0) //then assume already parameters
1257  pathStr += "&amp;";
1258  else if(pathStr.indexOf('?') > 0 && //then assume & for parameters is good
1259  pathStr[pathStr.length-1] != '?')
1260  pathStr += "&";
1261  else if(pathStr.length &&
1262  pathStr[pathStr.lengh-1] != '?') //then assume need ?
1263  pathStr += '?';
1264  windowPath = pathStr + windowPath;
1265  }
1266  else
1267  windowPath = pathStr;
1268 
1269  newWin = Desktop.desktop.addWindow( //(name,subname,url,unique)
1270  windowName,
1271  "",
1272  windowPath + //e.g. "http://rulinux03.dhcp.fnal.gov:1983/WebPath/html/ConfigurationGUI.html?urn=280",
1273  ((windowPath.indexOf('?') < 0)? "?":"&amp;") + //add ? start of get parameters if necessary
1274  ((newWindowOps)?"newWindowOps=" + newWindowOps:""), //add get parameter to path for further operations
1275  eval(pathUniquePair[1]));
1276  } //end handling of opening desktop window
1277  else
1278  {
1279  _firstCheckOfMailboxes = false; //no need to check at mailbox check time, we are good to go already!
1280  newWin = Desktop.desktop.addWindow( //(name,subname,url,unique)
1281  windowName,
1282  windowSubname,
1283  windowPath + //e.g. "http://rulinux03.dhcp.fnal.gov:1983/WebPath/html/ConfigurationGUI.html?urn=280",
1284  ((windowPath.indexOf('?') < 0)? "?":"&amp;") + //add ? start of get parameters if necessary
1285  ((newWindowOps)?"newWindowOps=" + newWindowOps:""), //add get parameter to path for further operations
1286  eval(windowUnique));
1287  }
1288 
1289  //set to fore window and full screen
1290 
1291  Desktop.desktop.dashboard.toggleWindowDashboard(0,false);
1292 
1293  //delay the setting of the fore window and fullscreen
1294  // so that the window exists before changing it
1295  window.setTimeout(function(){
1296  Desktop.desktop.setForeWindow(newWin);
1297  Desktop.desktop.toggleFullScreen();
1298  }, 200);
1299 
1300  //clear mailbox string since no window is listening for done when a new desktop begins
1301  //_openWindowMailbox.innerHTML = "";//str; //indicate done
1302  }
1303  } //end actOnParameterAction()
1304 
1305  //------------------------------------------------------------------
1306  //handle class construction ----------------------
1307  //------------------------------------------------------------------
1308 
1309  //create a div just to direct style properly to contents of Desktop
1310  _desktopElement = document.createElement("div");
1311  _desktopElement.setAttribute("id", "Desktop");
1312  document.body.appendChild(_desktopElement);
1313  document.body.onmousemove = Desktop.handleBodyMouseMove;
1314  window.onmouseup = Desktop.handleWindowMouseUp; //added to fix firefox mouseup glitch with window moving
1315  document.body.addEventListener('touchmove',Desktop.handleBodyTouchMove);
1316  document.body.addEventListener('touchend',Desktop.handleBodyTouchEnd);
1317  window.onresize = _handleDesktopResize;
1318  Desktop.desktop = this;
1319 
1320 // //create windowZmailbox for focus switching through iFrame
1321 // _windowZmailbox = document.createElement("div");
1322 // _windowZmailbox.setAttribute("id", "Desktop-windowZmailbox");
1323 // _windowZmailbox.innerHTML = _defaultWindowMaxZindex;
1324 // _windowZmailbox.style.display = "none";
1325 // _desktopElement.appendChild(_windowZmailbox);
1326 
1327 // //create mouseOverXmailbox for focus switching through iFrame
1328 // _mouseOverXmailbox = document.createElement("div");
1329 // _mouseOverXmailbox.setAttribute("id", "Desktop-mouseOverXmailbox");
1330 // _mouseOverXmailbox.style.display = "none";
1331 // _desktopElement.appendChild(_mouseOverXmailbox);
1332 //
1333 // //create mouseOverYmailbox for focus switching through iFrame
1334 // _mouseOverYmailbox = document.createElement("div");
1335 // _mouseOverYmailbox.setAttribute("id", "Desktop-mouseOverYmailbox");
1336 // _mouseOverYmailbox.style.display = "none";
1337 // _desktopElement.appendChild(_mouseOverYmailbox);
1338 
1339  this.resetFrameMouse();
1340 
1341  //create mailboxes for Window content code
1342 // var tmpHiddenDiv = document.createElement("div");
1343 // tmpHiddenDiv.setAttribute("id", "DesktopContent-cookieCodeMailbox");
1344 // tmpHiddenDiv.style.display = "none";
1345 // _desktopElement.appendChild(tmpHiddenDiv);
1346 // _updateTimeMailbox = document.createElement("div");
1347 // _updateTimeMailbox.setAttribute("id", "DesktopContent-updateTimeMailbox");
1348 // _updateTimeMailbox.style.display = "none";
1349 // _desktopElement.appendChild(_updateTimeMailbox);
1350 // _needToLoginMailbox = document.createElement("div");
1351 // _needToLoginMailbox.setAttribute("id", "DesktopContent-needToLoginMailbox");
1352 // _needToLoginMailbox.style.display = "none";
1353 // _desktopElement.appendChild(_needToLoginMailbox);
1354 
1355 // _blockSystemCheckMailbox = document.createElement("div");
1356 // _blockSystemCheckMailbox.setAttribute("id", "DesktopContent-blockSystemCheckMailbox");
1357 // _blockSystemCheckMailbox.style.display = "none";
1358 // _desktopElement.appendChild(_blockSystemCheckMailbox);
1359 
1360 
1361 
1362  //create mailbox for opening windows from Desktop Windows
1363 // _openWindowMailbox = document.createElement("div");
1364 // _openWindowMailbox.setAttribute("id", "DesktopContent-openWindowMailbox");
1365 // _openWindowMailbox.style.display = "none";
1366 // _desktopElement.appendChild(_openWindowMailbox);
1367 
1368  //create mailbox for settings update
1369  _updateSettingsMailbox = document.createElement("div");
1370  _updateSettingsMailbox.setAttribute("id", "DesktopContent-updateSettingsMailbox");
1371  _updateSettingsMailbox.style.display = "none";
1372  _updateSettingsMailbox.innerHTML = ""; //init to empty
1373  _desktopElement.appendChild(_updateSettingsMailbox);
1374  _settingsLayoutMailbox = document.createElement("div");
1375  _settingsLayoutMailbox.setAttribute("id", "DesktopContent-settingsLayoutMailbox");
1376  _settingsLayoutMailbox.style.display = "none";
1377  _settingsLayoutMailbox.innerHTML = ""; //init to empty
1378  _desktopElement.appendChild(_settingsLayoutMailbox);
1379 
1380  //create postbox for chosen color settings
1381 // _windowColorPostbox = document.createElement("div");
1382 // _windowColorPostbox.setAttribute("id", "DesktopContent-windowColorPostbox");
1383 // _windowColorPostbox.style.display = "none";
1384 // _windowColorPostbox.innerHTML = this.defaultWindowsFrameColor; //init to color string
1385 // _desktopElement.appendChild(_windowColorPostbox);
1386 
1387 
1388  //create message request listener from desktop windows, to overcome same-origin policy
1389  window.addEventListener('message', event => {
1390 
1391  console.log("Parent event.data",event.data);
1392 
1393  if(event.data.windowId === undefined)
1394  {
1395  Debug.log("Illegal window message received! Notify admins", Debug.HIGH_PRIORITY);
1396  return;
1397  }
1398 
1399  var responseObject;
1400  switch(event.data.request)
1401  {
1402  case "updateMouseoverXY":
1403  //add window frame position(absolute) + iframe position within window + mouse position within iframe
1404  var el = document.getElementById("DesktopWindowFrame-" + event.data.windowId);
1405  if(el)
1406  {
1407  _mouseOverXmailbox = parseInt(el.parentNode.parentNode.offsetLeft) +
1408  parseInt(el.offsetLeft) + parseInt(event.data.x);
1409  _mouseOverYmailbox = parseInt(el.parentNode.parentNode.offsetTop) +
1410  parseInt(el.offsetTop) + parseInt(event.data.y);
1411  }
1412  else
1413  {
1414  _mouseOverXmailbox = event.data.x|0;
1415  _mouseOverYmailbox = event.data.y|0;
1416  }
1417  console.log("updateMouseoverXY",_mouseOverXmailbox,_mouseOverYmailbox);
1418  break;
1419  case "makeForeWindow":
1420  //console.log("makeForeWindow",event.data.windowId);
1421  Desktop.desktop.setForeWindow(this.getWindowById(event.data.windowId|0));
1422  break;
1423  case "openNewWindow":
1424  console.log("openNewWindow");
1425 
1426  var requestingWindowId = event.data.windowId|0;
1427  var windowPath = event.data.windowPath;
1428  var windowName = event.data.windowName;
1429  var windowSubname = event.data.windowSubname;
1430  var windowUnique = event.data.windowUnique;
1431 
1432  if(windowPath != "")
1433  {
1434  //have work to do!
1435  // Note: similar to L1000 in actOnParameterAction()
1436  console.log("requestingWindowId=" + requestingWindowId);
1437  console.log("windowPath=" + windowPath);
1438  while(windowPath.length && windowPath[0] == '?') windowPath = windowPath.substr(1); //remove leading ?'s
1439  console.log("modified windowPath=" + windowPath);
1440  console.log("windowName=" + windowName);
1441  console.log("windowSubname=" + windowSubname);
1442  console.log("windowUnique=" + windowUnique);
1443 
1444  var newWin;
1445 
1446  //if only windowName is defined, then attempt to open the icon on the
1447  // Desktop with that name (this helps resolve supervisor LIDs, etc.)
1448  if((windowSubname === undefined || windowSubname == "undefined") &&
1449  (windowUnique === undefined || windowUnique == "undefined")) //the string undefined is what comes through
1450  {
1451  console.log("Opening desktop window... " + windowName);
1452 
1453  var pathUniquePair = Desktop.desktop.icons.iconNameToPathMap[windowName];
1454  console.log("Desktop.desktop.icons.iconNameToPathMap",
1455  Desktop.desktop.icons.iconNameToPathMap);
1456 
1457  if(pathUniquePair ===
1458  undefined)
1459  {
1460  Debug.log("An error occurred opening the window named '" +
1461  windowName + "' - it was not found in the Desktop icons. " +
1462  "Do you have permissions to access this window? Notify admins if the problem persists.",
1463  Debug.HIGH_PRIORITY);
1464 
1465  //respond done
1466 // var str = "requestingWindowId=" + requestingWindowId;
1467 // str += "&done=1";
1468 // _openWindowMailbox.innerHTML = str; //indicate done
1469 
1470  return;
1471  }
1472 
1473  var pathStr = pathUniquePair[0];
1474 
1475  if(windowPath != "undefined") //add parameters if defined
1476  {
1477  Debug.log("Adding parameter path " + windowPath);
1478  if(pathStr.indexOf('?') >= 0) //then assume already parameters
1479  pathStr += "&";
1480  else if(pathStr.length) //then assume need ?
1481  pathStr += '?';
1482  windowPath = pathStr + windowPath;
1483  }
1484  else
1485  windowPath = pathStr;
1486 
1487  newWin = Desktop.desktop.addWindow( //(name,subname,url,unique)
1488  windowName,
1489  "",
1490  windowPath, //e.g. "http://rulinux03.dhcp.fnal.gov:1983/WebPath/html/ConfigurationGUI.html?urn=280",
1491  eval(pathUniquePair[1]));
1492  }
1493  else
1494  {
1495  newWin = Desktop.desktop.addWindow( //(name,subname,url,unique)
1496  windowName,
1497  windowSubname,
1498  windowPath, //e.g. "http://rulinux03.dhcp.fnal.gov:1983/WebPath/html/ConfigurationGUI.html?urn=280",
1499  eval(windowUnique));
1500  }
1501 
1502  //delay the setting of the fore window
1503  window.setTimeout(function(){ Desktop.desktop.setForeWindow(newWin); }, 200);
1504 
1505 // var str = "requestingWindowId=" + requestingWindowId;
1506 // str += "&done=1";
1507 // _openWindowMailbox.innerHTML = str; //indicate done
1508  }
1509 
1510  break;
1511  case "refreshIcons":
1512  console.log("refreshIcons");
1513 
1514  //reset icons, if permissions undefined, keep permissions from before
1515  Desktop.desktop.icons.resetWithPermissions(
1516  undefined /*undefined permissions*/, true /*keepSamePermissions*/);
1517 
1518  break;
1519  case "startSystemBlackout":
1520  console.log("startSystemBlackout");
1521  //windows can request a blackout, to avoid logging out (attempt to stop all other tabs by using browser cookie)
1522  Desktop.desktop.login.blackout(true);
1523  break;
1524  case "stopSystemBlackout":
1525  console.log("stopSystemBlackout");
1526  Desktop.desktop.login.blackout(false);
1527  break;
1528  case "getCookieCode":
1529  responseObject = {
1530  "cookieCode": Desktop.desktop.login.getCookieCode()
1531  };
1532  console.log("getCookieCode");
1533  break;
1534  case "updateCookieCode":
1535  //do ms compare to decide if desktop cookie code should be updated with some throttling
1536  var delta = parseInt(event.data.cookieCodeTime) - parseInt(Desktop.desktop.login.getCookieTime());
1537 
1538  console.log("updateCookieCode",delta);
1539  if(delta > 5*1000 /*ms*/) //update based on content value
1540  {
1541  Debug.log("Updating desktop cookie code from content window");
1542  Desktop.desktop.login.updateCookieFromContent(
1543  event.data.cookieCode,
1544  parseInt(event.data.cookieCodeTime));
1545  }
1546  break;
1547  case "needToLogin":
1548  console.log("needToLogin");
1549 
1550  if(!document.getElementById("Desktop-loginDiv") &&
1551  !Desktop.desktop.login.isBlackout())
1552  {
1553  //only signal logout if login div is gone (login complete)
1554  Debug.log("DesktopContent signaled new login needed!",Debug.HIGH_PRIORITY);
1555  Desktop.logout();
1556  }
1557  else
1558  Debug.log("Ignoring desktop content need for login signal due to blackout.");
1559 
1560  break;
1561  default:
1562  Debug.log("Illegal window message request received! Notify admins", Debug.HIGH_PRIORITY);
1563  return;
1564  }
1565 
1566  if(responseObject !== undefined) //send response back
1567  {
1568  //send message to window (add windowId for 'security')
1569  responseObject["windowId"] = event.data.windowId;
1570  responseObject["request"] = event.data.request + "Response";
1571  console.log("responseObject",responseObject);
1572  this.getWindowById(event.data.windowId|0).getFrame().contentWindow.postMessage(
1573  responseObject,"*");
1574 
1575  }
1576  }); //end Desktop window message listener
1577 
1578 
1579  //add dashboard
1580  this.dashboard = _dashboard = Desktop.createDashboard(_defaultDashboardZindex);
1581  _desktopElement.appendChild(_dashboard.dashboardElement);
1582 
1583  //add icons
1584  this.icons = _icons = Desktop.createIcons(0);
1585  _desktopElement.appendChild(_icons.iconsElement);
1586 
1587  _handleDesktopResize();
1588 
1589  window.clearTimeout(this.checkMailboxTimer);
1590  this.checkMailboxTimer = window.setTimeout(_checkMailboxes,_MAILBOX_TIMER_PERIOD); //start timer for checking foreground window changes due to iFrame content code
1591 
1592  //add login
1593  this.login = _login = new Desktop.login(!(this.security == Desktop.SECURITY_TYPE_NONE)); //pass true to enable login
1594  if(_login.loginDiv)
1595  _desktopElement.appendChild(_login.loginDiv); //add to desktop element for login to display things
1596 
1597  Debug.log("Desktop Created",Debug.LOW_PRIORITY);
1598 
1599  Debug.log("Checking for any shortcut work from get parameters...",Debug.LOW_PRIORITY);
1600  Desktop.desktop.actOnParameterAction(); //first time, _firstCheckOfMailboxes is true (then it will try again in checkMailboxes)
1601 } //end Desktop constructor
1602 
1605 //define Desktop mouse helper functions
1608 
1609 Desktop.foreWinLastMouse = [-1,-1];
1610 Desktop.winManipMode = -1;
1611 Desktop.stretchAndMoveInterval = 0; //used to stretch and move even while moving over iFrames
1612 Desktop.disableMouseDown = 0;
1613 
1615 
1616 //==============================================================================
1617 //Desktop.handleTouchStart ~~
1618 // touch start is called before mouse down, so need to prepare mousedown
1619 // as though mousemove has been called. Only allow moving window.
1620 // Disallow dashboard resizing.
1621 Desktop.handleTouchStart = function(touchEvent)
1622 {
1623  Desktop.disableMouseDown = 1; //Disable mouse down on windows if touches are happening
1624  var touch = touchEvent.targetTouches[0];
1625 
1626  var winId = this.id.split('-')[1]; //get id string from div container id
1627  var isDashboard = (winId == "windowDashboard");
1628  var win;
1629  if(!isDashboard)
1630  {
1631  win = Desktop.desktop.getWindowById(winId);
1632  if(win == -1) return false;
1633  if(win.isMaximized()) {this.style.cursor = "default";return false;}
1634 
1635  //bring window to front if newly selected
1636  if(Desktop.desktop.getForeWindow() != win)
1637  Desktop.desktop.setForeWindow(win);
1638  }
1639  else return false; //disable dashboard sizing
1640 
1641  //if not manipulating the foreground window
1642  if(Desktop.foreWinLastMouse[0] == -1)
1643  {
1644  var locX = touch.pageX - this.offsetLeft;
1645  var locY = touch.pageY - this.offsetTop;
1646 
1647  //Debug.log("Touch Down " + locX + " - " + locY);
1648 
1649  Desktop.desktop.getForeWindow().hideFrame();
1650 
1651  Desktop.foreWinLastMouse = [touch.pageX,touch.pageY];
1652 
1653  if(locY < win.getWindowHeaderHeight())
1654  { //move
1655  Desktop.winManipMode = 0;
1656  }
1657  }
1658 
1659  return false; //to disable drag and drops
1660 } //end handleTouchStart()
1661 
1662 //==============================================================================
1663 //Desktop.handleTouchEnd ~~
1664 // determine starting mouse position of move or resize
1665 Desktop.handleBodyTouchEnd = function(touchEvent) {Desktop.handleTouchEnd(touchEvent);}
1666 Desktop.handleTouchEnd = function(touchEvent)
1667 {
1668 
1669  if(Desktop.foreWinLastMouse[0] != -1) //action was happening
1670  {
1671  Desktop.foreWinLastMouse = [-1,-1];
1672  Desktop.winManipMode = -1;
1673  if(Desktop.desktop.getForeWindow()) Desktop.desktop.getForeWindow().showFrame();
1674  //Debug.log("Touch End ");
1675  }
1676 } //end handleTouchEnd()
1677 
1678 //==============================================================================
1679 //Desktop.handleTouchMove ~~
1680 // determine starting mouse position of move or resize
1681 Desktop.handleBodyTouchMove = function(touchEvent) {Desktop.handleTouchMove(touchEvent);}
1682 Desktop.handleTouchMove = function(touchEvent)
1683 {
1684  if(Desktop.winManipMode != -1 && Desktop.foreWinLastMouse[0] != -1) //action happen now
1685  {
1686  touchEvent.preventDefault(); //fix chrome issue of only 2 fires
1687  touchEvent.cancelBubble=true; //eat event away so scrolling doesnt happen
1688 
1689  var touch = touchEvent.targetTouches[0];
1690  var delta = [touch.pageX-Desktop.foreWinLastMouse[0], touch.pageY-Desktop.foreWinLastMouse[1]];
1691  //Debug.log("Touch move " + delta[0] + " , " + delta[1]);
1692  Desktop.desktop.getForeWindow().moveWindowByOffset(delta[0],delta[1]);
1693  Desktop.foreWinLastMouse = [touch.pageX,touch.pageY];
1694  }
1695 } //end handleTouchMove()
1697 
1698 //==============================================================================
1699 //Desktop.handleWindowMouseDown ~~
1700 // determine starting mouse position of move or resize
1701 Desktop.handleWindowMouseDown = function(mouseEvent)
1702 {
1703  var winId = this.id.split('-')[1]; //get id string from div container id
1704  var isDashboard = (winId == "windowDashboard");
1705  var win;
1706  if(!isDashboard)
1707  {
1708  win = Desktop.desktop.getWindowById(winId);
1709  if(win == -1) return false;
1710 
1711  //bring window to front if newly selected
1712  if(Desktop.desktop.getForeWindow() != win)
1713  Desktop.desktop.setForeWindow(win);
1714  }
1715 
1716  //touches can disable window mouse ops
1717  if(!Desktop.disableMouseDown && Desktop.winManipMode != -1 && this.style.cursor != "default") //if moving or resizing window
1718  {
1719  //register move cursor and window in question
1720  Desktop.foreWinLastMouse = [mouseEvent.clientX,mouseEvent.clientY];
1721  if(!isDashboard) Desktop.desktop.getForeWindow().hideFrame();
1722  //Debug.log("Move/Resize Mode: " + Desktop.winManipMode);
1723  }
1724 
1725  //if(!isDashboard) Debug.log("Mouse Down WinId:" + win.getWindowId() + " - " + this.style.cursor,Debug.LOW_PRIORITY);
1726 
1727  return false; //to disable drag and drops
1728 } //end handleWindowMouseDown()
1729 
1730 //==============================================================================
1731 //handleWindowMouseUp ~~
1732 // indicate that no further movement is happening
1733 Desktop.handleWindowMouseUp = function(mouseEvent)
1734 {
1735 
1736  if(Desktop.foreWinLastMouse[0] != -1) //currently action happening on foreground window
1737  {
1738  if(Desktop.stretchAndMoveInterval)
1739  {
1740  window.clearInterval(Desktop.stretchAndMoveInterval); //kill interval iframe mouse watchdog
1741  Desktop.stretchAndMoveInterval = 0;
1742 
1743  //stop needing mouse xy from desktop windows
1744  var reqObject = {"request": "stopNeedingMouseXY"};
1745  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i)
1746  {
1747  reqObject["windowId"] = Desktop.desktop.getWindowByIndex(i).getWindowId();
1748  Desktop.desktop.getWindowByIndex(i).getFrame().contentWindow.postMessage(
1749  reqObject,"*");
1750  }
1751  }
1752 
1753  Desktop.foreWinLastMouse = [-1,-1]; //indicate no movements happening
1754  Desktop.winManipMode = -1;
1755  if(Desktop.desktop.getForeWindow()) Desktop.desktop.getForeWindow().showFrame();
1756 
1757  //Debug.log("Mouse was released! which=" + mouseEvent.which);
1758  }
1759  Desktop.desktop.icons.closeFolder();
1760  return false;
1761 } //end handleWindowMouseUp()
1762 
1763 //==============================================================================
1764 //handle window move and resize
1765 Desktop.handleWindowMouseMove = function(mouseEvent)
1766 {
1767  var winId = this.id.split('-')[1]; //get id string from div container id
1768  var isDashboard = (winId == "windowDashboard");
1769  var win;
1770  if(!isDashboard){
1771  win = Desktop.desktop.getWindowById(winId);
1772  if(win == -1) return false;
1773  if(win.isMaximized()) {this.style.cursor = "default";return false;}
1774  }
1775 
1776  //change mouse cursor if over a window object and not manipulating the foreground window
1777  if(Desktop.foreWinLastMouse[0] == -1) {
1778  var locX = mouseEvent.clientX - this.offsetLeft;
1779  var locY = mouseEvent.clientY - this.offsetTop;
1780 
1781  var hotCornerSz = 7;
1782  if(isDashboard) {
1783  if(locX > Desktop.desktop.dashboard.getDashboardWidth() - hotCornerSz) {
1784  this.style.cursor = "e-resize";
1785  Desktop.winManipMode = 100;
1786  }
1787  else
1788  this.style.cursor = "default";
1789  }
1790  else {
1791  if((locX < hotCornerSz && locY < hotCornerSz) ||
1792  (locX > win.getWindowWidth() - hotCornerSz && locY > win.getWindowHeight() - hotCornerSz)) {
1793  this.style.cursor = "nw-resize";
1794  Desktop.winManipMode = locY < hotCornerSz?1:2;
1795  }
1796  else if((locX > win.getWindowWidth() - hotCornerSz && locY < hotCornerSz) ||
1797  (locX < hotCornerSz && locY > win.getWindowHeight() - hotCornerSz)) {
1798  this.style.cursor = "ne-resize";
1799  Desktop.winManipMode = locY < hotCornerSz?3:4;
1800  }
1801  else if(locX < hotCornerSz) {
1802  this.style.cursor = "w-resize";
1803  Desktop.winManipMode = 5;
1804  }
1805  else if(locX > win.getWindowWidth() - hotCornerSz) {
1806  this.style.cursor = "e-resize";
1807  Desktop.winManipMode = 6;
1808  }
1809  else if(locY < hotCornerSz) {
1810  this.style.cursor = "n-resize";
1811  Desktop.winManipMode = 7;
1812  }
1813  else if(locY > win.getWindowHeight() - hotCornerSz) {
1814  this.style.cursor = "s-resize";
1815  Desktop.winManipMode = 8;
1816  }
1817  else if(locY < win.getWindowHeaderHeight()) {
1818  this.style.cursor = "all-scroll";
1819  Desktop.winManipMode = 0;
1820  }
1821  else
1822  this.style.cursor = "default";
1823  }
1824  }
1825 
1826  //handle mouse movements within the page for better user response
1827  Desktop.handleBodyMouseMove(mouseEvent);
1828 
1829  return false; //to disable drag and drops
1830 } //end handleWindowMouseMove()
1831 
1832 Desktop._mouseMoveSubscribers = [];
1833 //==============================================================================
1834 //Desktop.mouseMoveSubscriber ~~
1835 Desktop.mouseMoveSubscriber = function(newHandler)
1836 {
1837  Desktop._mouseMoveSubscribers.push(newHandler);
1838 }
1839 
1840 //==============================================================================
1841 //Desktop.handleBodyMouseMove ~~
1842 // handle resizing and moving events for desktop
1843 // Returning true is important for allowing selection of text of Debug popup windows
1844 // (Does it break anything to return true?)
1845 Desktop.handleBodyMouseMove = function(mouseEvent)
1846 {
1847 
1848  //call each subscriber
1849  for(var i=0; i<Desktop._mouseMoveSubscribers.length; ++i)
1850  Desktop._mouseMoveSubscribers[i](mouseEvent);
1851 
1852  Desktop.desktop.resetFrameMouse(); //reset last iFrame mouse move
1853 
1854  //handle special case for dashboard resize
1855  if(Desktop.foreWinLastMouse[0] != -1 && Desktop.winManipMode == 100) {
1856 
1857  if(mouseEvent.which == 0) //mouse button was released!!
1858  return Desktop.handleWindowMouseUp(mouseEvent);
1859 
1860  var delta = mouseEvent.clientX-Desktop.foreWinLastMouse[0];
1861  Desktop.desktop.dashboard.setDashboardWidth(Desktop.desktop.dashboard.getDashboardWidth()+delta);
1862  Desktop.foreWinLastMouse = [mouseEvent.clientX,mouseEvent.clientY];
1863 
1864  if(Desktop.stretchAndMoveInterval == 0) //start timer for iframe mouse watchdog
1865  {
1866  //start needing mouse xy from desktop windows
1867  var reqObject = {"request": "startNeedingMouseXY"};
1868  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i)
1869  {
1870  reqObject["windowId"] = Desktop.desktop.getWindowByIndex(i).getWindowId();
1871  Desktop.desktop.getWindowByIndex(i).getFrame().contentWindow.postMessage(
1872  reqObject,"*");
1873  }
1874 
1875  Desktop.stretchAndMoveInterval = window.setInterval(
1876  function() { //handle dashboard resize remotely through iframe mouse event
1877  if(Desktop.desktop.getLastFrameMouseX() == -1) return; //if not in iframe do nothing
1878 
1879  var delta = Desktop.desktop.getLastFrameMouseX()-Desktop.foreWinLastMouse[0];
1880  Desktop.desktop.dashboard.setDashboardWidth(Desktop.desktop.dashboard.getDashboardWidth()+delta);
1881  Desktop.foreWinLastMouse = [Desktop.desktop.getLastFrameMouseX(),Desktop.desktop.getLastFrameMouseY()];
1882  }
1883  ,10);
1884  }
1885 
1886  return true;
1887  }
1888 
1889  if(!Desktop.desktop.getForeWindow()) return true;
1890 
1891  if(Desktop.foreWinLastMouse[0] != -1) //window selected and mouse moving now so do something
1892  {
1893  if(mouseEvent.which == 0) //mouse button was released!!
1894  return Desktop.handleWindowMouseUp(mouseEvent);
1895 
1896  var xy = [mouseEvent.clientX, mouseEvent.clientY];
1897  if(xy[0] < Desktop.desktop.getDesktopContentX() + 4)
1898  xy[0] = Desktop.desktop.getDesktopContentX() + 4; //get away from shadow
1899  if(xy[1] < Desktop.desktop.getDesktopContentY() + 6)
1900  xy[1] = Desktop.desktop.getDesktopContentY() + 6; //get away from shadow
1901  var delta = [xy[0]-Desktop.foreWinLastMouse[0], xy[1]-Desktop.foreWinLastMouse[1]];
1902 
1903  //console.log("MouseXY",mouseEvent.clientX,mouseEvent.clientY);
1904 
1905  Desktop.handleWindowManipulation(delta);
1906 
1907  Desktop.foreWinLastMouse = [xy[0],xy[1]];
1908 
1909  if(Desktop.stretchAndMoveInterval == 0) //start timer for iframe mouse watchdog
1910  {
1911  //start needing mouse xy from desktop windows
1912  var reqObject = {"request": "startNeedingMouseXY"};
1913  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i)
1914  {
1915  reqObject["windowId"] = Desktop.desktop.getWindowByIndex(i).getWindowId();
1916  Desktop.desktop.getWindowByIndex(i).getFrame().contentWindow.postMessage(
1917  reqObject,"*");
1918  }
1919 
1920  Desktop.stretchAndMoveInterval = window.setInterval(
1921  function()
1922  { //handle dashboard resize remotely through iframe mouse event
1923  if(Desktop.desktop.getLastFrameMouseX() == -1) return; //if not in iframe do nothing
1924 
1925  var delta = [Desktop.desktop.getLastFrameMouseX()-Desktop.foreWinLastMouse[0],
1926  Desktop.desktop.getLastFrameMouseY()-Desktop.foreWinLastMouse[1]];
1927  Desktop.handleWindowManipulation(delta);
1928  Desktop.foreWinLastMouse = [Desktop.desktop.getLastFrameMouseX(),Desktop.desktop.getLastFrameMouseY()];
1929  }
1930  ,10);
1931  }
1932  }
1933 
1934  return true;
1935 } //end Desktop.handleBodyMouseMove()
1936 
1937 //==============================================================================
1938 //handle resizing and moving events for desktop
1939 Desktop.handleWindowManipulation = function(delta)
1940 {
1941  if(!Desktop.desktop.getForeWindow()) return false;
1942 
1943  var win = Desktop.desktop.getForeWindow();
1944 
1945  switch(Desktop.winManipMode) {
1946  case 0: //move
1947  win.moveWindowByOffset(delta[0],delta[1]);
1948  break;
1949  case 1: //size from top-left
1950  win.resizeAndPositionWindow(
1951  win.getWindowX() + delta[0],
1952  win.getWindowY() + delta[1],
1953  win.getWindowWidth() - delta[0],
1954  win.getWindowHeight() - delta[1]);
1955  break;
1956  case 2: //size from bottom-right
1957  win.resizeAndPositionWindow(
1958  win.getWindowX(),
1959  win.getWindowY(),
1960  win.getWindowWidth() + delta[0],
1961  win.getWindowHeight() + delta[1]);
1962  break;
1963  case 3: //size from top-right
1964  win.resizeAndPositionWindow(
1965  win.getWindowX(),
1966  win.getWindowY() + delta[1],
1967  win.getWindowWidth() + delta[0],
1968  win.getWindowHeight() - delta[1]);
1969  break;
1970  case 4: //size from bottom-left
1971  win.resizeAndPositionWindow(
1972  win.getWindowX() + delta[0],
1973  win.getWindowY(),
1974  win.getWindowWidth() - delta[0],
1975  win.getWindowHeight() + delta[1]);
1976  break;
1977  case 5: //size from left
1978  win.resizeAndPositionWindow(
1979  win.getWindowX() + delta[0],
1980  win.getWindowY(),
1981  win.getWindowWidth() - delta[0],
1982  win.getWindowHeight());
1983  break;
1984  case 6: //size from right
1985  win.resizeAndPositionWindow(
1986  win.getWindowX(),
1987  win.getWindowY(),
1988  win.getWindowWidth() + delta[0],
1989  win.getWindowHeight());
1990  break;
1991  case 7: //size from top
1992  win.resizeAndPositionWindow(
1993  win.getWindowX(),
1994  win.getWindowY() + delta[1],
1995  win.getWindowWidth(),
1996  win.getWindowHeight() - delta[1]);
1997  break;
1998  case 8: //size from bottom
1999  win.resizeAndPositionWindow(
2000  win.getWindowX(),
2001  win.getWindowY(),
2002  win.getWindowWidth(),
2003  win.getWindowHeight() + delta[1]);
2004  break;
2005  default:
2006  }
2007 } //end handleWindowManipulation()
2008 
2009 //==============================================================================
2010 Desktop.handleWindowButtonDown = function(mouseEvent)
2011 {
2012  mouseEvent.cancelBubble=true; //do nothing but eat event away from window so window doesn't move
2013  return false;
2014 } //end handleWindowButtonDown()
2015 
2016 //==============================================================================
2017 Desktop.handleWindowRefresh = function(mouseEvent)
2018  {
2019  Debug.log("Refresh " + this.id.split('-')[1]);
2020  Desktop.desktop.refreshWindowById(this.id.split('-')[1]);
2021  return false;
2022 } //end handleWindowRefresh()
2023 
2024 //==============================================================================
2025 Desktop.handleWindowHelp = function (mouseEvent)
2026 {
2027  Debug.log("Help " + this.id.split('-')[1]);
2028  Desktop.desktop.windowHelpById(this.id.split('-')[1]);
2029  return false;
2030 } //end handleWindowHelp()
2031 
2032 //==============================================================================
2033 Desktop.handleFullScreenWindowRefresh = function(mouseEvent)
2034 {
2035  Debug.log("Refresh Full Screen Window");
2036 
2037  var foreWindowId = undefined;
2038  try
2039  {
2040  foreWindowId = Desktop.desktop.getForeWindow().getWindowId();
2041  }
2042  catch(e)
2043  {
2044  Debug.log("Could not find foreground window, ignoring.");
2045  }
2046 
2047 
2048  Desktop.desktop.resetDesktop();
2049  Desktop.desktop.refreshDesktop();
2050 
2051  var foreWindow = undefined;
2052  var isMaxWindow = undefined;
2053 
2054 
2055  //for Debugging:
2056  // for(var i = 0; i < Desktop.desktop.getNumberOfWindows(); i++)
2057  // {
2058  // var window = Desktop.desktop.getWindowByIndex(i);
2059  // var id = window.getWindowId();
2060  // var z = window.getWindowZ();
2061  //
2062  // Debug.log("name: " + i + " " + window.getWindowName());
2063  // Debug.log("ID: " + id + " z=" + z);
2064  //
2065  // }
2066 
2067  //if in max window mode, only refresh the max window
2068  //else cycle through all windows and refresh
2069 
2070  //determine max window
2071  if(Desktop.desktop.getForeWindow() &&
2072  Desktop.desktop.getForeWindow().isMaximized())
2073  {
2074  Debug.log("Refreshing just maximized window...");
2075 
2076  Desktop.desktop.refreshWindow();
2077 
2078  } //end refresh maxed window
2079  else
2080  {
2081  Debug.log("Refreshing all windows...");
2082  //Note: refresh window takes foreground window
2083  // and deletes it, then makes a new one that ends up being the
2084  // last window in the array... so always take index 0 to iterate through them
2085  // but save the encountered current foreWindow
2086  for(var i = 0; i < Desktop.desktop.getNumberOfWindows(); i++)
2087  {
2088  var window = Desktop.desktop.getWindowByIndex(0);
2089  var id = window.getWindowId();
2090 
2091  Debug.log("name: " + i + " " + window.getWindowName());
2092  Debug.log("ID: " + id);
2093 
2094  var maximized = window.isMaximized();
2095 
2096  Desktop.desktop.setForeWindow(window);
2097  window = Desktop.desktop.refreshWindow();
2098 
2099  if(foreWindowId == id)
2100  {
2101  foreWindow = window;
2102 
2103  if(maximized)
2104  isMaxWindow = window;
2105  }
2106  }
2107 
2108 
2109  //for Debugging:
2110  // for(var i = 0; i < Desktop.desktop.getNumberOfWindows(); i++)
2111  // {
2112  // var window = Desktop.desktop.getWindowByIndex(i);
2113  // var id = window.getWindowId();
2114  // var z = window.getWindowZ();
2115  //
2116  // Debug.log("name: " + i + " " + window.getWindowName());
2117  // Debug.log("ID: " + id + " z=" + z);
2118  //
2119  // }
2120 
2121  if(foreWindow)
2122  Desktop.desktop.setForeWindow(foreWindow);
2123  if(isMaxWindow)
2124  Desktop.desktop.setForeWindow(foreWindow);
2125  } //end refresh all windows
2126 
2127 
2128  //for Debugging:
2129  // for(var i = 0; i < Desktop.desktop.getNumberOfWindows(); i++)
2130  // {
2131  // var window = Desktop.desktop.getWindowByIndex(i);
2132  // var id = window.getWindowId();
2133  // var z = window.getWindowZ();
2134  //
2135  // Debug.log("name: " + i + " " + window.getWindowName());
2136  // Debug.log("ID: " + id + " z=" + z);
2137  //
2138  // }
2139  return false;
2140 } //end handleFullScreenWindowRefresh()
2141 
2142 //==============================================================================
2143 Desktop.handleWindowMinimize = function(mouseEvent)
2144 {
2145  Debug.log("minimize " + this.id.split('-')[1]);
2146  Desktop.desktop.minimizeWindowById(this.id.split('-')[1]);
2147  return false;
2148 }
2149 
2150 //==============================================================================
2151 Desktop.handleWindowMaximize = function(mouseEvent)
2152 {
2153  Debug.log("maximize " + this.id.split('-')[1]);
2154  Desktop.desktop.maximizeWindowById(this.id.split('-')[1]);
2155  return false;
2156 }
2157 
2158 //==============================================================================
2159 Desktop.handleWindowClose = function(mouseEvent)
2160 {
2161 // Debug.log("close Window " + this.id.split('-')[1]);
2162  Desktop.desktop.closeWindowById(this.id.split('-')[1]);
2163  return false;
2164 }
2165 
2166 //==============================================================================
2167 //Desktop.XMLHttpRequest ~~
2168 // forms request properly for ots server, POSTs data
2169 // and when request is returned, returnHandler is called with
2170 // req result on success, if failure do to bad url called with 0
2171 //
2172 // reqIndex is used to give the returnHandler an index to route responses to.
2173 //
2174 Desktop.XMLHttpRequest = function(requestURL, data, returnHandler, reqIndex)
2175 {
2176 
2177  var errStr = "";
2178  var req = new XMLHttpRequest();
2179 
2180  req.onreadystatechange = function()
2181  {
2182  if (req.readyState==4)
2183  { //when readyState=4 return complete, status=200 for success, status=400 for fail
2184  if(req.status==200)
2185  {
2186  //response received
2187 
2188  if(!Desktop.desktop.serverConnected) //mark as connected
2189  {
2190  Desktop.desktop.serverConnected = true;
2191  Desktop.desktop.dashboard.displayConnectionStatus(true);
2192 
2193  Desktop.desktop.resetDesktop(); //give no permissions, to do simple reset
2194  // and re-start timer for checking foreground window changes due to iFrame content code
2195  }
2196 
2197  //check if failed due to cookieCode and go to login prompt
2198  if(req.responseText == Globals.REQ_NO_PERMISSION_RESPONSE)
2199  {
2200  errStr = "Request failed do to insufficient account permissions.";
2201  //return;
2202  }
2203  else if(req.responseText == Globals.REQ_NO_LOGIN_RESPONSE)
2204  {
2205  errStr = "Login has expired.";
2206 
2207  window.clearTimeout(Desktop.desktop.checkMailboxTimer); //stop checking mailbox
2208  Desktop.logout();
2209  //return;
2210  }
2211 
2212  //Debug.log("Request Response Text " + req.responseText + " ---\nXML " + req.responseXML,Debug.LOW_PRIORITY);
2213  }
2214  else
2215  {
2216  //response failure
2217 
2218  if(Desktop.desktop.serverConnected) //mark as disconnected
2219  {
2220  Desktop.desktop.serverConnected = false;
2221  Desktop.desktop.dashboard.displayConnectionStatus(false);
2222  }
2223 
2224  errStr = "Request Failed - Bad Address:\n" + requestURL;
2225  window.clearTimeout(Desktop.desktop.checkMailboxTimer); //stop checking mailbox
2226  Desktop.logout();
2227  }
2228 
2229  if(errStr != "")
2230  {
2231  errStr += "\n\n(Try refreshing the page, or alert ots admins if problem persists.)";
2232  Debug.log("Error: " + errStr,Debug.HIGH_PRIORITY);
2233  Debug.log("Error occurred from req = " + requestURL);
2234 
2235  req = 0; //force to 0 to indicate error
2236 
2237  Debug.log("The user interface is disconnected from the ots Gateway server.",
2238  Debug.HIGH_PRIORITY);
2239 
2240  //hide user with lock icon (because it usually looks bad when disconnected)
2241  document.getElementById("DesktopDashboard-userWithLock").style.display = "none";
2242  }
2243  if(returnHandler) returnHandler(req,reqIndex,errStr);
2244  }
2245  }
2246 
2247  if(Desktop.desktop.login) //add cookie code if login instance has been created
2248  data = "CookieCode="+Desktop.desktop.login.getCookieCode()+"&"+data;
2249  requestURL = "/urn:xdaq-application:lid=" + urnLid_ + "/" + requestURL; //urnLid_ is from parent html page
2250  //Debug.log("Post " + requestURL + "\n\tData: " + data);
2251  req.open("POST",requestURL,true);
2252  //req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
2253  req.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
2254  req.send(data);
2255 } //end XMLHttpRequest()
2256 
2257 //==============================================================================
2258 //returns xml entry value for an attribute
2259 Desktop.getXMLAttributeValue = function(req, name, attribute)
2260 {
2261  if(req && req.responseXML && req.responseXML.getElementsByTagName(name).length > 0)
2262  return req.responseXML.getElementsByTagName(name)[0].getAttribute(attribute);
2263  else
2264  return undefined;
2265 } //end getXMLAttributeValue()
2266 
2267 //==============================================================================
2268 //getXMLValue ~~
2269 // returns xml entry value for attribue 'value'
2270 Desktop.getXMLValue = function(req, name)
2271 {
2272  return Desktop.getXMLAttributeValue(req,name,"value");
2273 } //end getXMLValue()
2274 
2275 //==============================================================================
2276 //logout ~~
2277 // logout and login prompt
2278 Desktop.logout = function ()
2279 {
2280  if(Desktop.desktop && Desktop.desktop.login &&
2281  !Desktop.desktop.login.isBlackout())
2282  Desktop.desktop.login.logout();
2283 } //end logout()
2284 
2285 //==============================================================================
2286 //formatTime ~~
2287 Desktop.formatTime = function(t)
2288 {
2289  var date = new Date(t * 1000);
2290  var mm = date.getMinutes() < 10?"0"+date.getMinutes():date.getMinutes();
2291  var ss = date.getSeconds() < 10?"0"+date.getSeconds():date.getSeconds();
2292  return date.getHours() + ":" + mm + ":" + ss;
2293 } //end formatTime()
2294 
2295 //==============================================================================
2296 //closeSystemMessage ~~
2297 Desktop.closeSystemMessage = function(id)
2298 {
2299  var el = document.getElementById("Desktop-systemMessageBox-" + id);
2300  el.parentNode.removeChild(el); //remove from page!
2301 } //end closeSystemMessage()
2302 
2303 //==============================================================================
2304 //isWizardMode ~~
2305 Desktop.isWizardMode = function()
2306 {
2307  //return true if in --config desktop mode
2308  //Debug.log("Desktop Security: " + Desktop.desktop.security);
2309 
2310  return !(!Desktop.desktop.security ||
2311  Desktop.desktop.security == Desktop.SECURITY_TYPE_DIGEST_ACCESS ||
2312  Desktop.desktop.security == Desktop.SECURITY_TYPE_NONE);
2313 } //end isWizardMode()
2314 
2315 //==============================================================================
2316 //openNewBrowserTab ~~
2317 Desktop.openNewBrowserTab = function(name,subname,windowPath,unique)
2318 {
2319 
2320 
2321  //for windowPath, need to check lid=## is terminated with /
2322  // check from = that there is nothing but numbers
2323  {
2324  var i = windowPath.indexOf("urn:xdaq-application:lid=") + ("urn:xdaq-application:lid=").length;
2325  var isAllNumbers = true;
2326  for(i;i<windowPath.length;++i)
2327  {
2328  Debug.log(windowPath[i]);
2329 
2330  if(windowPath[i] < "0" || windowPath[i] > "9")
2331  {
2332  isAllNumbers = false;
2333  break;
2334  }
2335  }
2336  if(isAllNumbers)
2337  windowPath += "/";
2338  }
2339  Debug.log("DesktopWindow= " + windowPath);
2340 
2341  Debug.log("name= " + name);
2342  Debug.log("subname= " + subname);
2343  Debug.log("unique= " + unique);
2344  var search = window.parent.window.location.search;
2345  url = window.parent.window.location.pathname;
2346 
2347  var str = "requestingWindowId=Desktop";
2348  str += "&windowName=" + name;
2349  str += "&windowSubname=" + subname;
2350  str += "&windowUnique=" + unique;
2351  str += "&windowPath=" + encodeURIComponent(windowPath);
2352 
2353  //if there is no search, need to check lid=## is terminated with /
2354  // check from = that there is nothing but numbers
2355 
2356  if(!Desktop.isWizardMode())
2357  {
2358  var i = url.indexOf("urn:xdaq-application:lid=") + ("urn:xdaq-application:lid=").length;
2359  var isAllNumbers = true;
2360  for(i;i<url.length;++i)
2361  {
2362  Debug.log(url[i]);
2363 
2364  if(url[i] < "0" || url[i] > "9")
2365  {
2366  isAllNumbers = false;
2367  break;
2368  }
2369  }
2370  if(isAllNumbers)
2371  url += "/";
2372  url += "?" + str;
2373  }
2374  else// if(Desktop.isWizardMode())
2375  {
2376  url += search.split('&')[0] + "&" + str; //take first parameter (for wiz mode)
2377  }
2378 
2379  Debug.log("DesktopContent.openNewBrowserTab= " + url);
2380 
2381  window.open(url,'_blank');
2382 } //end openNewBrowserTab()
2383 
2384 //==============================================================================
2385 //call to show desktop tooltip
2386 // shown for wiz mode and normal mode, e.g.
2387 Desktop.desktopTooltip = function()
2388 {
2389 
2390  DesktopContent.tooltip("Desktop Introduction",
2391  "Welcome to the <i>otsdaq</i> Desktop environment. This is your portal " +
2392  "to all of the possibilities of <i>otsdaq</i>.\n\n" +
2393  "Briefly, here are the features:" +
2394 
2395  "\n\t- <b>Desktop Window Icons:</b> " +
2396  "<INDENT>" +
2397  "Click the rounded-square icons on your Desktop to open " +
2398  "a particular window. If you hold down your click (for a second), you " +
2399  "can open the window in fullscreen, or in a new tab, or even open the window " +
2400  "then tile it on the screen with all other open windows!" +
2401  "</INDENT>" +
2402 
2403  "\n\t- <b>Desktop Dashboard (top pane):</b> " +
2404  "<INDENT>" +
2405  "Along the top and left margins of the Desktop, you will find the Desktop " +
2406  "Dashboard - this section is an introduction to the top pane of the Dashboard. " +
2407  "The top pane of the Dashboard " +
2408  "is made of buttons and icons going from left to right:" +
2409 
2410  "\n\t- <b>Left Pane Toggler:</b> " +
2411  "<INDENT>" +
2412  "The first button you will encounter in the top pane looks like a horizontal double-arrow " +
2413  "icon. This button toggles the display of the left pane of the Dashboard. Note when you " +
2414  "refresh the page, the state of the left pane persists!" +
2415  "</INDENT>" +
2416 
2417  "\n\t- <b>Layouts Menu:</b> " +
2418  "<INDENT>" +
2419  "The next button you will encounter in the top pane reads 'Layouts.' " +
2420  "This button gives you access to your Window Layout Presets. You will see 2 'System' presets there " +
2421  "which can be setup by uesrs with admin privileges. There are also 3 'User' presets which you can setup for " +
2422  "yourself in the User Settings window (get there with " +
2423  "the cog wheel icon in the upper-right of the Desktop)." +
2424  "</INDENT>" +
2425 
2426  "\n\t- <b>Tile Desktop Windows:</b> " +
2427  "<INDENT>" +
2428  "The next button you will encounter in the top pane reads 'Tile.' " +
2429  "This button will automatically tile all open Desktop Windows to fit in your browser window." +
2430  "</INDENT>" +
2431 
2432  "\n\t- <b>Show Desktop:</b> " +
2433  "<INDENT>" +
2434  "The next button you will encounter in the top pane reads 'Show Desktop.' " +
2435  "This button will minimize all open Desktop Windows which is nice " +
2436  "when you want to see all of your Desktop Icons again." +
2437  "</INDENT>" +
2438 
2439  "\n\t- <b>Full Screen:</b> " +
2440  "<INDENT>" +
2441  "The next button you will encounter in the top pane reads 'Full Screen.' " +
2442  "This button will maximize to full screen the Desktop Window that was last used (i.e. the window that has the focus)." +
2443  "</INDENT>" +
2444  "</INDENT>" +
2445 
2446  "\n\t- <b>Desktop Dashboard (left pane):</b> " +
2447  "<INDENT>" +
2448  "Along the top and left margins of the Desktop, you will find the Desktop " +
2449  "Dashboard - this section is an introduction to the left pane of the Dashboard. " +
2450  "The left pane of the Dashboard " +
2451  "is a listing of all open Desktop Windows. If you click one of the buttons in the list, " +
2452  "the associated window " +
2453  "will be minimized or restored. If you hold down your click (for one second) you can choose " +
2454  "to minimize, maximize, or close the window!" +
2455  "</INDENT>" +
2456 
2457 
2458 
2459  "\n\nRemember, if you would like to take a look at the available online documentation, " +
2460  "click the question mark at the top-right of the Desktop."
2461  );
2462 } //end desktopTooltip()
2463 
2464 
2465 
2466 
2467 
2468 
2469 
2470 
2471 
2472 
2473 
2474 
2475 
2476 
2477 
2478 
2479 
2480