otsdaq_utilities  v2_04_02
ViewerRootHud.js
1 //Hud "class" for ViewerRoot
2 
3 
4 ViewerRoot.createHud = function() {
5 
6 
7  //"memeber" functions
8  // this.handleWindowResize()
9  // this.checkboxUpdate(i)
10  // this.handlerRefreshPeriodChange(v)
11  // this.radioSelect(i)
12  // this.handleDirContents(req)
13  // handleUserPreferences(req)
14  // findDir(path,currDir,currPath)
15  // redrawDirectoryDisplay(currDir,tabSz,path,str)
16  // this.collapseDirectory(dirPath)
17  // this.changeDirectory(dirPath)
18  // animateDropDown()
19  // mouseOverDropDown()
20  // mouseOutDropDown(event)
21  // this.toggleControls()
22  // this.toggleAdminControls(type, path)
23  // this.makeConfigDir()
24  // this.saveConfigFile()
25  // this.removeConfigPath()
26  // this.adminControlsReqHandler()
27  // this.popUpVerification()
28  // this.clearPopUpVerification()
29 
30  var hudMouseOverDiv;
31  var animationTargetTop, isDropDownAnimating, isDropDownDown;
32 
33  var hudDirBrowserDiv;
34  var hudAdminSettingsDiv;
35  var hudPopUpDiv = 0;
36 
37  var displayingControls = false;
38  var PRE_MADE_ROOT_CFG_DIR = "Pre-made Views";
39  var adminControlsPath;
40 
41  var DIR_BRW_HDR_MAX_SIZE = 30;
42  var DIR_DISP_TAB_SZ = 16;
43  var TUPLE_TYPE = 0, TUPLE_NAME = 1, TUPLE_CONTENT = 2, TUPLE_PARENT = 3;
44  var TUPLE_TYPE_FILE = 1, TUPLE_TYPE_DIR = 1<<1, TUPLE_TYPE_DIR_EXPANDED = 1<<2; //bit mask
45  var dirStruct = [[TUPLE_TYPE_DIR,"",0,0]]; //always start with root existing and define from there
46  //structure is embedded tuples [<file type>,<name>,<embedded directory contents> or <root file content> for file, <parent ptr>]
47  var currDirPtr = dirStruct[0]; //pointer to the directory level that is currently displayed
48 
49  this.handleWindowResize = function() {
50  //Debug.log("ViewerRoot Hud handleWindowResize");
51 
52  if(ViewerRoot.hudAutoHide)
53  this.hudMouseOverDiv.style.left = window.innerWidth - this.hudMouseOverDiv.offsetWidth - ViewerRoot.HUD_MARGIN_RIGHT + "px";
54  else
55  {
56  this.hudMouseOverDiv.style.left = window.innerWidth - this.hudMouseOverDiv.offsetWidth + "px";
57  this.hudMouseOverDiv.style.top = -15 + "px";
58  }
59 
60  hudDirBrowserDiv.style.width = this.hudDiv.offsetWidth - 45 + "px";
61  hudDirBrowserDiv.style.height = window.innerHeight - 190 + "px";
62 
63  if(ViewerRoot.userPermissions >= ViewerRoot.ADMIN_PERMISSIONS_THRESHOLD)
64  document.getElementById("ViewerRoot-hudControlsIcon").style.display = "block";
65  else
66  document.getElementById("ViewerRoot-hudControlsIcon").style.display = "none";
67  } //end handleWindowResize()
68 
69  //should match response by handleUserPreferences()
70  this.checkboxUpdate = function(i) {
71  var chk;
72  if (i == 3) {
73  chk = document.getElementById("hardRefreshCheckbox");
74  ViewerRoot.hardRefresh = chk.checked; //hard refresh
75  console.log("checkboxUpdate: hardRefresh: " + chk.checked);
76  DesktopContent.XMLHttpRequest("Request?RequestType=setUserPreferences&hardRefresh="+
77  (chk.checked?1:0),
78  "",
79  "" /*reqHandler*/,
80  0 /*reqParam*/,
81  0 /*progressHandler*/,
82  0 /*callHandlerOnErr*/,
83  true /*doNoShowLoadingOverlay*/);
84  }
85  else
86  {
87  chk = document.getElementById("hudCheckbox" + i);
88  Debug.log("ViewerRoot Hud checkboxUpdate " + i + "=" + chk.checked);
89 
90  if(i==0)
91  {
92  ViewerRoot.autoRefreshDefault = chk.checked; //auto refresh
93 
94  DesktopContent.XMLHttpRequest("Request?RequestType=setUserPreferences&autoRefresh="+
95  (chk.checked?1:0),
96  "",
97  ""/*reqHandler*/,
98  0 /*reqParam*/,
99  0 /*progressHandler*/,
100  0 /*callHandlerOnErr*/,
101  true /*doNoShowLoadingOverlay*/);
102  }
103  else if(i==1)
104  {
105  ViewerRoot.hudAutoHide = chk.checked; //auto hide
106  ViewerRoot.handleWindowResize();
107 
108  DesktopContent.XMLHttpRequest("Request?RequestType=setUserPreferences&autoHide="+
109  (chk.checked?1:0),
110  "",
111  ""/*reqHandler*/,
112  0 /*reqParam*/,
113  0 /*progressHandler*/,
114  0 /*callHandlerOnErr*/,
115  true /*doNoShowLoadingOverlay*/);
116  }
117  else if(i==2)
118  {
119  ViewerRoot.pauseRefresh = chk.checked; //pause auto refresh
120 
121  //reset auto refresh array with re-activation of auto refresh
122  // just in case...
123  if(!ViewerRoot.pauseRefresh) ViewerRoot.autoRefreshMatchArr = [];
124  }
125 
126  }
127 
128  } //end checkboxUpdate()
129 
130  this.handlerRefreshPeriodChange = function(v) {
131  v = parseInt(v);
132  if(!v || v < 1) v = 1;
133  if(v > 9999999) v = 9999999;
134  Debug.log("ViewerRoot Hud handlerRefreshPeriodChange " + v);
135  document.getElementById("hudAutoRefreshPeriod").value = v;
136  ViewerRoot.autoRefreshPeriod = v;
137  DesktopContent.XMLHttpRequest("Request?RequestType=setUserPreferences&autoRefreshPeriod="+
138  ViewerRoot.autoRefreshPeriod,
139  "",
140  ""/*reqHandler*/,
141  0 /*reqParam*/,
142  0 /*progressHandler*/,
143  0 /*callHandlerOnErr*/,
144  true /*doNoShowLoadingOverlay*/);
145  if(ViewerRoot.autoRefreshTimer) window.clearInterval(ViewerRoot.autoRefreshTimer);
146  ViewerRoot.autoRefreshTimer = window.setInterval(ViewerRoot.autoRefreshTick,
147  ViewerRoot.autoRefreshPeriod);
148  } //end handlerRefreshPeriodChange()
149 
150  this.radioSelect = function(i) {
151  Debug.log("ViewerRoot Hud radioSelect " + i);
152  ViewerRoot.nextObjectMode = i;
153 
154  DesktopContent.XMLHttpRequest("Request?RequestType=setUserPreferences&radioSelect="+i);
155  } //end radioSelect()
156 
157  this.handleDirContents = function(req) {
158  Debug.log("ViewerRoot Hud handleDirContents " + req.responseText);
159 
160  var path = DesktopContent.getXMLValue(req,'path');
161  if(!path)
162  {
163  Debug.log("ViewerRoot Hud handleDirContents no path returned",Debug.HIGH_PRIORITY);
164  return;
165  }
166 
167  //add results into directory structure
168  //var paths = path.split("/");
169  //Debug.log("ViewerRoot Hud handleDirContents " + paths.length + ":" + paths);
170 
171  //find path
172  var baseDir = findDir(path);
173  if(!baseDir)
174  {
175  Debug.log("ViewerRoot Hud handleDirContents path not found");
176  return;
177  }
178  //Debug.log("ViewerRoot Hud handleDirContents baseDir " + baseDir);
179 
180 
181  baseDir[TUPLE_CONTENT] = []; //clear all current content
182  baseDir[TUPLE_TYPE] |= TUPLE_TYPE_DIR_EXPANDED; //expand the directory
183 
184  var dirs = req.responseXML.getElementsByTagName("dir");
185  var files = req.responseXML.getElementsByTagName("file");
186 
187  for(var i=0;i<dirs.length;++i) //add dirs
188  baseDir[TUPLE_CONTENT][baseDir[TUPLE_CONTENT].length] = [TUPLE_TYPE_DIR,dirs[i].getAttribute("value").replace(/[\/]+/g, ''),0,baseDir];
189 
190  for(var i=0;i<files.length;++i) //add files
191  baseDir[TUPLE_CONTENT][baseDir[TUPLE_CONTENT].length] = [TUPLE_TYPE_FILE,files[i].getAttribute("value").replace(/[\/]+/g, ''),0,baseDir];
192 
193  //Debug.log("ViewerRoot Hud handleDirContents baseDir " + baseDir);
194 
195  redrawDirectoryDisplay();
196  } //end handleDirContents()
197 
198  //set user preferences based on server response
199  // should match response by this.checkboxUpdate() and this.radioSelect()
200  var handleUserPreferences = function(req) {
201  Debug.log("handleUserPreferences");
202  var radioSelect = DesktopContent.getXMLValue(req,'radioSelect');
203  if(radioSelect && radioSelect != "")
204  {
205  Debug.log("setting radioSelect=" + (radioSelect|0));
206  ViewerRoot.nextObjectMode = radioSelect|0;
207  document.getElementById("newRootObjectModeRadio" + (radioSelect|0)).checked = true;
208  }
209  var autoRefresh = DesktopContent.getXMLValue(req,'autoRefresh');
210  if(autoRefresh && autoRefresh != "")
211  {
212  Debug.log("setting autoRefresh=" + (autoRefresh|0));
213  var chk = document.getElementById("hudCheckbox" + 0);
214  chk.checked = (autoRefresh|0)?true:false;
215  Debug.log("setting autoRefresh=" + chk.checked);
216  ViewerRoot.autoRefreshDefault = chk.checked; //auto refresh
217  }
218  var autoHide = DesktopContent.getXMLValue(req,'autoHide');
219  if(autoHide && autoHide != "")
220  {
221  Debug.log("setting autoHide=" + (autoHide|0));
222  var chk = document.getElementById("hudCheckbox" + 1);
223  chk.checked = (autoHide|0)?true:false;
224  Debug.log("setting autoHide=" + chk.checked);
225  ViewerRoot.hudAutoHide = chk.checked; //auto hide
226  ViewerRoot.handleWindowResize();
227  }
228  var hardRefresh = DesktopContent.getXMLValue(req,'hardRefresh');
229  if(hardRefresh !== undefined && hardRefresh !== "")
230  {
231  hardRefresh = hardRefresh|0; //force to integer
232  Debug.log("setting hardRefresh=" + hardRefresh);
233  ViewerRoot.hardRefresh = hardRefresh; //hard refresh
234  }
235  var autoRefreshPeriod = DesktopContent.getXMLValue(req,'autoRefreshPeriod');
236  if(autoRefreshPeriod && autoRefreshPeriod !== "")
237  {
238  Debug.log("setting autoRefreshPeriod=" + autoRefreshPeriod);
239  ViewerRoot.autoRefreshPeriod = autoRefreshPeriod; //autoRefreshPeriod
240  document.getElementById("hudAutoRefreshPeriod").value = ViewerRoot.autoRefreshPeriod;
241  }
242  } // end handleUserPreferences()
243 
244  //return tuple to path, if not found return 0
245  // recursive function
246  // calling syntax is
247  // var baseDir = findDir(path);
248  var findDir = function(path,currDir,currPath) {
249  if(!currDir)
250  {
251  currDir = dirStruct[0];
252  currPath = currDir[TUPLE_NAME] + "/";
253  //Debug.log("ViewerRoot Hud findDir " + currPath);
254  //Debug.log("ViewerRoot Hud findDir path to find " + path);
255  }
256 
257  if(currDir[TUPLE_TYPE] & TUPLE_TYPE_DIR == 0) return 0; //current path is not a directory, path not found
258  if(path == currPath) return currDir; //path is found
259  if(!currDir[TUPLE_CONTENT]) return 0; //no structure to current path, path not found
260 
261  //traverse directory content
262  var retVal = 0;
263  for(var i=0;i<currDir[TUPLE_CONTENT].length;++i)
264  {
265  if(currDir[TUPLE_CONTENT][i][TUPLE_TYPE] & TUPLE_TYPE_DIR == 0) continue; //child is not a directory so skip
266 
267  retVal = findDir(path,currDir[TUPLE_CONTENT][i],currPath + currDir[TUPLE_CONTENT][i][TUPLE_NAME] + "/");
268  if(retVal) return retVal;
269  }
270  }
271 
272  //return complete path of tuplePtr, return "/" if failure
273  var getPath = function(tuplePtr) {
274  if(!tuplePtr) return "/";
275  var path = tuplePtr[TUPLE_NAME] + "/";
276  while(tuplePtr[TUPLE_PARENT])
277  {
278  path = tuplePtr[TUPLE_PARENT][TUPLE_NAME] + "/" + path;
279  tuplePtr = tuplePtr[TUPLE_PARENT];
280  }
281  return path;
282  } //end findDir()
283 
284 
285  //draw for current directory, currDir, as starting level
286  // recursive function
287  // calling syntax redrawDirectoryDisplay(); //will redraw current directory
288  var redrawDirectoryDisplay = function(currDir,tabSz,path,str) {
289 
290  var applyStr = false;
291  var locPath;
292  var dirClr;
293  if(!currDir) //init first time
294  {
295  hudDirBrowserDiv.innerHTML = ""; //clear all
296  str = "";
297  currDir = currDirPtr;
298  tabSz = 0;
299  path = getPath(currDirPtr);
300  applyStr = true;
301  //Debug.log("ViewerRoot Hud redrawDirectoryDisplay FIRST path " + path);
302 
303  locPath = path.length>DIR_BRW_HDR_MAX_SIZE?("..." + path.substr(path.length-DIR_BRW_HDR_MAX_SIZE+3)):path;
304  str += "<div id='ViewerRoot-hudDirBrowser-header'>";
305  str += "<a title='Refresh\n" + path + "' style='float:left' href='Javascript:ViewerRoot.hud.changeDirectory(\"" +
306  path + "\");'>" + locPath + "</a>";
307  str += "<a title='Change to Parent Directory' style='float:right' href='Javascript:ViewerRoot.hud.changeDirectory(\"" +
308  getPath(currDirPtr[TUPLE_PARENT]) + "\");'> cd .. </a>";
309  str += "</div>";
310  str += "<div style='clear:both'></div>";
311  }
312 
313  for(var i=0;currDir[TUPLE_CONTENT] && i<currDir[TUPLE_CONTENT].length;++i)
314  {
315  locPath = path + currDir[TUPLE_CONTENT][i][TUPLE_NAME];
316  if(currDir[TUPLE_CONTENT][i][TUPLE_TYPE] & TUPLE_TYPE_DIR) locPath += "/"; //if directory add slash
317 
318  str += "<div class='ViewerRoot-hudDirBrowser-item' style='margin-left:" + tabSz + "px;'>"; //item container
319 
320  dirClr = currDir[TUPLE_CONTENT][i][TUPLE_NAME].indexOf(".root") >= 0?"#B9E6E6":"gray";
321  if(currDir[TUPLE_CONTENT][i][TUPLE_TYPE] & TUPLE_TYPE_DIR_EXPANDED) //dir currently expanded, so action is to minimize it
322  {
323  str += "<a title='Collapse Directory\n" + locPath + "' href='Javascript:ViewerRoot.hud.collapseDirectory(\"" + locPath + "\");'> + </a> ";
324 
325  str += "<a title='Change Directory\n" + locPath + "' style='color:" + dirClr + "' href='Javascript:ViewerRoot.hud.changeDirectory(\"" + locPath + "\");'>" + currDir[TUPLE_CONTENT][i][TUPLE_NAME] + "</a>";
326  }
327  else if(currDir[TUPLE_CONTENT][i][TUPLE_TYPE] & TUPLE_TYPE_DIR) //dir currently minimized, so action is to expand it
328  {
329  str += "<a title='Expand Directory\n" + locPath + "' style='color:gray' href='Javascript:ViewerRoot.getDirectoryContents(\"" + locPath + "\");'> - </a> ";
330 
331  str += "<a title='Change Directory\n" + locPath + "' style='color:" + dirClr + "' href='Javascript:ViewerRoot.hud.changeDirectory(\"" + locPath + "\");'>" + currDir[TUPLE_CONTENT][i][TUPLE_NAME] + "</a>";
332  }
333  else if(currDir[TUPLE_CONTENT][i][TUPLE_TYPE] & TUPLE_TYPE_FILE) //file, so action is to launch it
334  {
335  if(locPath.indexOf(".root") > 0) //root file
336  {
337  str += "<a title='Open Root File\n" + locPath + "' href='Javascript:ViewerRoot.rootReq(\"" + locPath + "\");'>" +
338  "<img style='margin:2px 2px -2px 0;' src='/WebPath/js/visualizers_lib/ViewerRoot_lib/img/histo.png'>";
339  str += currDir[TUPLE_CONTENT][i][TUPLE_NAME] + "</a>";
340  }
341  else if(locPath.indexOf(".rcfg") > 0) //root config file
342  {
343  str += "<a title='Open Root File\n" + locPath + "' href='Javascript:ViewerRoot.rootConfigReq(\"" + locPath + "\");'>" +
344  "<img style='margin:2px 2px -2px 0;' src='/WebPath/js/visualizers_lib/ViewerRoot_lib/img/histo3d.png'>";
345  str += currDir[TUPLE_CONTENT][i][TUPLE_NAME] + "</a>";
346  }
347  else
348  Debug.log("ViewerRoot Hud redrawDirectoryDisplay unknown file extension");
349  }
350  else
351  alert("Impossible DIRECTORY error!! Notify admins");
352 
353  str += "</div>"; //close item container
354 
355  //recursive call
356  if(currDir[TUPLE_CONTENT][i][TUPLE_TYPE] & TUPLE_TYPE_DIR_EXPANDED)
357  str = redrawDirectoryDisplay(currDir[TUPLE_CONTENT][i],tabSz+DIR_DISP_TAB_SZ,
358  path + currDir[TUPLE_CONTENT][i][TUPLE_NAME] + "/",str);
359  }
360 
361  //if admin pre-made view directory, add ability to MAKE directory or SAVE new premade view
362  if(ViewerRoot.userPermissions >= ViewerRoot.ADMIN_PERMISSIONS_THRESHOLD &&
363  path.indexOf(PRE_MADE_ROOT_CFG_DIR) >= 0)
364  {
365  Debug.log("ViewerRoot Hud redrawDirectoryDisplay path " + path);
366 
367  var iconArr = ["folderopen","page","remove"];//,"refresh"];
368  var captionArr = ["Make New Directory","Save New View","Delete Pre-made File/Folder!"];//,"Toggle Hard/Soft Refresh"];
369  for(var i=0;i<captionArr.length;++i)
370  {
371  str += "<div class='ViewerRoot-hudDirBrowser-item' style='margin-left:" + tabSz + "px;'>"; //item container
372  str += "<a style='color:gray' title='Admin action: " + captionArr[i] +
373  "' href='Javascript:ViewerRoot.hud.toggleAdminControls(" + i + ",\"" + path + "\");'>" +
374  "<img style='margin:2px 2px -2px 0;' src='/WebPath/js/visualizers_lib/ViewerRoot_lib/img/" + iconArr[i] + ".gif'>";
375  str += captionArr[i] + "</a>";
376  str += "</div>"; //close item container
377  }
378  }
379 
380  if(applyStr)
381  hudDirBrowserDiv.innerHTML = str;
382  else
383  return str;
384  } //end redrawDirectoryDisplay()
385 
386 
387  //minimize directory is done by removing the structure from dirPath
388  this.collapseDirectory = function(dirPath) {
389  Debug.log("ViewerRoot Hud collapseDirectory " + dirPath);
390 
391  var baseDir = findDir(dirPath);
392 
393  baseDir[TUPLE_CONTENT] = 0; //clear array to 0
394  baseDir[TUPLE_TYPE] &= ~TUPLE_TYPE_DIR_EXPANDED; //unset dir expanded flag
395 
396  redrawDirectoryDisplay(); //redraw current directory
397  } //end collapseDirectory()
398 
399  this.changeDirectory = function(dirPath) {
400  Debug.log("ViewerRoot Hud changeDirectory " + dirPath);
401  currDirPtr = findDir(dirPath);
402  ViewerRoot.getDirectoryContents(dirPath);
403  } // end changeDirectory()
404 
405 
406  // animateDropDown ~~
407  var animateDropDown = function() {
408  var dir = (animationTargetTop - hudMouseOverDiv.offsetTop > 0)? 1: -1;
409 
410  var tmpTop = hudMouseOverDiv.offsetTop + dir*ViewerRoot.HUD_DROP_DOWN_SPEED;
411  if(Math.abs(tmpTop - animationTargetTop) <= ViewerRoot.HUD_DROP_DOWN_SPEED) //done
412  {
413  hudMouseOverDiv.style.top = animationTargetTop + "px";
414  isDropDownAnimating = false;
415  return;
416  }
417  //else still going towards target
418  hudMouseOverDiv.style.top = tmpTop + "px";
419  window.setTimeout(animateDropDown,30);
420  } //end animateDropDown()
421 
422  // mouseOverDropDown ~~
423  var mouseOverDropDown = function() {
424 
425  if(isDropDownAnimating) return; //do nothing if animating currently
426 
427  if(!ViewerRoot.hudAutoHide) return; //if not autohide lock size
428 
429  if(!isDropDownDown) //start animation
430  {
431  isDropDownDown = true;
432  isDropDownAnimating = true;
433  animationTargetTop = -15;
434  window.setTimeout(animateDropDown,30);
435  }
436  } //end mouseOverDropDown()
437 
438  // mouseOutDropDown ~~
439  var mouseOutDropDown = function(event) {
440  if(isDropDownAnimating) return; //do nothing if animating currently
441 
442  if(event)
443  {
444  var e = event.toElement || event.relatedTarget;
445  while(e) //if moving within drop down menu ignore
446  {
447  if(e == this) return;
448  e = e.parentNode;
449  }
450  }
451 
452  if(!ViewerRoot.hudAutoHide) return ViewerRoot.hud.handleWindowResize(); //if not autohide lock size
453 
454  if(isDropDownDown) //start animation
455  {
456  isDropDownDown = false;
457  isDropDownAnimating = true;
458  animationTargetTop = 15 - hudMouseOverDiv.offsetHeight;
459  window.setTimeout(animateDropDown,30);
460  }
461  } //end mouseOutDropDown()
462 
463  //types
464  this.toggleControls = function() {
465  displayingControls = !displayingControls;
466  Debug.log("ViewerRoot Hud toggleControls " + displayingControls);
467 
468  if(displayingControls) //show admin controls in browser window
469  {
470  hudDirBrowserDiv.innerHTML = ""; //clear all
471  var str = "";
472  if(ViewerRoot.hardRefresh)
473  str += "<input type='checkbox' id='hardRefreshCheckbox' checked ";
474  else
475  str += "<input type='checkbox' id='hardRefreshCheckbox' ";
476  str += "onchange='if(this.checked) ViewerRoot.hardRefresh = 1; else ViewerRoot.hardRefresh = 0; ViewerRoot.hud.checkboxUpdate(3);'>Hard Refresh";
477 
478  str += "<br><div id='hudAdminControlStatus'></div>";
479  str += "<br>";
480  str += "<a href='javascript:ViewerRoot.hud.toggleControls();' title='Return to ROOT Browser' " +
481  "<u>Return to Browser</u></a>";
482  hudDirBrowserDiv.innerHTML = str;
483  }
484  else //return to showing current directory
485  ViewerRoot.hud.changeDirectory(getPath(currDirPtr)); //return and refresh directory contents from server
486  } //end this.toggleControls()
487 
488  //types
489  // 0 - make directory
490  // 1 - save file
491  // 2 - delete
492  this.toggleAdminControls = function(type, path) {
493  displayingControls = !displayingControls;
494  Debug.log("ViewerRoot Hud toggleAdminControls " + displayingControls);
495 
496  if(displayingControls) //show admin controls in browser window
497  {
498  Debug.log("ViewerRoot Hud toggleAdminControls " + type + ": " + path);
499 
500  adminControlsPath = path;
501  hudDirBrowserDiv.innerHTML = ""; //clear all
502 
503  var str = "";
504 
505  if(type == 0) //make directory
506  {
507  str += "Make a new ROOT Viewer<br>Configuration Directory<br>at path:<br><br>" + path + "<br>";
508  str += "<input type='text' id='hudAdminControlField' onkeyup='document.getElementById(\"hudAdminControlStatus\").innerHTML=\"\";' size='20' value=''><br>";
509  str += "<input type='button' onmouseup=\"ViewerRoot.hud.popUpVerification(" +
510  "'Are you sure you want to create directory with name &quot;REPLACE&quot;?','ViewerRoot.hud.makeConfigDir');\" value='Make New Directory'>";
511  }
512  else if(type == 1) //new file
513  {
514  str += "Save a new ROOT Viewer<br>Configuration File for all users <br>based on the current view<br>at path:<br><br>" + path + "<br>";
515  str += "<input type='text' id='hudAdminControlField' size='20' value=''><br>";
516 
517  str += "<div ><input type='checkbox' id='hudSaveFileRunWildCardCheckbox'>" +
518  "<label for='hudSaveFileRunWildCardCheckbox' >" + "Use Wildcard Run #" + "</label></div>";
519 
520  str += "<input type='button' onmouseup=\"ViewerRoot.hud.popUpVerification(" +
521  "'Are you sure you want to save a file with name &quot;REPLACE&quot;?','ViewerRoot.hud.saveConfigFile');\" value='Save New File'>";
522  }
523  else if(type == 2) //delete path
524  {
525  str += "Delete a ROOT Viewer<br>Configuration Directory or File<br>at path:<br><br>" + path + "<br>";
526  str += "<input type='text' id='hudAdminControlField' onkeyup='document.getElementById(\"hudAdminControlStatus\").innerHTML=\"\";' size='20' value=''><br>";
527  str += "<input type='button' onmouseup=\"ViewerRoot.hud.popUpVerification(" +
528  "'Are you sure you want to delete file or directory with name &quot;REPLACE&quot;?','ViewerRoot.hud.removeConfigPath');\" value='Delete Path'><br>";
529 
530  }
531  else
532  {
533  Debug.log("Unknown admin type " + type);
534  throw("Unknown type?");
535  }
536 
537  str += "<br><div id='hudAdminControlStatus'></div>";
538  str += "<br>";
539  str += "<a href='javascript:ViewerRoot.hud.toggleAdminControls();' title='Return to ROOT Browser' " +
540  "<u>Return to Browser</u></a>";
541  hudDirBrowserDiv.innerHTML = str;
542 
543  }
544  else //return to showing current directory
545  ViewerRoot.hud.changeDirectory(getPath(currDirPtr)); //return and refresh directory contents from server
546  } //end toggleAdminControls()
547 
548  this.makeConfigDir = function() {
549  var dir = document.getElementById('hudAdminControlField').value;
550  Debug.log("ViewerRoot Hud makeConfigDir " + dir);
551 
552  DesktopContent.XMLHttpRequest("Request?RequestType=rootAdminControls&cmd=mkdir", "path="+adminControlsPath+"&name="+dir, ViewerRoot.hud.adminControlsReqHandler,
553  ""/*reqHandler*/,
554  0 /*reqParam*/,
555  0 /*progressHandler*/,
556  0 /*callHandlerOnErr*/,
557  true /*doNoShowLoadingOverlay*/);
558 
559  } //end makeConfigDir()
560 
561  this.saveConfigFile = function() {
562 
563  //create file string based on current configuration
564  if(ViewerRoot.numPositionsTiled < 1)
565  {
566  document.getElementById('hudAdminControlStatus').innerHTML = "You must have at least 1 Root object in your configuration to save it.";
567  return;
568  }
569 
570  var file = document.getElementById('hudAdminControlField').value;
571  var wildcard = document.getElementById('hudSaveFileRunWildCardCheckbox').checked;
572 
573  var fileStr = "";
574 
575  fileStr += "<ROOT><DATA>";
576  fileStr += "<numPositionsTiled>" + ViewerRoot.numPositionsTiled + "</numPositionsTiled>";
577  fileStr += "<runNumWildcard>" + (wildcard?1:0) + "</runNumWildcard>";
578 
579  for(var i=0;i<ViewerRoot.rootElArr.length;++i)
580  {
581  fileStr += "<rootObjName>" + ViewerRoot.rootObjNameArr[i] + "</rootObjName>";
582  fileStr += "<rootPos>" + ViewerRoot.rootPosArr[i] + "</rootPos>";
583  fileStr += "<rootIsTransparent>" + (ViewerRoot.rootIsTransparentArr[i]?1:0) + "</rootIsTransparent>";
584  fileStr += "<rootIsAutoRefresh>" + (ViewerRoot.rootIsAutoRefreshArr[i]?1:0) + "</rootIsAutoRefresh>";
585  }
586 
587  fileStr += "</DATA></ROOT>";
588  Debug.log("ViewerRoot Hud saveConfigFile fileStr " + fileStr);
589 
590  DesktopContent.XMLHttpRequest("Request?RequestType=rootAdminControls&cmd=save",
591  "path="+adminControlsPath+"&name="+file+"&config="+fileStr, ViewerRoot.hud.adminControlsReqHandler);
592  } //end saveConfigFile()
593 
594  this.removeConfigPath = function() {
595 
596  var target = document.getElementById('hudAdminControlField').value;
597  Debug.log("ViewerRoot Hud removeConfigPath " + target);
598 
599  DesktopContent.XMLHttpRequest("Request?RequestType=rootAdminControls&cmd=delete", "path="+adminControlsPath+"&name="+target, ViewerRoot.hud.adminControlsReqHandler);
600  } //end removeConfigPath()
601 
602  this.adminControlsReqHandler = function(req) {
603  Debug.log("ViewerRoot Hud adminControlsReqHandler " + req.responseText);
604 
605  var status = DesktopContent.getXMLValue(req,'status');
606 
607  if(status == "1") //success indicated
608  ViewerRoot.hud.toggleAdminControls();
609  else
610  document.getElementById('hudAdminControlStatus').innerHTML = status;
611  } //end adminControlsReqHandler()
612 
613  //popUpVerification ~~
614  // asks user if sure
615  // replace REPLACE in prompt with value
616  this.popUpVerification = function(prompt, func) {
617  //remove pop up if already exist
618  if(hudPopUpDiv) hudPopUpDiv.parentNode.removeChild(hudPopUpDiv);
619 
620  var path = document.getElementById('hudAdminControlField').value;
621 
622  var ptrn = /^([a-zA-Z0-9_-]+)$/;
623  if(path.length < 3 || !ptrn.test(path))
624  {
625  document.getElementById('hudAdminControlStatus').innerHTML = "Entry must be at least 3 characters and alpha-numeric with only underscores and dashes.";
626  return;
627  }
628 
629  //replace REPLACE
630  prompt = prompt.replace(/REPLACE/g, path);
631 
632  var el = this.hudDiv;//document.getElementById("adminArea");
633  hudPopUpDiv = document.createElement("div");
634  hudPopUpDiv.setAttribute("class", "hudPopUpDiv");
635  var str = "<div id='hudPopUpText'>" + prompt + "</div>" +
636  "<input type='submit' onmouseup='ViewerRoot.hud.clearPopUpVerification(" + func + ");' value='Yes'> " +
637  "&nbsp;&nbsp;&nbsp;" +
638  "<input type='submit' onmouseup='ViewerRoot.hud.clearPopUpVerification();' value='Cancel'>";
639  hudPopUpDiv.innerHTML = str;
640  el.appendChild(hudPopUpDiv);
641  } //end popUpVerification()
642 
643  //clearPopUpVerification ~~
644  // call func after clearing, if exists
645  this.clearPopUpVerification = function(func) {
646  //remove pop up if already exist
647  if(hudPopUpDiv) hudPopUpDiv.parentNode.removeChild(hudPopUpDiv);
648  hudPopUpDiv = 0;
649  if(func) func();
650  else //Action was cancelled by user
651  document.getElementById('hudAdminControlStatus').innerHTML = "Action was cancelled by user!";
652  } //end clearPopUpVerification()
653 
654  hudMouseOverDiv = this.hudMouseOverDiv = document.createElement('div');
655  hudMouseOverDiv.setAttribute("id", "ViewerRoot-hudMouseOver");//ViewerRoot.hudAutoHide?"ViewerRoot-hudMouseOver":"ViewerRoot-hudMouseOver-locked");
656  hudMouseOverDiv.style.position = "absolute";
657  hudMouseOverDiv.style.zIndex = 100;
658 
659  this.hudDiv = document.createElement('div');
660  this.hudDiv.setAttribute("id","ViewerRoot-hud");// ViewerRoot.hudAutoHide?"ViewerRoot-hud":"ViewerRoot-hud-locked");
661 
662 
663 
664 
665  //create content elements
666  var str = "";
667  str += "With new Root objects...<br>";
668 
669  var chkLabels = ["Auto-Refresh"];
670  var chkDefaults = [""]; //"checked" for default true
671  str += "<div style='float:right'>"
672  for(var i=0;i<chkLabels.length;++i)
673  str += "<input type='checkbox' id='hudCheckbox" + i + "' onchange='ViewerRoot.hud.checkboxUpdate(" + i +
674  ");' " + chkDefaults[i] + "><label for='hudCheckbox" + i + "' >" + chkLabels[i] + "</label>";
675  str += "</div>";
676 
677  var radioLabels = ["Tile","Replace", "Superimpose"];
678  var radioDefault = ViewerRoot.nextObjectMode;
679  for(var i=0;i<radioLabels.length;++i)
680  str += "<input type='radio' id='newRootObjectModeRadio" + i + "' " + (i==radioDefault?"checked":"") +
681  " onchange='ViewerRoot.hud.radioSelect(" + i + ");'" +
682  " name='newRootObjectModeRadio' value='0' /><label for='newRootObjectModeRadio" + i + "'>" + radioLabels[i] + "</label><br>";
683 
684  str += "<hr>";
685 
686  str += "<div id='ViewerRoot-hudDirBrowser'></div>";
687  //var histos = ["TH1F","TH2F","TProfile","TCanvas"];
688  //for(var i=0;i<histos.length;++i)
689  // str += "<a href='javascript:ViewerRoot.rootReq(\""+histos[i]+"\");'>"+histos[i]+"</a><br>";
690  str += "<hr>";
691 
692  str += "<div id='ViewerRoot-hudControlsIcon' " +
693  "style='float:left;margin: -2px 0 -20px 20px; cursor: pointer;' onmouseup='ViewerRoot.hud.toggleControls();' " +
694  "title='Admin Controls'><img width='18px' src='/WebPath/images/dashboardImages/icon-Settings.png'></div>";
695 
696  str += "<div style='float:right; margin:-3px 0 -20px 0;'>";
697  str += "Refresh Period: <input type='text' id='hudAutoRefreshPeriod' onchange='ViewerRoot.hud.handlerRefreshPeriodChange(this.value);' size='6' value='" +
698  ViewerRoot.autoRefreshPeriod + "'> ms</div>";
699 
700  str += "<br>";
701 
702  str += "<a href='javascript:ViewerRoot.clearAll();' title='Clear ROOT objects from view'>Clear</a>";
703 
704  str += "<div style='float:right;' ><input type='checkbox' id='hudCheckbox" + chkLabels.length + "' onchange='ViewerRoot.hud.checkboxUpdate(" + chkLabels.length +
705  ");' " + "" + "><label for='hudCheckbox" + chkLabels.length + "' >" + "Auto-Hide" + "</label></div>";
706 
707  str += "<div style='float:right;margin-right:10px;' ><input type='checkbox' id='hudCheckbox" + (chkLabels.length+1) + "' onchange='ViewerRoot.hud.checkboxUpdate(" + (chkLabels.length+1) +
708  ");' " + "" + "><label for='hudCheckbox" + (chkLabels.length+1) + "' >" + "Pause Refresh" + "</label></div>";
709 
710  this.hudDiv.innerHTML = str;
711 
712 
713 
714 
715 
716 
717  hudMouseOverDiv.appendChild(this.hudDiv);
718 
719  hudMouseOverDiv.style.width = ViewerRoot.HUD_WIDTH + "px";
720  hudMouseOverDiv.onmouseover = mouseOverDropDown;
721  hudMouseOverDiv.onmouseout = mouseOutDropDown;
722  ViewerRoot.omni.appendChild(hudMouseOverDiv);
723 
724  hudDirBrowserDiv = document.getElementById('ViewerRoot-hudDirBrowser');
725 
726  /*
727  hudAdminSettingsDiv = document.createElement('div');
728  hudAdminSettingsDiv.setAttribute("id", "ViewerRoot-hudAdminSettings");
729  hudMouseOverDiv.appendChild(hudAdminSettingsDiv);
730  */
731 
732  if(ViewerRoot.hudAutoHide)
733  {
734  //setup dropdown effect
735  hudMouseOverDiv.style.top = 15 - hudMouseOverDiv.offsetHeight + "px";//hudMouseOverDiv.offsetHeight - 15 + "px";
736 
737  isDropDownDown = false;
738  isDropDownAnimating = true;
739  animationTargetTop = 15 - hudMouseOverDiv.offsetHeight;
740  window.setTimeout(animateDropDown,30);
741  }
742  else
743  this.handleWindowResize();
744 
745  //get user preferences from server
746  DesktopContent.XMLHttpRequest("Request?RequestType=getUserPreferences","",handleUserPreferences);
747 }
748 
749 
750 
751 
752 
753 
754 
755 
756 
757 
758 
759 
760 
761 
762