otsdaq_utilities  v2_05_02_indev
DesktopDashboard.js
1 //=====================================================================================
2 //
3 // Created Dec, 2012
4 // by Ryan Rivera ((rrivera at fnal.gov))
5 //
6 // DesktopDashboard.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 
16 if (typeof Debug == 'undefined')
17  console.log('ERROR: Debug is undefined! Must include Debug.js before Desktop.js');
18 
19 if (typeof Desktop == 'undefined')
20  console.log('ERROR: Desktop is undefined! Must include Desktop.js before DesktopDashboard.js');
21 else {
22 
23 
26  //define Desktop.createDashboard to return dashboard class
29  Desktop.createDashboard = function(z) {
30  if(false === (this instanceof Desktop.createDashboard)) {
31  //here to correct if called as "var v = Desktop.createDesktop();"
32  // instead of "var v = new Desktop.createDesktop();"
33  return new Desktop.createDashboard(z);
34  }
35 
36 
37 
38  //------------------------------------------------------------------
39  //list of members functions ----------------------
40  //------------------------------------------------------------------
41  //private:
42  //public:
43  //displayConnectionStatus(connected) //bool connected
44 
45 
46 
47 
48 
49 
50  //------------------------------------------------------------------
51  //create private members variables ----------------------
52  //------------------------------------------------------------------
53  var _defaultDashboardColor = "rgb(0,40,85)";
54 
55 
56 
57  //all units in pixels unless otherwise specified
58 
59  var _defaultDashboardHeight = 38;
60  var _defaultWindowDashboardWidth = 200;
61  var _defaultWindowDashboardMinWidth = 50;
62 
63  Debug.log("Setup Dashboard based on window.parent.window.location.hash=" +
64  window.parent.window.location.hash,
65  Debug.MED_PRIORITY);
66 
67  var _urlHashVal = (window.parent.window.location.hash && window.parent.window.location.hash.length>1)?
68  (window.parent.window.location.hash.substr(1)|0):
69  undefined;
70  var _windowDashboardWidth = ((_urlHashVal|0) > 1)?
71  ((_urlHashVal | 0)*_defaultWindowDashboardWidth/1000):
72  _defaultWindowDashboardWidth;
73  var _displayWindowDashboard = //default window dashboard view
74  (_urlHashVal === undefined)?1:(_urlHashVal?1:0);
75 
76  var _windowDashboard,_topBar,_showDesktopBtn,_fullScreenBtn,_fullScreenRefreshBtn;
77 
78  var _windowDashboardWindowCSSRule; //e.g. _var.style.width = "100px"
79 
80  var _layoutDropDownDisplayed = false;
81  var _layoutMenuItems = [];
82  var numOfUserLayouts = 5;
83  var numOfSystemLayouts = 5;
84  for(var i=0;i<numOfSystemLayouts;++i)
85  _layoutMenuItems.push("System Preset-" + (i+1));
86  _layoutMenuItems.push("---");
87  for(var i=0;i<numOfUserLayouts;++i)
88  _layoutMenuItems.push("User Preset-" + (i+1));
89 
90  var _dashboardElement, _dashboardColorPostbox;
91 
92  var _deepClickTimer = 0;
93  //------------------------------------------------------------------
94  //create public members variables ----------------------
95  //------------------------------------------------------------------
96  this.dashboardElement;
97 
98 
99 
100  //------------------------------------------------------------------
101  //create PRIVATE members functions ----------------------
102  //------------------------------------------------------------------
103  //=====================================================================================
104  var _toggleWindowDashboard = function(event,setValue) {
105 
106  if(setValue !== undefined)
107  _displayWindowDashboard = setValue;
108  else //toggle
109  _displayWindowDashboard = !_displayWindowDashboard;
110 
111  _setDashboardWidth(); //undefined to keep width and save status to URL
112 
113 // var newURL = window.parent.window.location.pathname +
114 // window.parent.window.location.search +
115 // "#"+
116 // (_displayWindowDashboard?"1":"0");
117 //
118 // //update browser url so refresh will give same desktop experience
119 // if(!Desktop.isWizardMode())
120 // window.parent.window.history.replaceState('ots', 'ots', newURL);
121 // else
122 // window.parent.window.history.replaceState('ots wiz', 'ots wiz', newURL);
123 
124  _windowDashboard.style.display = _displayWindowDashboard?"inline":"none";
125  Desktop.desktop.redrawDesktop();
126  } //end _toggleWindowDashboard()
127 
128  //=====================================================================================
129  // w undefined will leave width unchanged
130  var _setDashboardWidth = function(w)
131  {
132  console.log("_setDashboardWidth",w);
133  console.log("_setDashboardWidth _windowDashboardWidth",_windowDashboardWidth);
134  if(w !== undefined)
135  {
136  _windowDashboardWidth = w|0;
137  }
138  //else dont change, but always keep min
139 
140  if(_windowDashboardWidth < _defaultWindowDashboardMinWidth)
141  _windowDashboardWidth = _defaultWindowDashboardMinWidth;
142 
143  //save as integer fraction of 1000 into URL
144  var newURL = window.parent.window.location.pathname +
145  window.parent.window.location.search +
146  "#"+
147  (_displayWindowDashboard?
148  ((_windowDashboardWidth*1000/_defaultWindowDashboardWidth)|0):
149  "0");
150 
151  //update browser url so refresh will give same desktop experience
152  if(!Desktop.isWizardMode())
153  window.parent.window.history.replaceState('ots', 'ots', newURL);
154  else
155  window.parent.window.history.replaceState('ots wiz', 'ots wiz', newURL);
156 
157  Desktop.desktop.redrawDesktop();
158 
159  } //end setDashboardWidth()
160 
161  //=====================================================================================
162  //_refreshTitle() ~~~
163  // private function to refresh title name based on dashboard size
164  // clip text if too long
165  var _refreshTitle = function()
166  {
167 
168  var el,winIndex;
169  var hdrW = _windowDashboardWidth - 14; //2*7px padding
170  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i) {
171  el = document.getElementById('DesktopDashboard-windowDashboard-win'+i);
172  winIndex = document.getElementById('DesktopDashboard-windowDashboard-winIndex'+i).innerHTML;
173  el.innerHTML = Desktop.desktop.getWindowNameByIndex(winIndex) +
174  (Desktop.desktop.getWindowSubNameByIndex(winIndex)==""?"":" - ") +
175  Desktop.desktop.getWindowSubNameByIndex(winIndex);
176  while(el.scrollWidth > hdrW && el.innerHTML.length > 4)
177  el.innerHTML = el.innerHTML.substr(0,el.innerHTML.length-4)+"...";
178 
179  el.innerHTML += "<div class='hiddenDiv' " + //add hidden window index back in for future use
180  "id='DesktopDashboard-windowDashboard-winIndex"+i+"'>"+ winIndex + "</div>";
181  }
182  } //end _refreshTitle()
183 
184  //=====================================================================================
185  var _redrawDashboard = function()
186  {
187 
188  _topBar.style.left = Desktop.desktop.getDesktopX()+"px";
189  _topBar.style.top = Desktop.desktop.getDesktopY()+"px";
190  _topBar.style.width = Desktop.desktop.getDesktopWidth()+"px";
191  _topBar.style.height = _defaultDashboardHeight+"px";
192 
193  _windowDashboard.style.left = Desktop.desktop.getDesktopX()+"px";
194  _windowDashboard.style.top = Desktop.desktop.getDesktopY()+_defaultDashboardHeight+"px";
195  _windowDashboard.style.width = _windowDashboardWidth+"px";
196  _windowDashboardWindowCSSRule.style.width = (_windowDashboardWidth-34)+"px"; //2*7px padding, 2*10px margin
197  _refreshTitle();
198  _windowDashboard.style.height = Desktop.desktop.getDesktopHeight()-(Desktop.desktop.getDesktopY()+_defaultDashboardHeight)+"px";
199 
200  } //end _redrawDashboard()
201 
202  //=====================================================================================
203  //get CSS style rule fpr dasboard window boxes
204  var _getDashboardWindowWidthCSSRule = function()
205  {
206 
207  var i,j;
208  for(i=0;i<document.styleSheets.length;++i) {
209  Debug.log(document.styleSheets[i].href);
210  if(document.styleSheets[i].href && document.styleSheets[i].href.split('/').pop() ==
211  "Desktop.css") {
212  for(j=0;j<document.styleSheets[i].cssRules.length;++j) {
213  if(document.styleSheets[i].cssRules[j].selectorText ==
214  "#Desktop .DesktopDashboard-windowDashboard-win")
215  return document.styleSheets[i].cssRules[j]; //success!!
216  }
217  break; //failed
218  }
219  }
220  if(i == document.styleSheets.length) Debug.log("FAIL -- Could not locate CSS Rule for Dashboard Window.",Debug.HIGH_PRIORITY);
221  return 0;
222  }
223 
224 
225  //tile the desktop windows in various ways
226  var _windowOrganizeMode = -1;
227  var _windowOrganizeModeTimeout = 0;
228  var _windowDashboardOrganize = function() {
229 
230  //reset mode after 10 seconds
231  clearTimeout(_windowOrganizeModeTimeout);
232  _windowOrganizeModeTimeout = setTimeout(function() {_windowOrganizeMode = -1; Debug.log("Reseting _windowOrganizeMode.");},10000);
233 
234 
235  var win;
236 
237  var dx = Desktop.desktop.getDesktopContentX(), dy = Desktop.desktop.getDesktopContentY(),
238  dw = Desktop.desktop.getDesktopContentWidth(), dh = Desktop.desktop.getDesktopContentHeight();
239  var xx, yy;
240 
241  var numOfWindows = Desktop.desktop.getNumberOfWindows();
242 
243  //cycle through different modes where the various windows get a bigger spot
244  if(++_windowOrganizeMode < 0 || _windowOrganizeMode > numOfWindows)
245  _windowOrganizeMode = 0; //wrap-around
246 
247  //for all modes, except 0, add a spot
248  // and allow that window to use the first two spots
249  if(_windowOrganizeMode && numOfWindows > 1)
250  ++numOfWindows;
251 
252  if(1) //tile code
253  {
254  var rows = 1;
255  var ww = Math.floor(dw/numOfWindows);
256  var wh = dh;
257 
258  while(ww*2 < wh) {
259  //Debug.log("Desktop Dashboard Organize " + ww + " , " + wh,Debug.LOW_PRIORITY);
260  ww = Math.floor(dw/Math.ceil(numOfWindows/++rows)); wh = Math.floor(dh/rows);
261  } //have too much height, so add row
262  xx = dx; yy = dy;
263  //Debug.log("Desktop Dashboard Organize " + ww + " , " + wh,Debug.LOW_PRIORITY);
264  var cols = Math.ceil(numOfWindows/rows);
265  Debug.log("Desktop Dashboard Organize r" + rows + " , c" + cols,Debug.LOW_PRIORITY);
266 
267 
268  //we know size, now place windows
269 
270  //first the bigger one
271  var ic = 0; //counter for new row
272  if(_windowOrganizeMode && numOfWindows > 1)
273  {
274  var i = _windowOrganizeMode-1; //target window index
275 
276  win = Desktop.desktop.getWindowByIndex(
277  document.getElementById('DesktopDashboard-windowDashboard-winIndex'+i).innerHTML);
278 
279  if(win.isMinimized()) win.unminimize();
280  if(win.isMaximized()) win.unmaximize();
281 
282  //make double wide
283  win.setWindowSizeAndPosition(xx,yy,ww*2,wh);
284 
285  xx += ww*2;
286  ic+=2;
287  if((ic)%cols==0){xx = dx; yy += wh;} //start new row
288  // Debug.log("Desktop Dashboard Organize i:" + i + " - " + (ic)%cols + " - "
289  // + xx + " , " + yy + " :: "
290  // + ww*2 + " , " + wh,Debug.LOW_PRIORITY);
291  }
292 
293  //now the other windows
294  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i) {
295 
296  if(_windowOrganizeMode && numOfWindows > 1 && i == _windowOrganizeMode-1) continue; //skip the window already placed
297 
298  win = Desktop.desktop.getWindowByIndex(
299  document.getElementById('DesktopDashboard-windowDashboard-winIndex'+i).innerHTML);
300 
301  if(win.isMinimized()) win.unminimize();
302  if(win.isMaximized()) win.unmaximize();
303 
304  //if last window fill remaining space rows*cols > numOfWindows
305  if(i == Desktop.desktop.getNumberOfWindows()-1)
306  win.setWindowSizeAndPosition(xx,yy,ww*(1 + (rows*cols - numOfWindows)),wh);
307  else
308  win.setWindowSizeAndPosition(xx,yy,ww,wh);
309 
310  xx += ww;
311  if((++ic)%cols==0){xx = dx; yy += wh;} //start new row
312  // Debug.log("Desktop Dashboard Organize i:" + i + " - " + (ic)%cols + " - "
313  // + xx + " , " + yy + " :: "
314  // + ww + " , " + wh,Debug.LOW_PRIORITY);
315  }
316  Desktop.desktop.redrawDashboardWindowButtons();
317  }
318 
319  Debug.log("Desktop Dashboard Organize Mode: " + _windowOrganizeMode,Debug.LOW_PRIORITY);
320  }
321 
322  var _windowDashboardMinimizeAll = function() {
323  var win;
324  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i) {
325  win = Desktop.desktop.getWindowByIndex(i);
326  win.minimize(); if(!win.isMinimized()) win.minimize(); //minimize twice, in case was mazimized
327 
328  }
329  }
330 
331  var _windowDashboardRestoreAll = function() {
332  var win;
333  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i) {
334  win = Desktop.desktop.getWindowByIndex(i);
335  win.unminimize();
336  if (win.isMaximized())
337  Desktop.desktop.setForeWindow(win);
338 
339  }
340  //Desktop.desktop.setForeWindow(Desktop.desktop.getWindowByIndex(0));
341  }
342 
343 
344  var _windowDashboardToggleWindows = function () {
345 
346 
347  // if (Desktop.desktop.getForeWindow() &&
348  // Desktop.desktop.getForeWindow().isMinimized())
349  // _windowDashboardRestoreAll();
350  //else
351  // _windowDashboardMinimizeAll();
352 
353  if(_showDesktopBtn.innerHTML.indexOf(">Show Desktop</a>") !== -1)
354  _windowDashboardMinimizeAll();
355  else
356  _windowDashboardRestoreAll();
357 
358  Desktop.desktop.redrawDashboardWindowButtons();
359 
360 // _showDesktopBtn.innerHTML = "<a href='#' title='Click to toggle minimize/restore all windows'>" +
361 // ((Desktop.desktop.getForeWindow() &&
362 // Desktop.desktop.getForeWindow().isMinimized())?"Restore Windows":"Show Desktop") + "</a>";
363  }
364 
365  var _windowDashboardRefresh = function() {
366  updateWindows();
367  Debug.log("Window refreshed.");
368  }
369 
370  //_windowDashboardLayoutsDropDown ~
371  // toggles default layout drop down menu
372  var _windowDashboardLayoutsDropDown = function() {
373  _layoutDropDownDisplayed = !_layoutDropDownDisplayed;
374  Debug.log("Desktop _windowDashboardDefaultsDropDown " +
375  _layoutDropDownDisplayed,Debug.LOW_PRIORITY);
376 
377  var el;
378  //remove drop down if already present
379  el = document.getElementById("DesktopDashboard-defaults-dropdown");
380  if(el) { //should not be any DesktopDashboard-defaults-dropdown div so delete
381 
382  Debug.log("found DesktopDashboard-defaults-dropdown div and deleted",Debug.LOW_PRIORITY);
383  el.parentNode.removeChild(el);
384  }
385  if(!_layoutDropDownDisplayed) return; //do not create if closing
386 
387  //create default dropdown menu element
388  el = document.createElement("div");
389  el.setAttribute("id", "DesktopDashboard-defaults-dropdown");
390  el.style.backgroundColor = _defaultDashboardColor;
391  var str = "";
392  for(var i=0;i<_layoutMenuItems.length;++i)
393  if(_layoutMenuItems[i] == "---") //horizontal line
394  str += "<center><hr width='75%' style='border:1px solid; margin-top:5px'/></center>";
395  else {
396  str += "<a href='#' onmouseup='Desktop.desktop.dashboard.windowDashboardLayoutsDropDown(); "
397  + "Desktop.desktop.defaultLayoutSelect("+i+"); return false;'>"
398  + _layoutMenuItems[i] + "</a>";
399 
400  str += "<a onclick='Desktop.openNewBrowserTab(" +
401  "\"Desktop.openLayout(" + i + ")\",\"\"," +
402  "\"\",0 /*unique*/);' " + //end onclick
403  "title='Click to open the layout in a new tab' " +
404  ">"
405  str += "<img style='width:11px;margin-left:10px;' " +
406  "src='/WebPath/images/dashboardImages/icon-New-Tab.png'>";
407  str += "</a>";
408 
409  if(i<_layoutMenuItems.length-1)
410  str += "<br/>";
411  }
412 
413  el.innerHTML = str;
414  _dashboardElement.appendChild(el);
415  }
416 
417  //------------------------------------------------------------------
418  //create PUBLIC members functions ----------------------
419  //------------------------------------------------------------------
420  this.getDashboardHeight = function() { return _defaultDashboardHeight;}
421  this.getDashboardWidth = function() { return _displayWindowDashboard?_windowDashboardWidth:0;}
422 
423 
424  this.setDashboardWidth = _setDashboardWidth;
425  this.toggleWindowDashboard = _toggleWindowDashboard;
426  this.redrawDashboard = _redrawDashboard;
427  this.windowDashboardLayoutsDropDown = _windowDashboardLayoutsDropDown;
428  this.windowDashboardOrganize = _windowDashboardOrganize;
429 
430  //=====================================================================================
431  this.updateWindows = function()
432  {
433 
434  _windowDashboard.innerHTML = "";
435 
436  var mySortArrId = [];
437  var mySortArrIndex = [];
438  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i) {
439  mySortArrId.push(Desktop.desktop.getWindowByIndex(i).getWindowId());
440  mySortArrIndex.push(i);
441  }
442 
443  //sort by id
444  for(var i=0;i<mySortArrId.length-1;++i) {
445  var min = i;
446  for(var j=i+1;j<mySortArrId.length;++j)
447  if(mySortArrId[j] < mySortArrId[min])
448  min = j;
449 
450  //have min, swap to i
451  var tmp;
452  tmp = mySortArrId[i];
453  mySortArrId[i] = mySortArrId[min];
454  mySortArrId[min] = tmp;
455  tmp = mySortArrIndex[i];
456  mySortArrIndex[i] = mySortArrIndex[min];
457  mySortArrIndex[min] = tmp;
458  }
459 
460  //have sorted by id, create window buttons for dashboard
461  var tmpClassStr, defClassStr = "DesktopDashboard-windowDashboard-win";
462 
463  for(var i=0;i<Desktop.desktop.getNumberOfWindows();++i) {
464 
465  tmpClassStr = defClassStr + //if foreground window, append class
466  ((mySortArrIndex[i] == Desktop.desktop.getNumberOfWindows()-1)?
467  " DesktopDashboard-windowDashboard-foreWin":"");
468  _windowDashboard.innerHTML +=
469  "<div " +
470  "onmouseup='Desktop.desktop.dashboard.handleDashboardWinMouseUp(event," +
471  //"onmouseup='Desktop.desktop.clickedWindowDashboard(" +
472  mySortArrId[i] + ");' " +
473  "onmousedown='Desktop.desktop.dashboard.handleDashboardWinMouseDown(event," +
474  //"onmouseup='Desktop.desktop.clickedWindowDashboard(" +
475  mySortArrId[i] + ");' " +
476  //"onmousedown='Desktop.handleWindowButtonDown(event);' " + //eat window button down event
477  "class='" + tmpClassStr + "' " +
478  "id='DesktopDashboard-windowDashboard-win"+i+"'>" +
479  Desktop.desktop.getWindowNameByIndex(mySortArrIndex[i]) + " - " +
480  Desktop.desktop.getWindowSubNameByIndex(mySortArrIndex[i]) +
481  "<div class='hiddenDiv' " +
482  "id='DesktopDashboard-windowDashboard-winIndex"+i+"'>"+ mySortArrIndex[i] +
483  "</div>" +
484  "</div>\n";
485  }
486 
487  _refreshTitle();
488  }
489 
490  //=====================================================================================
491  this.redrawFullScreenButton = function()
492  {
493  _fullScreenBtn.innerHTML = "<a href='#' title='Click to toggle full screen mode for current window'>" +
494  ((Desktop.desktop.getForeWindow() &&
495  Desktop.desktop.getForeWindow().isMaximized())?
496  "Exit Full Screen":"Full Screen") + "</a>";
497 
498  }
499 
500  //=====================================================================================
501  this.redrawRefreshButton = function()
502  {
503  if(Debug.BROWSER_TYPE == Debug.BROWSER_TYPE_FIREFOX) //firefox
504  {
505  //firefox shows circle-arrow character smaller
506  _fullScreenRefreshBtn.innerHTML =
507  "<div style='font-size:32px;margin-top:-12px;' title='Click to reload the desktop and all windows'>↻</div>";
508  _fullScreenRefreshBtn.style.height = "16px";
509  _fullScreenRefreshBtn.style.padding = "3px 10px 7px 10px";
510  }
511  else //chrome
512  {
513  _fullScreenRefreshBtn.innerHTML =
514  "<div style='font-size: 18px; margin: -1px 0 0 2px; font-weight: 300;' title='Click to reload the desktop and all windows'>↻</div>";
515  _fullScreenRefreshBtn.style.height = "16px";
516  _fullScreenRefreshBtn.style.padding = "3px 10px 7px 10px";
517  }
518  } //end redrawRefreshButton()
519 
520  //=====================================================================================
521  this.redrawShowDesktopButton = function()
522  {
523  _showDesktopBtn.innerHTML = "<a href='#' title='Click to toggle minimize/restore all windows'>" +
524  ((Desktop.desktop.getForeWindow() &&
525  Desktop.desktop.getForeWindow().isMinimized())?
526  "Restore Windows":"Show Desktop") + "</a>";
527  //Debug.log("Desktop.desktop.getForeWindow().isMinimized() " + Desktop.desktop.getForeWindow().isMinimized());
528  }
529 
530  //=====================================================================================
531  this.getDefaultDashboardColor = function() { return _defaultDashboardColor; }
532 
533  //=====================================================================================
534  this.setDefaultDashboardColor = function(color) {
535  _defaultDashboardColor = color;
536  _dashboardColorPostbox.innerHTML = _defaultDashboardColor; //set to color string
537 
538  _topBar.style.backgroundColor = _defaultDashboardColor;
539  _windowDashboard.style.backgroundColor = _defaultDashboardColor;
540  } //end setDefaultDashboardColor()
541 
542  var _oldUserNameWithLock = "";
543  //=====================================================================================
544  this.doSetUserWithLock = function()
545  {
546  Debug.log("doSetUserWithLock()");
547  var user = Desktop.desktop.login.getUsername();
548  var data = "";
549  data += "lock=" + ((!_oldUserNameWithLock || _oldUserNameWithLock == "")?"1":"0") + "&";
550  data += "username=" + user;
551 
552  Desktop.XMLHttpRequest(
553  "Request?RequestType=setUserWithLock&accounts=1",
554  data,
555  Desktop.desktop.dashboard.handleSetUserWithLock);
556 
557  } //end doSetUserWithLock()
558  //=====================================================================================
559  this.displayUserLock = function(usernameWithLock, el)
560  {
561  if(!el)
562  el = document.getElementById("DesktopDashboard-userWithLock");
563 
564  var user = Desktop.desktop.login.getUsername();
565  var data = "";
566  data += "lock=" + ((!usernameWithLock || usernameWithLock == "")?"1":"0") + "&";
567  data += "username=" + user;
568 
569  var jsReq = "Desktop.desktop.dashboard.doSetUserWithLock();";
570 // "Desktop.XMLHttpRequest(\"" +
571 // "Request?RequestType=setUserWithLock&accounts=1\"," +
572 // "\"" + data + "\",Desktop.desktop.dashboard.handleSetUserWithLock)";
573 
574 
575  if(_oldUserNameWithLock == usernameWithLock &&
576  el.style.display == "block")
577  return; //no need to re-write element
578 
579 
580  var str = "";
581 
582  if(!usernameWithLock || usernameWithLock == "")
583  {
584  //nobody has lock
585  str += "<a href='javascript:" + jsReq + "'" +
586  "title='Click to lockout the system and take the ots Lock'>";
587  str += "<img " +
588  "src='/WebPath/images/dashboardImages/icon-Settings-Unlock.png'>";
589  str += "</a>";
590  el.innerHTML = str;
591  _oldUserNameWithLock = "";
592  el.style.display = "block";
593  return;
594  }
595 
596  if(usernameWithLock != user) //not user so cant unlock
597  str = "<img src='/WebPath/images/dashboardImages/icon-Settings-LockDisabled.png' " +
598  "title='User " +
599  usernameWithLock + " has the ots Lock'>";
600  else //this is user so can unlock
601  {
602  str += "<a href='javascript:" + jsReq + "' " +
603  "title='Click to unlock the system and release the ots Lock'>";
604  str += "<img " +
605  "src='/WebPath/images/dashboardImages/icon-Settings-Lock.png'>";
606  str += "</a>";
607  }
608 
609  el.innerHTML = str;
610  el.style.display = "block";
611 
612  _oldUserNameWithLock = usernameWithLock;
613  }
614 
615  //=====================================================================================
616  this.handleSetUserWithLock = function(req)
617  {
618  Debug.log(req);
619  //extract alert from server
620  var serverAlert = Desktop.getXMLValue(req,"server_alert");
621  if(serverAlert) Debug.log("Message from Server: " + serverAlert, Debug.HIGH_PRIORITY);
622 
623  Desktop.desktop.dashboard.displayUserLock(
624  Desktop.getXMLValue(req,"username_with_lock"));
625 
626  Desktop.desktop.resetDesktop(); //soft reset attempt
627  }
628 
629 
630  //displayConnectionStatus ~~
631  // bool connected
632  this.displayConnectionStatus = function(connected) {
633  var el = document.getElementById("DesktopDashboard-serverConnectionStatus");
634 
635  if(connected)
636  {
637  el.style.display = "none";
638  el.innerHTML = "";
639  }
640  else
641  {
642  el.innerHTML = "*** <a onclick='Desktop.desktop.resetDesktop();//soft reset attempt' " +
643  "style='cursor:pointer; color:rgb(255,150,0);'>Disconnected</a> ***";
644  el.style.display = "block";
645 
646  //hide user with lock icon (because it usually looks bad when disconnected)
647  document.getElementById("DesktopDashboard-userWithLock").style.display = "none";
648  }
649  }
650 
651  //handleDashboardWinMouseUp ~~
652  this.handleDashboardWinMouseUp = function(event, winId) {
653  if(_deepClickTimer)
654  {
655  window.clearTimeout(_deepClickTimer);
656  _deepClickTimer = 0;
657  }
658  Desktop.desktop.clickedWindowDashboard(winId);
659  }
660 
661  //handleDashboardWinMouseDown ~~
662  this.handleDashboardWinMouseDown = function(event, winId) {
663  event.cancelBubble = true; //prevent default behavior
664  event.preventDefault();
665  _deepClickTimer = window.setTimeout(function() {
666 
667  var targetWin = Desktop.desktop.getWindowById(winId);
668  Debug.log("Create Dashboard Window Menu " +
669  targetWin.isMaximized() + "-" + targetWin.isMinimized());
670 
671  var menuItems = [
672  targetWin.isMaximized()?
673  "Restore Window":"Maximize Window",
674  targetWin.isMinimized()?
675  "Restore Window":"Minimize Window",
676  "Close Window"
677  ];
678  var menuItemHandlers = [
679  "Desktop.desktop.maximizeWindowById("+ winId + ")",
680  "Desktop.desktop.minimizeWindowById("+ winId + ")",
681  "Desktop.desktop.closeWindowById("+ winId + ")",
682  ];
683  Debug.log("createEditTableMenu()");
684  SimpleContextMenu.createMenu(
685  menuItems,
686  menuItemHandlers,
687  "DesktopIconContextMenu", //element ID
688  event.pageX-1,event.pageY-1, //top left position
689  Desktop.desktop.dashboard.getDefaultDashboardColor(), //primary color
690  "white" //secondary color
691  );
692 
693  },500); //end timeout handler
694  }
695 
696  //------------------------------------------------------------------
697  //handle class construction ----------------------
698  //------------------------------------------------------------------
699 
700  this.dashboardElement = _dashboardElement = document.createElement("div");
701  this.dashboardElement.setAttribute("class", "DesktopDashboard");
702  this.dashboardElement.setAttribute("id", "DesktopDashboard");
703 
704  //create top bar
705  _topBar = document.createElement("div");
706  _topBar.setAttribute("class", "DesktopDashboard-topBar");
707  _topBar.style.position = "absolute";
708  _topBar.style.zIndex = z;
709  _topBar.style.backgroundColor = _defaultDashboardColor;
710 
711  var tmpBtn = document.createElement("div");
712  tmpBtn.setAttribute("class", "DesktopDashboard-button DesktopDashboard-button-left");
713  tmpBtn.innerHTML = "<a href='#' title='Click to toggle side Window Bar'>" +
714  "<img id='dashboard_bi_arrow' src='/WebPath/images/dashboardImages/icon-Bi-arrow-gray.png'></a>";
715  tmpBtn.onmouseup = _toggleWindowDashboard;
716  _topBar.appendChild(tmpBtn);
717 
718  tmpBtn = document.createElement("div");
719  tmpBtn.setAttribute("class", "DesktopDashboard-button DesktopDashboard-button-left");
720  tmpBtn.innerHTML = "<a href='#' title='Click to open default window layouts'>Layouts</a>";
721  tmpBtn.onmouseup = _windowDashboardLayoutsDropDown;
722  _topBar.appendChild(tmpBtn);
723 
724  tmpBtn = document.createElement("div");
725  tmpBtn.setAttribute("class", "DesktopDashboard-button DesktopDashboard-button-left");
726  tmpBtn.innerHTML = "<a href='#' title='Click to automatically arrange and tile windows'>Tile</a>";
727  tmpBtn.onmouseup = _windowDashboardOrganize;
728  _topBar.appendChild(tmpBtn);
729 
730  _showDesktopBtn = document.createElement("div");
731  _showDesktopBtn.setAttribute("class", "DesktopDashboard-button DesktopDashboard-button-left");
732  _showDesktopBtn.innerHTML = "<a href='#' title='Click to toggle minimize/restore all windows'>Show Desktop</a>";
733  _showDesktopBtn.onmouseup = _windowDashboardToggleWindows;
734  _topBar.appendChild(_showDesktopBtn);
735 
736  _fullScreenBtn = document.createElement("div");
737  _fullScreenBtn.setAttribute("class", "DesktopDashboard-button DesktopDashboard-button-left");
738  this.redrawFullScreenButton();
739  _fullScreenBtn.onmouseup = Desktop.desktop.toggleFullScreen;
740  _topBar.appendChild(_fullScreenBtn);
741 
742  _fullScreenRefreshBtn = document.createElement("div");
743  _fullScreenRefreshBtn.setAttribute("class", "DesktopDashboard-button DesktopDashboard-button-left");
744  this.redrawRefreshButton();
745  _fullScreenRefreshBtn.onmouseup = Desktop.handleFullScreenWindowRefresh;
746  _topBar.appendChild(_fullScreenRefreshBtn);
747 
748  //user with lock on far right.. because it is the highest priority for user to see
749  tmpBtn = document.createElement("div");
750  tmpBtn.setAttribute("class", "DesktopDashboard-button-right");
751  tmpBtn.setAttribute("id", "DesktopDashboard-serverConnectionStatus");
752  tmpBtn.setAttribute("title", "Click to attempt to reconnect the server. You could also try refreshing the page, or if the problem persists contact the ots admins.");
753  tmpBtn.style.display = "none";
754  tmpBtn.style.color = "rgb(255,150,0)";
755  _topBar.appendChild(tmpBtn);
756 
757  //user with lock on far right.. because it is the highest priority for user to see
758  tmpBtn = document.createElement("div");
759  tmpBtn.setAttribute("class", "DesktopDashboard-button-right");
760  tmpBtn.setAttribute("id", "DesktopDashboard-userWithLock");
761  tmpBtn.style.display = "none";
762  tmpBtn.style.marginTop = "4px";
763  _topBar.appendChild(tmpBtn);
764 
765  tmpBtn = document.createElement("div");
766  tmpBtn.setAttribute("class", "DesktopDashboard-button-right");
767  tmpBtn.innerHTML = "<a target='_blank' href='" +
768  "https://cdcvs.fnal.gov/redmine/projects/otsdaq/wiki/Otsdaq_User_Manual" +
769  " 'title='Click to open ots documentation in a new tab' ><img src='/WebPath/images/dashboardImages/icon-Help.png'></a>";
770  _topBar.appendChild(tmpBtn);
771 
772  if(Desktop.desktop.security == Desktop.SECURITY_TYPE_DIGEST_ACCESS ||
773  Desktop.desktop.security == Desktop.SECURITY_TYPE_NONE) //dont show features if in wizard mode
774  {
775  tmpBtn = document.createElement("div");
776  tmpBtn.setAttribute("class", "DesktopDashboard-button-right DesktopDashboard-user-account DesktopDashboard-user-logout");
777  tmpBtn.innerHTML = "<a href='#' title='Click to sign out of your account'>Sign out</a>";
778  tmpBtn.onmouseup = Desktop.logout;
779  _topBar.appendChild(tmpBtn);
780 
781  tmpBtn = document.createElement("div");
782  tmpBtn.setAttribute("class", "DesktopDashboard-button-right");
783  tmpBtn.setAttribute("id", "DesktopDashboard-settings-icon");
784  tmpBtn.innerHTML = "<a href='Javascript:var win = Desktop.desktop.addWindow(\"Settings\",Desktop.desktop.login.getUsername()," +
785  "\"/WebPath/html/UserSettings.html\",true);' title='Click to open settings window'><img src='/WebPath/images/dashboardImages/icon-Settings.png'></a>";
786  _topBar.appendChild(tmpBtn);
787 
788  tmpBtn = document.createElement("div");
789  tmpBtn.setAttribute("class", "DesktopDashboard-user-account");
790  tmpBtn.setAttribute("id", "DesktopDashboard-user-displayName");
791  tmpBtn.innerHTML = "";
792  _topBar.appendChild(tmpBtn);
793  }
794  else
795  Debug.log("Desktop Dashboard is in Wizard mode",Debug.LOW_PRIORITY);
796 
797  this.dashboardElement.appendChild(_topBar);
798  Debug.log("Desktop Dashboard Top Bar created",Debug.LOW_PRIORITY);
799 
800  //create window dashboard
801  _windowDashboard = document.createElement("div");
802  _windowDashboard.setAttribute("id", "DesktopDashboard-windowDashboard");
803  _windowDashboard.style.position = "absolute";
804  _windowDashboard.style.zIndex = z;
805  _windowDashboard.style.backgroundColor = _defaultDashboardColor;
806  _toggleWindowDashboard(0,_displayWindowDashboard); //set initial value
807  this.updateWindows();
808  this.dashboardElement.appendChild(_windowDashboard);
809 
810 
811  _dashboardColorPostbox = document.createElement("div");
812  _dashboardColorPostbox.setAttribute("id", "DesktopContent-dashboardColorPostbox");
813  _dashboardColorPostbox.style.display = "none";
814  _dashboardColorPostbox.innerHTML = _defaultDashboardColor; //init to color string
815  this.dashboardElement.appendChild(_dashboardColorPostbox);
816 
817 
818  //add mouse handlers
819  _windowDashboard.onmousemove = Desktop.handleWindowMouseMove;
820  _windowDashboard.onmousedown = Desktop.handleWindowMouseDown;
821  _windowDashboard.onmouseup = Desktop.handleWindowMouseUp;
822 
823  _windowDashboardWindowCSSRule = _getDashboardWindowWidthCSSRule(); //get CSS rule for the dashboard window divs
824 
825  Debug.log("Desktop Window Dashboard created",Debug.LOW_PRIORITY);
826 
827  Debug.log("Desktop Dashboard created",Debug.LOW_PRIORITY);
828  }
829 
830 }
831 
832 
833 
834 
835 
836 
837 
838 
839 
840