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