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