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