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