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