otsdaq_utilities  v2_05_02_indev
RecordWiz_ConfigurationGUI.js
1 
2 
3 // Description of Record Wizard Configuration GUI Functionality/Behavior:
4 //
5 // Example call:
6 // RecordWiz.createWiz(
7 // function(atLeastOneRecordWasCreated)
8 // {
9 // Debug.log("Done at Template! " + atLeastOneRecordWasCreated,
10 // Debug.INFO_PRIORITY);
11 // });
12 //
13 // - User can have LOCK
14 //
15 // Display:
16 // - walk through steps at center of window
17 // - use popup dialog to place at center
18 // - steps:
19 // - (error if unrecognized base path)
20 // - "what is the name of your <record type>?"
21 // - note the active context and config group being modified, with dropdown to
22 // change them.
23 // - "do you want to add it to an existing context or create a new one?"
24 // - if create a new one
25 // - provide default name with edit pencil, and continue
26 //
27 //
28 
31 
32 //public functions:
33 // RecordWiz.createWiz(doneHandler)
34 // - when the user closes the wizard dialog,
35 // doneHandler is called with a bool parameter with true indicating
36 // at least one record was created.
37 
38 
40 //functions:
41  //localParameterCheck()
42  //xdaqContextTooltip()
43  //xdaqApplicationTooltip()
44  //initRecordWizard()
45  //showPrompt(stepIndex,paramObj)
46  // localAddContent()
47  // localAddHandlers()
48  // switch statements
49  // scopeForSetRecordFieldsContent()
50  // localAppSelectHandler(event)
51  // localAddressSelectHandler(event)
52  // localPortSelectHandler(event)
53  // localContextSelectHandler(event)
54  // localGetAllHostInfo()
55  // localRecordsSelectHandler(event)
56  // (stepString + "editConfig").onclick
57  // (stepString + "editContext").onclick
58  // (stepString + "deleteRecordIcon").onclick
59  // localPromptAndHandleRecordDeletion(recordType,recordName)
60  // ConfigurationAPI.deleteSubsetRecords() handler
61  // ConfigurationAPI.saveModifiedTables() handler
62  // localCheckParentChildren()
63 
64  // share scope functions (between switch and next/prev handlers)
65  // localHandleIntermediateLevel()
66  // localCreateIntermediateLevelRecord(name)
67  // localSetupIntermediateLevelRecord(name)
68  // localGetExistingIntermediateTargetGroupID(supervisorName)
69 
70  // localCreateApp(name)
71  // localSetupApp(name)
72  // localCreateAppConfig(name)
73  // localSetupAppConfig(name)
74 
75  // localGetExistingSupervisorTargetGroupID(supervisorName)
76  // localCreateRecord(table)
77  // localGetHelperValuesForRecord()
78 
79  // localNextButtonHandler() switch
80  // localScopeSetRecordFieldsDoIt() _STEP_SET_RECORD_FIELDS
81  // localHandleSetupContext() _STEP_SET_CONTEXT_HOST
82  // localGetAppInfo()
83  // scopeWhichRecordTypeNext() _STEP_WHICH_RECORD_TYPE
84 
85  // localPrevButtonHandler() switch
86 
87  //htmlOpen(tag,attObj,innerHTML,closeTag)
88  //htmlClearDiv()
89 
90  //getApp()
91  //getAppClass()
92  //getAppModule()
93  //getAppConfiguration()
94  //getRecordConfiguration()
95  //getRecordGroupIDField()
96  //getRecordFilter()
97 
98  //getIntermediateTable()
99  //getIntermediateTypeName()
100  //getParentTable(generationsBack)
101  //getParentType(generationsBack)
102  //getParentLinkField(generationsBack)
103  //getParentFilter(generationsBack)
104 
105 
108 
109 
110 /*
111 <script type="text/JavaScript" src="/WebPath/js/Globals.js"></script>
112 <script type="text/JavaScript" src="/WebPath/js/Debug.js"></script>
113 <script type="text/JavaScript" src="/WebPath/js/DesktopContent.js"></script>
114 <script type="text/JavaScript" src="/WebPath/js/js_lib/SimpleContextMenu.js"></script>
115 <script type="text/JavaScript" src="/WebPath/js/js_lib/ConfigurationAPI.js"></script>
116 */
117 
118 var RecordWiz = RecordWiz || {}; //define RecordWiz namespace
119 
120 if (typeof Debug == 'undefined')
121  console.log('ERROR: Debug is undefined! Must include Debug.js before RecordWiz_ConfigurationGUI.js');
122 else if (typeof Globals == 'undefined')
123  console.log('ERROR: Globals is undefined! Must include Globals.js before RecordWiz_ConfigurationGUI.js');
124 else
125  RecordWiz.wiz; //this is THE RecordWiz variable
126 
127 
130 //call createWiz to create instance of a RecordWiz
133 RecordWiz.createWiz = function(doneHandler, recordsAliasFastForward) {
134 
135 
136  var _TABLE_BOOL_TYPE_TRUE_COLOR = "rgb(201, 255, 201)";
137  var _TABLE_BOOL_TYPE_FALSE_COLOR = "rgb(255, 178, 178)";
138 
139 
140 
141  //global vars for params
142  var _recordAlias;
143  var _doneHandler = doneHandler;
144  var _aRecordWasModified = false;
145 
146  var _RECORD_TYPE_FE = "Front-end";
147  var _RECORD_TYPE_PROCESSOR = "Processor";
148  var _RECORD_TYPE_CONSUMER = "Consumer";
149  var _RECORD_TYPE_PRODUCER = "Producer";
150  var _validRecordTypes = [_RECORD_TYPE_FE,_RECORD_TYPE_PROCESSOR];
151 
152 
154  function localParameterCheck()
155  {
156  //check for valid record alias
157  var i=_validRecordTypes.length-1;
158  for(i;i>=0;--i)
159  if(_validRecordTypes[i] == _recordAlias) break;
160  if(i<0) //alias error!!
161  {
162  var str = "Invalid Record Alias '" + _recordAlias + "' was specified. " +
163  "The only valid record aliases are as follows: ";
164 
165  for(i=_validRecordTypes.length-1;i>=0;--i)
166  str += "<br>\t" + _validRecordTypes[i];
167  Debug.log(str,Debug.HIGH_PRIORITY);
168  return false;
169  }
170  return true;
171  } //end localParameterCheck()
172 
173  //global vars for creation
174  var _subsetUIDs; //array of UIDs already defined at base path
175  var _systemGroups; //object of aliases and groups w/active groups
176  var _paramObjMap; //allows for lookup of parameter objects based on stepIndex
177  var _furthestStep = -1;
178  var _lastNextStep = -1;
179  var _intermediateLevel = -1;
180 
181  //global vars for saving tables
182  var _modifiedTables;
183 
184 
185  var _STEP_OUT_OF_SEQUENCE = 1000; //steps greater or equal are ignored in _furthestStep
186 
187  var
188  _STEP_PROC_WHICH_BUFFER = 200,
189  _STEP_SET_RECORD_FIELDS = 104,
190  _STEP_WHICH_APP = 103,
191  _STEP_SET_CONTEXT_HOST = 102,
192  _STEP_WHICH_CONTEXT = 101,
193  _STEP_CHANGE_GROUP = 1000,
194  _STEP_GET_RECORD_NAME = 100,
195  _STEP_WHICH_RECORD_TYPE = 20;
196 
197 
198  var _START_STEP_INDEX = _STEP_GET_RECORD_NAME;
199 
200  var _XDAQ_BASE_PATH = "XDAQContextTable";
201  var _XDAQAPP_BASE_PATH = "XDAQApplicationTable";
202 
203  var _DEFAULT_WIZ_COMMENT= "Generated by Record Creation Wiz";
204 
207  // end variable declaration
208  Debug.log("RecordWiz.wiz constructed");
209  RecordWiz.wiz = this;
210 
211  var windowTooltip = "Welcome to the Record Wizard GUI. Here you can create new records for " +
212  "your <i>otsdaq</i> system. \n\n" +
213  "The Record Wizard is presented as a step-by-step process that will walk you through creating the skeleton for your new record.\n\n" +
214 
215  "Briefly, here is a description of the steps: " +
216  "\n\t- 'What type of record do you want to add?'" +
217  "\n\t- 'Do you want to add it to an existing context or create a new one?'";
218  if(!recordsAliasFastForward || recordsAliasFastForward == "")
219  {
220  DesktopContent.tooltip("Record Wizard Introduction",
221  windowTooltip
222  );
223  DesktopContent.setWindowTooltip(windowTooltip);
224 
225  showPrompt(_STEP_WHICH_RECORD_TYPE);
226  }
227  else
228  {
229  _recordAlias = recordsAliasFastForward;
230  if(!localParameterCheck())
231  {
232  Debug.log("Invalid parameters to the Record Creation Wizard!", Debug.HIGH_PRIORITY);
233  return;
234  }
235 
236 
237  DesktopContent.tooltip(_recordAlias + " Wizard Introduction",
238  "Welcome to the " + _recordAlias + " Wizard GUI. Here you can create new records for " +
239  "your <i>otsdaq</i> system. \n\n" +
240  "The " + _recordAlias + " Wizard is presented as a step-by-step process that will walk you through creating the skeleton for your new " +
241  _recordAlias + ".\n\n" +
242  "Briefly, here is a description of the steps: " +
243  "\n\t- 'Do you want to add your " + _recordAlias + " to an existing context or create a new one?'"
244  );
245 
246  initRecordWizard();
247  }
248 
249  return;
250 
253  // start funtion declaration
254 
255 
256  //=====================================================================================
257  //xdaqContextTooltip ~~
258  function xdaqContextTooltip()
259  {
260  DesktopContent.tooltip("XDAQ Contexts",
261  "The lowest level parent for your record, in the <i>otsdaq</i> configuration tree, is a XDAQ Context. " +
262  "What is a XDAQ Context? Why do I need a XDAQ Context? Do I want a new one for my " + _recordAlias + " or not?" +
263  "<br><br>" +
264  "XDAQ Contexts are the fundamental executable program building blocks of <i>otsdaq</i>. " +
265  "A XDAQ Context runs a group of XDAQ Applications inside of it. If one of those XDAQ Applications crashes, " +
266  "then only the parent XDAQ Context will crash. This is one reason organizing your <i>otsdaq</i> entities into separate XDAQ Contexts makes sense." +
267  "<br><br>" +
268  "Two other useful features of XDAQ Contexts are that they can easily be turned on and off (enabled and disabled through the configuration editors), and " +
269  "they can easily be distributed to other nodes (computers) in your DAQ system when your system scales up."
270  );
271  } //end xdaqContextTooltip()
272  //=====================================================================================
273  //xdaqApplicationTooltip ~~
274  function xdaqApplicationTooltip()
275  {
276  DesktopContent.tooltip("XDAQ Applications",
277  "The second level parent for your record, in the <i>otsdaq</i> configuration tree, is a XDAQ Application. " +
278  "What is a XDAQ Application? Why do I need a XDAQ Application? Do I want a new one for my " + _recordAlias + " or not?" +
279  "<br><br>" +
280  "XDAQ Applications are server processes that can be controlled by <i>otsdaq</i> through network messages. " +
281  "Ther can be one or many XDAQ Applciation in a XDAQ Context. If one of those XDAQ Applications crashes, " +
282  "then all of the other XDAQ Applications in the parent XDAQ Context will crash. This is one reason organizing your <i>otsdaq</i> entities into separate XDAQ Contexts makes sense." +
283  "<br><br>" +
284  "Two other useful features of XDAQ Applications are that they can respond to web requests and state machine transitions."
285  );
286  } //end xdaqApplicationTooltip()
287 
288  //=====================================================================================
289  //initRecordWizard ~~
290  // get active groups and list of all groups
291  // get list of existing records at base path
292  function initRecordWizard()
293  {
294  _subsetUIDs = []; //reset
295  _modifiedTables = undefined; //reset
296  _furthestStep = -1; // reset
297  _paramObjMap = {}; //reset
298  _systemGroups = {}; //reset
299 
300  { //remove all existing dialogs
301 
302  var el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
303  while(el)
304  {
305  el.parentNode.removeChild(el); //close popup
306  el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
307  }
308  } //end remove all existing dialogs
309 
310 
311  // get groups and aliases
312  ConfigurationAPI.getAliasesAndGroups(
313  function(retObj)
314  {
315  _systemGroups = retObj;
316  console.log("_systemGroups",_systemGroups);
317  console.log("ConfigurationAPI._activeGroups",ConfigurationAPI._activeGroups);
318 
319 
320  // get existing records
321  ConfigurationAPI.getSubsetRecords(
322  getRecordConfiguration(),
323  getRecordFilter() /*_recordPreFilterList*/,
324  function(records)
325  {
326  _subsetUIDs = records;
327  Debug.log("records found = " + records.length);
328  console.log(records);
329 
330  showPrompt(_STEP_GET_RECORD_NAME);
331 
332  },_modifiedTables); //end getSubsetRecords
333 
334  }); //end getAliasesAndGroups
335 
336  } //end initRecordWizard()
337 
338  //=====================================================================================
339  //showPrompt ~~
340  // _paramObjMap allows for lookup parameters based on stepIndex
341  // paramObj is the new object for stepIndex
342  function showPrompt(stepIndex,paramObj)
343  {
344  //default to step 0
345  if(!stepIndex) stepIndex = 0;
346 
347  if(stepIndex > _furthestStep &&
348  _furthestStep < _STEP_OUT_OF_SEQUENCE)
349  _furthestStep = stepIndex;
350 
351  Debug.log("showPrompt " + stepIndex);
352  Debug.log("_furthestStep " + _furthestStep);
353 
354  //default to empty object
355  if(!_paramObjMap) _paramObjMap = {};
356 
357 
358  if(paramObj) //store to object map
359  _paramObjMap[stepIndex] = paramObj;
360  else if(_paramObjMap[stepIndex]) //load from object map
361  paramObj = _paramObjMap[stepIndex];
362  else
363  {
364  //default to empty object
365  _paramObjMap[stepIndex] = {};
366  paramObj = _paramObjMap[stepIndex];
367  }
368 
369  console.log("_paramObjMap",_paramObjMap);
370  console.log("paramObj",paramObj);
371 
372  var el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
373 
374  //remove all existing dialogs
375  while(el)
376  {
377  el.parentNode.removeChild(el); //close popup
378  el = document.getElementById(ConfigurationAPI._POP_UP_DIALOG_ID);
379  }
380  //note el is usable in code
381 
382  //set position and size
383  var w = 480;
384  var h = 350;//250;
385 
386  var str = "";
387  var stepString = "stepIndex-" + stepIndex + "-";
388 
389  var showPrevButton = true;
390  var showNextButton = true;
391  var prevStepIndex = stepIndex-1; //default back button to last next step //stepIndex-1;
392  if(prevStepIndex > _lastNextStep)
393  prevStepIndex = _lastNextStep;
394  _lastNextStep = stepIndex;
395 
396  var nextStepIndex = stepIndex+1;
397  var prevButtonText = "Go Back";
398  var nextButtonText = "Next Step";
399 
400  var recordName = "";
401  try //try to get record name since used often
402  {
403  recordName = _paramObjMap[_STEP_GET_RECORD_NAME]["recordName"];
404  } catch(e){;}
405 
408  // add content
409  localAddContent();
410  function localAddContent()
411  {
412  switch(stepIndex)
413  {
414  case _STEP_PROC_WHICH_BUFFER:
415  //xdaqApplicationTooltip();
416  h = 370;
417 
418  showNextButton = false; //replace it
419 
420  //take parameter recordName
421  Debug.log("_STEP_PROC_WHICH_BUFFER " + recordName);
422 
423  // " add to existing buffer or a new one?"
424  str += "<br>";
425  str += "Do you want to add the " + _recordAlias + " named '" +
426  recordName + "' to a new Data Manager Buffer " +
427  "or an existing one in the Data Manager '" +
428  _paramObjMap[_STEP_WHICH_APP]["appName"] + "'?";
429 
430  str += "<center>";
431  str += "<table style='margin-bottom: 10px;'>";
432 
434  { // new app input
435  str += "<tr><td><b>New Buffer:</b></td><td>";
436 
437  str += htmlOpen("input",
438  {
439  "type" : "text",
440  "id" : stepString + "bufferName",
441  "value": (paramObj["bufferName"]?paramObj["bufferName"]:
442  ConfigurationAPI.createNewRecordName("Buffer",
443  paramObj["allBuffers"])),
444  }, "" /*innerHTML*/, true /*closeTag*/);
445 
446  str += htmlOpen("input",
447  {
448  "id": stepString + "addToNew",
449  "type": "button",
450  "value": "Add to New",
451  "title": "Create a new Buffer and add the new " +
452  _recordAlias + " to it."
453  },
454  0 /*html*/, true /*closeTag*/);
455  str += "</td></tr>";
456  } //end new app input
457 
458  if(paramObj["buffers"].length)
459  {
460  str += "<tr><td><b>Existing Buffers:</b></td><td>";
461  { //start apps
462  str += htmlOpen("select",
463  {
464  "id" : stepString + "buffers",
465  });
466 
467  for(var i=0;i<paramObj["buffers"].length;++i)
468  {
469  str += htmlOpen("option",
470  {
471  },
472  paramObj["buffers"][i] /*innerHTML*/, true /*closeTag*/);
473  }
474  str += "</select>"; //end dropdown
475  str += htmlOpen("input",
476  {
477  "id": stepString + "addToExisting",
478  "type": "button",
479  "value": "Add to Existing",
480  "title": "Add new " + _recordAlias +
481  " to the chosen existing Buffer."
482  },
483  0 /*html*/, true /*closeTag*/);
484  } //end buffers
485  str += "</td></tr>";
486  } //end existing buffers
487 
488  str += "</table>";
489 
490 
491  if(paramObj["allBuffers"].length)
492  {
494  // existing addresses
495  str += htmlClearDiv();
496  str += "Here is a dropdown of all existing Buffers " +
497  " to help you in creating standardized names (Note: shown above are " +
498  "only the Buffers in the chosen Data Manager '" +
499  _paramObjMap[_STEP_WHICH_APP]["appName"] +
500  "':";
501 
502  str += htmlClearDiv();
503  str += htmlOpen("select",
504  {
505  "id" : stepString + "allBuffers",
506  "style" : "margin-bottom: 16px;"
507  });
508 
509  for(var i=0;i<paramObj["allBuffers"].length;++i)
510  {
511  str += htmlOpen("option",
512  {
513  },
514  paramObj["allBuffers"][i] /*innerHTML*/, true /*closeTag*/);
515  }
516  str += "</select>"; //end all buffers dropdown
517  } //end existing all buffers
518 
519 
520 
521  str += "</center>";
522  break; // _STEP_PROC_WHICH_BUFFER
523 
524  case _STEP_SET_RECORD_FIELDS:
525 
526  Debug.log("_STEP_SET_RECORD_FIELDS ");
527 
528  nextButtonText = "Done!";
529 
530  str += "<br>";
531  str += "Please edit the fields for your record and then click 'Done!' to save " +
532  " your new " + _recordAlias + " named '" + recordName + "':";
533 
534  str += htmlClearDiv();
535  str += htmlOpen("div",
536  {
537  "id" : stepString + "fields",
538  "style" : "margin: 20px;",
539 
540  }, "" /*innerHTML*/, true /*closeTag*/);
541  str += htmlClearDiv();
542 
543  break; //end _STEP_SET_RECORD_FIELDS
544 
545  case _STEP_WHICH_APP:
546 
547  h = 370;
548 
549  xdaqApplicationTooltip();
550 
551  showNextButton = false; //replace it
552 
553  //take parameter recordName
554  Debug.log("_STEP_WHICH_APP " + recordName);
555 
556  // " add to existing XDAQ App or a new one?"
557  str += "<br>";
558  str += "Do you want to add the " + _recordAlias + " named '" +
559  recordName + "' to a new XDAQ " + getAppClass() +
560  " Application or an existing one in the context '" +
561  _paramObjMap[_STEP_WHICH_CONTEXT]["contextName"] + "'?";
562 
563  str += "<center>";
564  str += "<table style='margin-bottom: 10px;'>";
565 
567  { // new app input
568  str += "<tr><td><b>New XDAQ App:</b></td><td>";
569 
570  str += htmlOpen("input",
571  {
572  "type" : "text",
573  "id" : stepString + "appName",
574  "value": (paramObj["appName"]?paramObj["appName"]:
575  ConfigurationAPI.createNewRecordName(getApp(),paramObj["allApps"])),
576  }, "" /*innerHTML*/, true /*closeTag*/);
577 
578  str += htmlOpen("input",
579  {
580  "id": stepString + "addToNew",
581  "type": "button",
582  "value": "Add to New",
583  "title": "Create a new XDAQ Application and add the new " + _recordAlias + " to it."
584  },
585  0 /*html*/, true /*closeTag*/);
586  str += "</td></tr>";
587  } //end new app input
588 
589  if(paramObj["apps"].length)
590  {
591  str += "<tr><td><b>Existing Apps:</b></td><td>";
592  { //start apps
593  str += htmlOpen("select",
594  {
595  "id" : stepString + "apps",
596  });
597 
598  for(var i=0;i<paramObj["apps"].length;++i)
599  {
600  str += htmlOpen("option",
601  {
602  },
603  paramObj["apps"][i] /*innerHTML*/, true /*closeTag*/);
604  }
605  str += "</select>"; //end dropdown
606  str += htmlOpen("input",
607  {
608  "id": stepString + "addToExisting",
609  "type": "button",
610  "value": "Add to Existing",
611  "title": "Add new " + _recordAlias + " to the chosen existing XDAQ Application."
612  },
613  0 /*html*/, true /*closeTag*/);
614  } //end apps
615  str += "</td></tr>";
616  } //end existing apps
617 
618  str += "</table>";
619 
620 
621  if(paramObj["allApps"].length)
622  {
624  // existing addresses
625  str += htmlClearDiv();
626  str += "Here is a dropdown of all existing XDAQ Applications " +
627  " to help you in creating standardized names (Note: shown above are " +
628  "only apps with class " + getAppClass() + " and in the chosen context '" +
629  _paramObjMap[_STEP_WHICH_CONTEXT]["contextName"] +
630  "'):";
631 
632  str += htmlClearDiv();
633  str += htmlOpen("select",
634  {
635  "id" : stepString + "allApps",
636  "style" : "margin-bottom: 16px;"
637  });
638 
639  for(var i=0;i<paramObj["allApps"].length;++i)
640  {
641  str += htmlOpen("option",
642  {
643  },
644  paramObj["allApps"][i] /*innerHTML*/, true /*closeTag*/);
645  }
646  str += "</select>"; //end all apps dropdown
647  } //end existing all apps
648 
649 
650 
651  str += "</center>";
652  break; // _STEP_WHICH_APP
653 
654  case _STEP_SET_CONTEXT_HOST:
655 
656  if(paramObj["isNewContext"])
657  str += "Please enter the Host Address and Port for the " +
658  "new Context named '" +
659  _paramObjMap[_STEP_WHICH_CONTEXT]["contextName"] + "':";
660  else
661  str += "Please verify the Host Address and Port for the " +
662  "existing Context named '" +
663  _paramObjMap[_STEP_WHICH_CONTEXT]["contextName"] + "':";
664 
665  str += "<center>";
666  str += "<table style=''>";
667 
669  { // address input
670  str += "<tr><td><b>Address:</b></td><td>";
671 
672  str += htmlOpen("input",
673  {
674  "type" : "text",
675  "id" : stepString + "address",
676  "value" : (paramObj["address"]?paramObj["address"]:""),
677  }, "" /*innerHTML*/, true /*closeTag*/);
678 
679  str += "</td></tr>";
680  } //end new context input
682  { // port input
683  str += "<tr><td><b>Port:</b></td><td>";
684 
685  str += htmlOpen("input",
686  {
687  "type" : "text",
688  "id" : stepString + "port",
689  "value" : (paramObj["port"]?paramObj["port"]:""),
690  }, "" /*innerHTML*/, true /*closeTag*/);
691 
692  str += "</td></tr>";
693  } //end new context input
694 
695  str += "</table>";
696  str += "</center>";
697 
699  // existing addresses
700  str += htmlClearDiv();
701  str += "Here is a dropdown of existing Host Addresses " +
702  " to help you in creating standardized addresses:";
703  str += htmlClearDiv();
704  str += htmlOpen("select",
705  {
706  "id" : stepString + "addresses",
707  "style" : "margin-bottom: 16px;"
708  });
709 
710 
711  for(var i=0;i<paramObj["hostAddresses"].length;++i)
712  {
713  str += htmlOpen("option",
714  {
715  },paramObj["hostAddresses"][i] /*innerHTML*/, true /*closeTag*/);
716  }
717  str += "</select>"; //end existing records dropdown
718 
720  // existing ports
721  str += htmlClearDiv();
722  str += "Here is a dropdown of existing Host Ports " +
723  " to help you in creating standardized ports:";
724  str += htmlClearDiv();
725  str += htmlOpen("select",
726  {
727  "id" : stepString + "ports",
728  "style" : ""
729  });
730 
731 
732  for(var i=0;i<paramObj["hostPorts"].length;++i)
733  {
734  str += htmlOpen("option",
735  {
736  },paramObj["hostPorts"][i] /*innerHTML*/, true /*closeTag*/);
737  }
738  str += "</select>"; //end existing records dropdown
739 
740  break; //end _STEP_SET_CONTEXT_HOST
741 
742  case _STEP_WHICH_CONTEXT:
743 
744  xdaqContextTooltip();
745 
746  showNextButton = false; //replace it
747 
748  //take parameter recordName
749  Debug.log("_STEP_WHICH_CONTEXT " + recordName);
750 
751  // " add to existing XDAQ Context or a new one?"
752  str += "<br>";
753  str += "Do you want to add the " + _recordAlias + " named '" +
754  recordName + "' to a new XDAQ Context or an existing one?";
755 
756 
757  str += "<center>";
758  str += "<table style='margin-bottom: 10px;'>";
759 
761  { // new context input
762  str += "<tr><td><b>New XDAQ Context:</b></td><td>";
763 
764  str += htmlOpen("input",
765  {
766  "type" : "text",
767  "id" : stepString + "contextName",
768  "value": (paramObj["contextName"]?paramObj["contextName"]:""),
769  }, "" /*innerHTML*/, true /*closeTag*/);
770 
771  str += htmlOpen("input",
772  {
773  "id": stepString + "addToNew",
774  "type": "button",
775  "value": "Add to New",
776  "title": "Create a new XDAQ Context and add the new " + _recordAlias + " to it."
777  },
778  0 /*html*/, true /*closeTag*/);
779  str += "</td></tr>";
780  } //end new context input
781 
782  if(paramObj["contexts"].length)
783  {
784  str += "<tr><td><b>Existing Contexts:</b></td><td>";
785  { //start contexts
786  str += htmlOpen("select",
787  {
788  "id" : stepString + "contexts",
789  });
790 
791  for(var i=0;i<paramObj["contexts"].length;++i)
792  {
793  str += htmlOpen("option",
794  {
795  },
796  paramObj["contexts"][i] /*innerHTML*/, true /*closeTag*/);
797  }
798  str += "</select>"; //end aliases dropdown
799  str += htmlOpen("input",
800  {
801  "id": stepString + "addToExisting",
802  "type": "button",
803  "value": "Add to Existing",
804  "title": "Add new " + _recordAlias + " to the chosen existing XDAQ Context."
805  },
806  0 /*html*/, true /*closeTag*/);
807  } //end contexts
808  str += "</td></tr>";
809  } //end existing contexts
810 
811  str += "</table>";
812  str += "</center>";
813 
814  break; //end _STEP_WHICH_CONTEXT
815 
816  case _STEP_CHANGE_GROUP:
817  //take paramter groupType
818 
819  showNextButton = false; //replace it
820  nextStepIndex = _STEP_GET_RECORD_NAME;
821  prevStepIndex = _STEP_GET_RECORD_NAME;
822 
823  str += "Choose a '" + paramObj["groupType"] +
824  "' group to activate (either a System Alias or specific group):";
825 
826  str += htmlClearDiv();
827 
828  str += "<center>";
829  str += "<table style='margin-bottom: 10px;'>";
830  if(_systemGroups.aliases[paramObj["groupType"]].length)
831  {
832  str += "<tr><td><b>System Aliases:</b></td><td>";
833  { //start aliases
834  str += htmlOpen("select",
835  {
836  "id" : stepString + "aliases",
837  });
838 
839  for(var i=0;i<_systemGroups.aliases[paramObj["groupType"]].length;++i)
840  {
841  str += htmlOpen("option",
842  {
843  },
844  _systemGroups.aliases[paramObj["groupType"]]
845  [i].alias /*innerHTML*/, true /*closeTag*/);
846  }
847  str += "</select>"; //end aliases dropdown
848  str += htmlOpen("input",
849  {
850  "id": stepString + "activateAlias",
851  "type": "button",
852  "value": "Activate Alias",
853  "title": "Activate chosen System Alias and return to creating your new " + _recordAlias + "."
854  },
855  0 /*html*/, true /*closeTag*/);
856  } //end aliases
857  str += "</td></tr>";
858  }
859  else
860  str += "<tr><td colspan='2'>No system aliases of type Context found.</td></tr>";
861 
862  var groupNames = Object.keys(_systemGroups.groups[paramObj["groupType"]]);
863  if(groupNames.length)
864  {
865  str += "<tr><td><b>Group Names:</b></td><td>";
866  { //start groups
867  str += htmlOpen("select",
868  {
869  "id" : stepString + "groupNames",
870  });
871 
872  for(var i=0;i<groupNames.length;++i)
873  {
874  str += htmlOpen("option",
875  {
876  },
877  groupNames[i] /*innerHTML*/, true /*closeTag*/);
878  }
879  str += "</select>"; //end group name dropdown
880 
881  } //end groups
882  str += "</td></tr>";
883  }
884  else
885  str += "<tr><td colspan='2'>No groups of type Context found.</td></tr>";
886 
887  if(groupNames.length)
888  {
889  str += "<tr><td><b>Group Keys:</b></td><td>";
890  { //start keys
891  str += htmlOpen("select",
892  {
893  "id" : stepString + "groupKeys",
894  });
895 
896  for(var i=0;i<_systemGroups.groups[paramObj["groupType"]]
897  [groupNames[0]].keys.length;++i)
898  {
899  str += htmlOpen("option",
900  {
901  },
902  _systemGroups.groups[paramObj["groupType"]]
903  [groupNames[0]].keys[i] /*innerHTML*/, true /*closeTag*/);
904  }
905  str += "</select>"; //end group keys dropdown
906  str += htmlOpen("input",
907  {
908  "id": stepString + "activateGroup",
909  "type": "button",
910  "value": "Activate Group",
911  "title": "Activate chosen Group and Key pair and return to creating your new " + _recordAlias + "."
912  },
913  0 /*html*/, true /*closeTag*/);
914  } //end keys
915  str += "</td></tr>";
916  }
917  str += "</table>";
918  str += "</center>";
919 
920  break; //end _STEP_CHANGE_GROUP
921 
922  case _STEP_GET_RECORD_NAME:
923 
924 
925  prevStepIndex = _STEP_WHICH_RECORD_TYPE;
926 
928  // header
929  str += htmlOpen("div",
930  {
931  "style" : "font-weight:bold; margin: 6px 0 20px 0;"
932  },
933  (_aRecordWasModified?
934  ("Would you like to create another " + _recordAlias + "?"):
935  ("Welcome to the " + _recordAlias + " creation Wizard!")) /*innerHTML*/,
936  true /*closeTag*/);
937  str += htmlClearDiv();
938 
940  // prompt
941  str += "Enter the unique record name for your " + _recordAlias + ": ";
942  str += htmlClearDiv();
943  str += htmlOpen("input",
944  {
945  "type" : "text",
946  "id" : stepString + "recordName",
947  "style" : "margin-bottom: 16px;",
948  "value" : (paramObj["recordName"]?paramObj["recordName"]:""),
949  }, "" /*innerHTML*/, true /*closeTag*/);
950 
951 
952 
954  // existing records
955  str += htmlClearDiv();
956  str += "Here is a dropdown of existing " + _recordAlias +
957  " records to help you in creating standardized record names:";
958  str += htmlClearDiv();
959 
960 
961  str += htmlOpen("select",
962  {
963  "id" : stepString + "records",
964  "style" : "margin-bottom: 16px;",
965  });
966 
967 
968  for(var i=0;i<_subsetUIDs.length;++i)
969  {
970  str += htmlOpen("option",
971  {
972  },_subsetUIDs[i] /*innerHTML*/, true /*closeTag*/);
973  }
974  str += "</select>"; //end existing records dropdown
975 
976 
977  str += htmlOpen("div",
978  {
979  "id" : stepString + "deleteRecordIcon",
980  "class": ConfigurationAPI._POP_UP_DIALOG_ID + "-deleteIcon",
981  "style" : "float: right; margin: 6px 112px -16px -200px; display: block;",
982 
983  }, 0 /*innerHTML*/, true /*closeTag*/);
984 
985 
986  //preload hover images
987  str += htmlOpen("div",
988  {
989  "id" : ConfigurationAPI._POP_UP_DIALOG_ID +
990  "-preloadImage-editIconHover",
991  "class": ConfigurationAPI._POP_UP_DIALOG_ID + "-preloadImage",
992  }, 0 /*innerHTML*/, true /*closeTag*/);
993  str += htmlOpen("div",
994  {
995  "id" : ConfigurationAPI._POP_UP_DIALOG_ID +
996  "-preloadImage-treeEditTrashIconHover",
997  "class": ConfigurationAPI._POP_UP_DIALOG_ID + "-preloadImage",
998  }, 0 /*innerHTML*/, true /*closeTag*/);
999 
1000 
1002  // active groups
1003  str += htmlClearDiv();
1004  str += "Note you are currently editing these active groups:";
1005  str += "<center>";
1006  str += "<table style='margin-bottom: 10px;'>";
1007  str += "<tr><td><b>Active Context:</b></td><td>";
1008  str += ConfigurationAPI._activeGroups.Context.groupName + " (" + ConfigurationAPI._activeGroups.Context.groupKey + ")";
1009  //_systemGroups.activeGroups.Context.groupName + " (" + _systemGroups.activeGroups.Context.groupKey + ")";
1010 
1011  str += htmlOpen("div",
1012  {
1013  "id": stepString + "editContext",
1014  "class": ConfigurationAPI._POP_UP_DIALOG_ID + "-editIcon",
1015  "style": "float:right; display:block; margin: -3px 0 0 10px;",
1016  "title": "Click to activate a different Context group.",
1017 
1018  }, 0 /*innerHTML*/, true /*closeTag*/);
1019 
1020  str += "</td></tr>";
1021  str += "<tr><td><b>Active Configuration:</b></td><td>";
1022  str += _systemGroups.activeGroups.Configuration.groupName + " (" + _systemGroups.activeGroups.Configuration.groupKey + ")";
1023 
1024  str += htmlOpen("div",
1025  {
1026  "id": stepString + "editConfig",
1027  "class": ConfigurationAPI._POP_UP_DIALOG_ID + "-editIcon",
1028  "style": "float:right; display:block; margin: -3px 0 0 10px;",
1029  "title": "Click to activate a different Configuration group.",
1030  }, 0 /*innerHTML*/, true /*closeTag*/);
1031 
1032  str += "</td></tr>";
1033  str += "</table>";
1034  str += "</center>";
1035 
1036 
1037  break; // end _STEP_GET_RECORD_NAME
1038  case _STEP_WHICH_RECORD_TYPE:
1039 
1040  nextStepIndex = _STEP_GET_RECORD_NAME;
1041  prevButtonText = "Close Wizard";
1042 
1044  // header
1045  str += htmlOpen("div",
1046  {
1047  "style" : "font-weight:bold; margin: 6px 0 20px 0;"
1048  },
1049  "Welcome to the record creation Wizard!" /*innerHTML*/,
1050  true /*closeTag*/);
1051  str += htmlClearDiv();
1052 
1054  // existing record types
1055  str += htmlClearDiv();
1056  str += "Below is a dropdown of record types that this Wizard can help you create. " +
1057  " Choose one and proceed through the steps to create your new record:";
1058  str += htmlClearDiv();
1059  str += htmlOpen("select",
1060  {
1061  "id" : stepString + "recordTypes",
1062  "style" : "margin-bottom: 16px;"
1063  });
1064 
1065  for(var i=0;i<_validRecordTypes.length;++i)
1066  {
1067  str += htmlOpen("option",
1068  {
1069  },_validRecordTypes[i] /*innerHTML*/, true /*closeTag*/);
1070  }
1071  str += "</select>"; //end existing records dropdown
1072 
1073  break; //end _STEP_WHICH_RECORD_TYPE
1074  default:
1075  Debug.log("Should never happen - bad stepIndex (" + stepIndex +
1076  ")!",Debug.HIGH_PRIORITY);
1077  return;
1078  }
1079 
1080  //add go back button
1081  //add proceed to next step button
1082  var ctrlStr = "";
1083 
1084  if(stepIndex && showPrevButton)
1085  ctrlStr += htmlOpen("input",
1086  {
1087  "class": "prevButton " + stepString + "prevButton",
1088  "type": "button",
1089  "value": prevButtonText,
1090  "title": "Return to the previous step in the " + _recordAlias + " creation wizard."
1091  },
1092  0 /*html*/, true /*closeTag*/);
1093  if(showNextButton)
1094  ctrlStr += htmlOpen("input",
1095  {
1096  "class": "nextButton " + stepString + "nextButton",
1097  "type": "button",
1098  "value": nextButtonText,
1099  "title": "Proceed to the next step in the " + _recordAlias + " creation wizard."
1100  },
1101  0 /*html*/, true /*closeTag*/);
1102 
1103 
1104  //make popup element
1105  el = document.createElement("div");
1106  el.setAttribute("id", ConfigurationAPI._POP_UP_DIALOG_ID);
1107 
1108  ConfigurationAPI.setPopUpPosition(el,w /*w*/,h /*h*/);
1109 
1110  el.innerHTML = ctrlStr + htmlClearDiv() + str + htmlClearDiv() + ctrlStr;
1111  document.body.appendChild(el);
1112  } //end localAddContent()
1113 
1114 
1117  // add handlers
1118  localAddHandlers();
1119  function localAddHandlers()
1120  {
1121  var newParamObj = {};
1122 
1124  //add handlers specific to the step
1125  switch(stepIndex)
1126  {
1127  case _STEP_SET_RECORD_FIELDS:
1128 
1129  { //start scope of _STEP_SET_RECORD_FIELDS localAddHandlers
1130  //add the fields content in after parent element exists
1131  scopeForSetRecordFieldsContent();
1133  function scopeForSetRecordFieldsContent()
1134  {
1135  var recordFields = paramObj["fields"];
1136 
1137  var fieldContainerEl = document.getElementById(stepString + "fields");
1138 
1139  //disable highlighting of fields
1140  ConfigurationAPI.editableField_SELECTED_COLOR_ = "transparent";
1141 
1142  //for each record,
1143  // make an element that is "editable" and "selectable" (_selectedFieldIndex)
1144  // - when clicked becomes selected element
1145  // - when pencil is clicked is edit mode
1146  // - tab should move from edit field to edit field
1147  for(var i=0;i<recordFields.length;++i)
1148  {
1149  el = document.createElement("div");
1150  el.setAttribute("id", "cfg_subset_field-" + i);
1151  el.setAttribute("style", "white-space:nowrap;" +
1152  "margin: 5px;");
1153  fieldContainerEl.appendChild(el); //add field to field container
1154 
1155  //fill field
1156  el.appendChild(ConfigurationAPI.createEditableFieldElement(
1157  recordFields[i],i));
1158 
1159  //add clear div
1160  el = document.createElement("div");
1161  el.setAttribute("id", "clearDiv");
1162  fieldContainerEl.appendChild(el);
1163  }
1164  } //end scopeForSetRecordFieldsContent
1165 
1166  } //end scope of _STEP_SET_RECORD_FIELDS localAddHandlers
1167  break;
1168 
1169  case _STEP_PROC_WHICH_BUFFER:
1170 
1171  { //start scope of _STEP_WHICH_APP localAddHandlers
1172 
1173  //create select change handler for existing records
1174  document.getElementById(stepString + "buffers").onclick = localAppSelectHandler;
1175  document.getElementById(stepString + "buffers").onchange = localAppSelectHandler;
1176  document.getElementById(stepString + "allBuffers").onclick = localAppSelectHandler;
1177  document.getElementById(stepString + "allBuffers").onchange = localAppSelectHandler;
1178 
1179  function localAppSelectHandler(event) {
1180  Debug.log("Selected " + this.value);
1181 
1182  //increment index
1183  document.getElementById(stepString + "bufferName").value =
1184  ConfigurationAPI.incrementName(this.value);
1185  }; //end onchange handler
1186 
1188  document.getElementById(stepString + "addToNew").onclick =
1189  function()
1190  {
1191  var name = document.getElementById(stepString + "bufferName").value.trim();
1192  Debug.log("addToNew " + name);
1193 
1194  //save name to param for this step
1195  paramObj["bufferName"] = name;
1196 
1197  localCreateIntermediateLevelRecord(name);
1198  }; //end addToNew button handler
1199 
1201  document.getElementById(stepString + "addToExisting").onclick =
1202  function()
1203  {
1204  var name = document.getElementById(stepString + "buffers").value.trim();
1205  Debug.log("addToExisting " + name);
1206 
1207  //save name to param for this step
1208  paramObj["bufferName"] = name;
1209 
1210  if(!_paramObjMap[_STEP_PROC_WHICH_BUFFER]["buffers"]) _paramObjMap[_STEP_PROC_WHICH_BUFFER]["buffers"] = []; //initialize if needed
1211  _paramObjMap[_STEP_PROC_WHICH_BUFFER]["isNew" + getIntermediateTypeName()] = false;
1212 
1213  //get buffer child group name: _paramObjMap[_STEP_PROC_WHICH_BUFFER]["recordGroupName"]
1214  localGetExistingIntermediateTargetGroupID(name);
1215 
1216  }; //end addToExisting handler
1217 
1218  } //end scope of _STEP_WHICH_APP localAddHandlers
1219  //NOTE: below this, functions were moved outside of swtich because they must be accessible to other steps and handlers
1220  // and, apparently {} create "function scope" inside a switch case
1221  // and, apparently switch statements create "function scope" too.
1222 
1223 
1224  break; //end _STEP_WHICH_APP
1225  case _STEP_WHICH_APP:
1226 
1227  { //start scope of _STEP_WHICH_APP localAddHandlers
1228 
1229  //create select change handler for existing records
1230  document.getElementById(stepString + "apps").onclick = localAppSelectHandler;
1231  document.getElementById(stepString + "apps").onchange = localAppSelectHandler;
1232  document.getElementById(stepString + "allApps").onclick = localAppSelectHandler;
1233  document.getElementById(stepString + "allApps").onchange = localAppSelectHandler;
1234 
1235  function localAppSelectHandler(event) {
1236  Debug.log("Selected " + this.value);
1237 
1238  //increment index
1239  document.getElementById(stepString + "appName").value =
1240  ConfigurationAPI.incrementName(this.value);
1241  }; //end onchange handler
1242 
1244  document.getElementById(stepString + "addToNew").onclick =
1245  function()
1246  {
1247  var name = document.getElementById(stepString + "appName").value.trim();
1248  Debug.log("addToNew " + name);
1249 
1250  //save name to param for this step
1251  paramObj["appName"] = name;
1252 
1253  localCreateApp(name);
1254  }; //end addToNew button handler
1255 
1257  document.getElementById(stepString + "addToExisting").onclick =
1258  function()
1259  {
1260  var name = document.getElementById(stepString + "apps").value.trim();
1261  Debug.log("addToExisting " + name);
1262 
1263  //save name to param for this step
1264  paramObj["appName"] = name;
1265 
1266  if(!_paramObjMap[_STEP_WHICH_APP]["apps"]) _paramObjMap[_STEP_WHICH_APP]["apps"] = []; //initialize if needed
1267  _paramObjMap[_STEP_WHICH_APP]["isNewApp"] = false;
1268 
1269  //check supervisor config
1270  localGetExistingSupervisorTargetGroupID(name);
1271 
1272  }; //end addToExisting handler
1273 
1274  } //end scope of _STEP_WHICH_APP localAddHandlers
1275  //NOTE: below this, functions were moved outside of switch because they must be accessible to other steps and handlers
1276  // and, apparently {} create "function scope" inside a switch case
1277  // and, apparently switch statements create "function scope" too.
1278 
1279 
1280  break; //end _STEP_WHICH_APP
1281  case _STEP_SET_CONTEXT_HOST:
1282 
1283  { //start scope of _STEP_SET_CONTEXT_HOST localAddHandlers
1284  //create select change handler for existing records
1285  document.getElementById(stepString + "addresses").onclick = localAddressSelectHandler;
1286  document.getElementById(stepString + "addresses").onchange = localAddressSelectHandler;
1287 
1288  function localAddressSelectHandler(event) {
1289  Debug.log("Selected " + this.value);
1290  document.getElementById(stepString + "address").value =
1291  this.value;
1292  }; //end onchange handler
1293 
1294  //create select change handler for existing records
1295  document.getElementById(stepString + "ports").onclick = localPortSelectHandler;
1296  document.getElementById(stepString + "ports").onchange = localPortSelectHandler;
1297 
1298  function localPortSelectHandler(event) {
1299  Debug.log("Selected " + this.value);
1300  document.getElementById(stepString + "port").value =
1301  this.value;
1302  }; //end onchange handler
1303 
1304  } //end scop of _STEP_SET_CONTEXT_HOST localAddHandlers
1305 
1306  break; //end _STEP_SET_CONTEXT_HOST
1307 
1308  case _STEP_WHICH_CONTEXT:
1309 
1310  { //start scope of _STEP_WHICH_CONTEXT localAddHandlers
1311  //create select change handler for existing records
1312  document.getElementById(stepString + "contexts").onclick = localContextSelectHandler;
1313  document.getElementById(stepString + "contexts").onchange = localContextSelectHandler;
1314 
1315  function localContextSelectHandler(event) {
1316  Debug.log("Selected " + this.value);
1317 
1318  //increment index
1319  document.getElementById(stepString + "contextName").value =
1320  ConfigurationAPI.incrementName(this.value);
1321  }; //end onchange handler
1322 
1324  document.getElementById(stepString + "addToNew").onclick =
1325  function()
1326  {
1327  var name = document.getElementById(stepString + "contextName").value.trim();
1328  Debug.log("addToNew " + name);
1329 
1330  //save name to param for this step
1331  paramObj["contextName"] = name;
1332 
1333 
1335  //create new record
1336  ConfigurationAPI.addSubsetRecords(
1337  _XDAQ_BASE_PATH,
1338  name,
1340  function(modifiedTables,err) //start addSubsetRecords handler
1341  {
1342  Debug.log("modifiedTables length " + modifiedTables.length);
1343  if(!modifiedTables.length)
1344  {
1345  //really an error
1346  Debug.log("There was an error while creating the XDAQ Context '" +
1347  name + ".' " + err,
1348  Debug.HIGH_PRIORITY);
1349  return;
1350  }
1351  _modifiedTables = modifiedTables;
1352 
1353  //at this point new context was created
1354  Debug.log("New context '" + name + "' was successfully created!");
1355 
1356  newParamObj["isNewContext"] = true;
1357 
1358  //add to context list for going back
1359  if(paramObj["contexts"].indexOf(name) == -1)
1360  paramObj["contexts"].push(name);
1361 
1362  localGetAllHostInfo();
1363 
1364  }, //end addSubsetRecords handler
1365  _modifiedTables,
1366  true /*silenceErrors*/); //end addSubsetRecords
1367 
1368  }; //end addToNew button handler
1369 
1371  document.getElementById(stepString + "addToExisting").onclick =
1372  function()
1373  {
1374  var name = document.getElementById(stepString + "contexts").value.trim();
1375  Debug.log("addToExisting " + name);
1376 
1377  //save name to param for this step
1378  paramObj["contextName"] = name;
1379 
1380  newParamObj["isNewContext"] = false;
1381 
1382  //get host info of
1383  ConfigurationAPI.getFieldValuesForRecords(
1384  _XDAQ_BASE_PATH,
1385  name,
1386  ["Address","Port","ApplicationGroupID"],
1387  function(objArr)
1388  {
1389  console.log(objArr);
1390  newParamObj["address"] = objArr[0].fieldValue;
1391  newParamObj["port"] = objArr[1].fieldValue;
1392  newParamObj["appGroupId"] = objArr[2].fieldValue;
1393 
1394  localGetAllHostInfo();
1395  }, //end getFieldValuesForRecords handler
1396  _modifiedTables); //end getFieldValuesForRecords
1397 
1398 
1399 
1400  }; //end addToExisting handler
1401 
1402 
1404  function localGetAllHostInfo()
1405  {
1406  Debug.log("localGetExistingHostInfo()");
1407  //get existing host addresses and ports
1408  ConfigurationAPI.getUniqueFieldValuesForRecords(
1409  _XDAQ_BASE_PATH,
1410  "*",
1411  ["Address","Port"],
1412  function(objArr)
1413  {
1414  console.log(objArr);
1415  newParamObj["hostAddresses"] = objArr[0].fieldUniqueValueArray;
1416  newParamObj["hostPorts"] = objArr[1].fieldUniqueValueArray;
1417 
1418  showPrompt(nextStepIndex,newParamObj);
1419  },
1420  _modifiedTables);
1421  } //end localGetAllHostInfo()
1422  } //end scope of _STEP_WHICH_CONTEXT localAddHandlers
1423 
1424  break; //end _STEP_WHICH_CONTEXT
1425 
1426  case _STEP_GET_RECORD_NAME:
1427 
1428  { //start scope of _STEP_GET_RECORD_NAME localAddHandlers
1429 
1430  //create select change handler for existing records
1431  document.getElementById(stepString + "records").onclick = localRecordsSelectHandler;
1432  document.getElementById(stepString + "records").onchange = localRecordsSelectHandler;
1433 
1435  function localRecordsSelectHandler(event) {
1436  Debug.log("Selected " + this.value);
1437 
1438  //increment index
1439  document.getElementById(stepString + "recordName").value =
1440  ConfigurationAPI.incrementName(this.value);
1441  }; //end onchange handler for existing records
1442 
1444  document.getElementById(stepString + "editConfig").onclick =
1445  function()
1446  {
1447  newParamObj["groupType"] = "Configuration";
1448  //save name to param for this step
1449  paramObj["recordName"] = document.getElementById(stepString + "recordName").value.trim();
1450  showPrompt(_STEP_CHANGE_GROUP,newParamObj);
1451  };
1453  document.getElementById(stepString + "editContext").onclick =
1454  function()
1455  {
1456  newParamObj["groupType"] = "Context";
1457  //save name to param for this step
1458  paramObj["recordName"] = document.getElementById(stepString + "recordName").value.trim();
1459  showPrompt(_STEP_CHANGE_GROUP,newParamObj);
1460  };
1462  document.getElementById(stepString + "deleteRecordIcon").onclick =
1463  function() //start deleteRecordIcon handler
1464  {
1465  var selectedIndex = document.getElementById(stepString + "records").selectedIndex;
1466  var recordName = _subsetUIDs[selectedIndex];
1467  Debug.log("deleteRecord " + selectedIndex + " : " + recordName);
1468  Debug.log("getRecordConfiguration " + getRecordConfiguration());
1469  Debug.log("getAppConfiguration " + getAppConfiguration());
1470  try
1471  {
1472  Debug.log("getIntermediateTable " + getIntermediateTable());
1473  Debug.log("getIntermediateTypeName " + getIntermediateTypeName());
1474  }catch(e){
1475  Debug.log("No intermediate table: " + e);
1476  }
1477 
1478  var generationsBack = 0; //initialize generations back for recursive prompt and remove
1479  var lastGenerationsBack, parentCheckParentIndex;
1480 
1481  //reset modified tables at start of deletion process
1482  // to not accidentally permanently save an incompletely created record
1483  _modifiedTables = undefined;
1484 
1485  localPromptAndHandleRecordDeletion(_recordAlias,recordName);
1487  function localPromptAndHandleRecordDeletion(recordType,recordName)
1488  {
1489  //Steps:
1490  // prompt user, are you sure?
1491  // reset modified tables
1492  // delete record
1493  // save modified tables
1494  // check parent level for any empty children groups
1495  // for each parent found with no children.. offer to delete them
1496  // when complete, re-initialize with initRecordWizard()
1497 
1498  var prompt;
1499 
1500  if(generationsBack == 0)
1501  prompt = "Are you sure you want to remove the " + recordType + " named '" +
1502  recordName + "' from the active configuration?";
1503  else
1504  prompt = "Alert! A parent node, " + generationsBack + " level(s) up in the " +
1505  "configuration tree from the " +
1506  "origial " + _recordAlias + " '" + _subsetUIDs[selectedIndex] + ",' was found to " +
1507  "have no children.<br><br>Do you want to remove the childless " + recordType + " named '" +
1508  recordName + "' from the active configuration?";
1509 
1510  DesktopContent.popUpVerification(
1511  prompt,
1512  function() //OK handler, delete the record handler
1513  {
1514 
1515  Debug.log("do deleteRecord " + recordType + " : " + recordName);
1516 
1517 
1519  //delete record
1520  ConfigurationAPI.deleteSubsetRecords(
1521  getParentTable(generationsBack),
1522  recordName,
1524  function(modifiedTables,err) //start deleteSubsetRecords handler
1525  {
1526  Debug.log("modifiedTables length " + modifiedTables.length);
1527  if(!modifiedTables.length)
1528  {
1529  //really an error
1530  Debug.log("There was an error while creating the XDAQ Context '" +
1531  recordName + ".' " + err,
1532  Debug.HIGH_PRIORITY);
1533  return;
1534  }
1535  _modifiedTables = modifiedTables;
1536  console.log(_modifiedTables);
1537 
1538  //at this point context was deleted in modified tables
1539  Debug.log("The " + recordType + " named '" +
1540  recordName + "' was successfully removed!",
1541  Debug.INFO_PRIORITY);
1542 
1543  parentCheckParentIndex = 0; //reset when record is deleted
1544 
1545 
1546  //now save, then check parent level for no children
1547 
1548  //proceed to save (quietly) tables, groups, aliases
1549  ConfigurationAPI.saveModifiedTables(_modifiedTables,
1550  function(savedTables, savedGroups, savedAliases)
1551  {
1552  if(!savedTables.length)
1553  {
1554  Debug.log("There was an error while saving the changes.",
1555  Debug.HIGH_PRIORITY);
1556  return;
1557  }
1558 
1559  Debug.log("The " +
1560  _recordAlias + " named '" + recordName + "' was successfully removed!",
1561  Debug.INFO_PRIORITY);
1562 
1563  _modifiedTables = undefined; //clear after save
1564 
1565  _aRecordWasModified = true;
1566 
1567  if(generationsBack == 0)
1568  {
1569  generationsBack = 1;
1570  localCheckParentChildren();
1571  }
1572  else
1573  localCheckParentChildren();
1574 
1575  }, //end saveModifiedTables handler
1576 
1577  0, //doNotIgnoreWarnings,
1578  0, //doNotSaveAffectedGroups,
1579  0, //doNotActivateAffectedGroups,
1580  0, //doNotSaveAliases,
1581  0, //doNotIgnoreGroupActivationWarnings,
1582  true //doNotKillPopUpEl
1583 
1584  ); //end saveModifiedTables handler
1585 
1586 
1587 
1588  }, //end deleteSubsetRecords handler
1589  _modifiedTables,
1590  true /*silenceErrors*/); //end deleteSubsetRecords
1591 
1592  }, //end OK, delete the record handler
1593  0 /* REPLACE val*/,
1594  "#efeaea" /*bgColor*/, 0 /*textColor*/,
1595  "#770000" /*borderColor*/,0 /*getUserInput*/,300 /*dialogWidth*/,
1596  function() // on Cancel, check parent children handler
1597  {
1598  Debug.log("User opted not to delete node.");
1599 
1600  //even if one parent is cancelled.. keep checking
1601  if(generationsBack)
1602  localCheckParentChildren();
1603  } //end Cancel, check parent children handler
1604  ); //end of DesktopContent.popUpVerification
1605 
1606 
1608  function localCheckParentChildren()
1609  {
1610  if(lastGenerationsBack != generationsBack)
1611  {
1612  //new generation, so reset starting parent to consider
1613  Debug.log("Starting new generation of checking...");
1614  parentCheckParentIndex = 0;
1615  lastGenerationsBack = generationsBack;
1616  }
1617  Debug.log("localCheckParentChildren generationsBack=" + generationsBack +
1618  " parentCheckParentIndex=" + parentCheckParentIndex);
1619 
1620  //Steps:
1621  // check parent level for any empty children groups
1622  // for each parent found with no children.. offer to delete them
1623  // when complete, re-initialize with initRecordWizard()
1624 
1625  //parent level table
1626  Debug.log("getAppConfiguration " + getAppConfiguration());
1627 
1628  var modifiedTablesListStr = "";
1629  for(var i=0;_modifiedTables && i<_modifiedTables.length;++i)
1630  {
1631  if(i) modifiedTablesListStr += ",";
1632  modifiedTablesListStr += _modifiedTables[i].tableName + "," +
1633  _modifiedTables[i].tableVersion;
1634  }
1635 
1636  // get tree looking for empty children
1637  DesktopContent.XMLHttpRequest("Request?RequestType=getTreeView" +
1638  "&tableGroup=" +
1639  "&tableGroupKey=-1" +
1640  "&hideStatusFalse=0" +
1641  "&depth=3", //make sure to see empty parents
1642  "startPath=/" + getParentTable(generationsBack) +
1643  "&filterList=" + getParentFilter(generationsBack) +
1644  "&modifiedTables=" + modifiedTablesListStr, //end post data
1645  function(req)
1646  {
1647 
1648  var tree = DesktopContent.getXMLNode(req,"tree");
1649  console.log(tree);
1650 
1651  //for each node record at parent level, check for empty children
1652  try
1653  {
1654  var i,j;
1655  var parentChildren;
1656  var parentName;
1657  for(i=parentCheckParentIndex;i<tree.children.length;++i)
1658  {
1659  ++parentCheckParentIndex; //next time ensure check next parent record first
1660 
1661  parentName = tree.children[i].getAttribute("value");
1662  Debug.log("Checking parent record " +
1663  parentCheckParentIndex + ":" +
1664  parentName);
1665 
1666  //find link field
1667  for(j=0;j<tree.children[i].children.length;++j)
1668  if(tree.children[i].children[j].getAttribute("value") ==
1669  getParentLinkField(generationsBack))
1670  {
1671  //found link
1672  parentChildren = DesktopContent.getXMLChildren(
1673  tree.children[i].children[j],
1674  "node");
1675  Debug.log("Num of children " + parentChildren.length);
1676 
1677  if(parentChildren.length == 0)
1678  {
1679  localPromptAndHandleRecordDeletion(
1680  getParentType(generationsBack),
1681  parentName)
1682  return; //do just one parent at a time, so async requests dont go crazy
1683  }
1684  break;
1685  }
1686  }
1687  //if here then no childless parent nodes found
1688  Debug.log("No childless parent nodes found");
1689 
1690  //try next generation back, recursively
1691  ++generationsBack;
1692  localCheckParentChildren();
1693  }
1694  catch(e)
1695  {
1696  //get here on error, or if completed tree traversal
1697 
1698  Debug.log("Giving up on childless parent node check. " +
1699  "Ignoring errors: " + e);
1700 
1701  initRecordWizard(); //start over to update list
1702  }
1703 
1704 
1705  }); //end getTreeView handler
1706 
1707  }
1708  } //end localPromptAndHandleRecordDeletion()
1709  }; //end deleteRecordIcon handler
1710  } //end scope of _STEP_GET_RECORD_NAME localAddHandlers
1711 
1712  break; //end _STEP_GET_RECORD_NAME
1713 
1714  case _STEP_CHANGE_GROUP:
1715 
1716  { //start scope of _STEP_CHANGE_GROUP localAddHandlers
1717 
1719  document.getElementById(stepString + "activateAlias").onclick =
1720  function()
1721  {
1722  //activate alias then go back to record name
1723  var alias = document.getElementById(stepString + "aliases").value;
1724  Debug.log("activateAlias " + alias);
1725 
1726  //find associated aliasObj
1727  var aliasObj;
1728  for(var i=0;i<
1729  _systemGroups.aliases[paramObj["groupType"]].length;++i)
1730  if(_systemGroups.aliases[paramObj["groupType"]][i].alias ==
1731  alias)
1732  {
1733  aliasObj = _systemGroups.aliases[paramObj["groupType"]][i];
1734  break;
1735  }
1736 
1737  Debug.log("activateAlias group " + aliasObj.name +
1738  "-" + aliasObj.key);
1739 
1740  ConfigurationAPI.activateGroup(aliasObj.name, aliasObj.key,
1741  true /*ignoreWarnings*/,
1742  /*doneHandler*/
1743  function()
1744  {
1745  Debug.log("The System Alias '" + alias +
1746  "' (" + aliasObj.name + " (" +
1747  aliasObj.key + ")) was successfully activated!", Debug.INFO_PRIORITY);
1748 
1749  initRecordWizard();
1750  }); //end activate group handler
1751  }; //end activate alias handler
1752 
1754  document.getElementById(stepString + "groupNames").onchange =
1755  function()
1756  {
1757  //fill keys drop down
1758  Debug.log("Filling dropdown with keys for " + this.value);
1759  var str = "";
1760  for(var i=0;i<_systemGroups.groups[paramObj["groupType"]]
1761  [this.value].keys.length;++i)
1762  {
1763  str += htmlOpen("option",
1764  {
1765  },
1766  _systemGroups.groups[paramObj["groupType"]]
1767  [this.value].keys[i] /*innerHTML*/, true /*closeTag*/);
1768  }
1769  document.getElementById(stepString + "groupKeys").innerHTML =
1770  str;
1771  }; //end group names dropdown handler
1772 
1774  document.getElementById(stepString + "activateGroup").onclick =
1775  function()
1776  {
1777  //activate alias then go back to record name
1778  var name = document.getElementById(stepString + "groupNames").value;
1779  var key = document.getElementById(stepString + "groupKeys").value;
1780 
1781  Debug.log("activateGroup " + name +
1782  "-" + key);
1783 
1784  ConfigurationAPI.activateGroup(name, key,
1785  true /*ignoreWarnings*/,
1786  /*doneHandler*/
1787  function()
1788  {
1789  Debug.log("The Group '" + name + " (" +
1790  key + ") was successfully activated!", Debug.INFO_PRIORITY);
1791 
1792  initRecordWizard();
1793  }); //end activate group handler
1794  }; //end activate alias handler
1795 
1796  } //end scope of _STEP_CHANGE_GROUP localAddHandlers
1797 
1798  break; //end _STEP_CHANGE_GROUP
1799  default:;
1800  }
1801 
1802 
1803 
1804 
1806  //add functions shared by handlers above and below
1807  { //fake scope for grouping
1808 
1809 
1811  function localCreateIntermediateLevelRecord(name)
1812  {
1813  Debug.log("localCreateIntermediateLevelRecord " + name);
1814 
1816  //create new record
1817  ConfigurationAPI.addSubsetRecords(
1818  getIntermediateTable(),
1819  name,
1821  function(modifiedTables,err) //start addSubsetRecords handler
1822  {
1823  Debug.log("modifiedTables length " + modifiedTables.length);
1824  if(!modifiedTables.length)
1825  {
1826  //really an error
1827  Debug.log("There was an error while creating the XDAQ Application '" +
1828  name + ".' " + err,
1829  Debug.HIGH_PRIORITY);
1830  return;
1831  }
1832  _modifiedTables = modifiedTables;
1833 
1834  //at this point new app was created
1835  Debug.log("New intermediate record '" + name + "' was successfully created!");
1836 
1837  newParamObj["isNew" + getIntermediateTypeName()] = true;
1838 
1839  if(_recordAlias == _RECORD_TYPE_PROCESSOR)
1840  {
1841  if(_intermediateLevel == 0)
1842  {
1843  //add to app list for going back
1844  // Note may need to initialize things, if skipped _STEP_WHICH_APP to get here
1845  if(!_paramObjMap[_STEP_PROC_WHICH_BUFFER]) _paramObjMap[_STEP_PROC_WHICH_BUFFER] = {};//initialize if needed
1846  if(!_paramObjMap[_STEP_PROC_WHICH_BUFFER]["allBuffers"]) _paramObjMap[_STEP_PROC_WHICH_BUFFER]["allBuffers"] = []; //initialize if needed
1847  if(_paramObjMap[_STEP_PROC_WHICH_BUFFER]["allBuffers"].indexOf(name) == -1)
1848  _paramObjMap[_STEP_PROC_WHICH_BUFFER]["allBuffers"].push(name);
1849  }
1850  else
1851  throw("?");
1852  }
1853  else
1854  throw("?");
1855 
1856  localSetupIntermediateLevelRecord(name);
1857 
1858  }, //end addSubsetRecords handler
1859  _modifiedTables,
1860  true /*silenceErrors*/); //end addSubsetRecords
1861  } //end localCreateIntermediateLevelRecord()
1862 
1864  function localSetupIntermediateLevelRecord(name)
1865  {
1866  //get group id
1867  var recordGroupId = "";
1868  if(_recordAlias == _RECORD_TYPE_PROCESSOR)
1869  {
1870  if(_intermediateLevel == 0)
1871  {
1872  recordGroupId = _paramObjMap[_STEP_WHICH_APP]["appChildGroupName"];
1873  }
1874  else
1875  throw("?");
1876  }
1877  else
1878  throw("?");
1879 
1880 
1881  Debug.log("localSetupIntermediateLevelRecord " + name +
1882  " into groupId=" + recordGroupId);
1883 
1884  var fieldArr,valueArr;
1885 
1886  if(_recordAlias == _RECORD_TYPE_PROCESSOR)
1887  {
1888  if(_intermediateLevel == 0)
1889  {
1890  fieldArr = [
1891  "Status",
1892  "DataManagerGroupID",
1893  "LinkToDataProcessorTable",
1894  "LinkToDataBufferGroupID",
1895  "CommentDescription"
1896  ];
1897 
1898  valueArr = [
1899  "1",//"Status",
1900  recordGroupId,//"DataManagerGroupID",
1901  getRecordConfiguration(),//"LinkToDataProcessorTable",
1902  name+"ProcessorGroup",//"LinkToDataBufferGroupID",
1903  _DEFAULT_WIZ_COMMENT//"CommentDescription"
1904  ];
1905  }
1906  else
1907  throw("?");
1908 
1909  }
1910 
1911  ConfigurationAPI.setFieldValuesForRecords(
1912  getIntermediateTable(),
1913  name, //recordArr
1914  fieldArr, //fieldArr
1915  valueArr, //valueArr
1916  function(modifiedTables)
1917  {
1918  Debug.log("modifiedTables length " + modifiedTables.length);
1919 
1920  if(!modifiedTables.length)
1921  {
1922  Debug.log("There was an error while writing the values for the App.",
1923  Debug.HIGH_PRIORITY);
1924  return;
1925  }
1926  _modifiedTables = modifiedTables;
1927 
1928  //now create record
1929 
1930  //store group name for record setup later
1931  if(!_paramObjMap[_STEP_PROC_WHICH_BUFFER]) _paramObjMap[_STEP_PROC_WHICH_BUFFER] = {}; //init if needed
1932  _paramObjMap[_STEP_PROC_WHICH_BUFFER]["recordGroupName"] = name+"ProcessorGroup";
1933 
1934  localCreateRecord(getRecordConfiguration());
1935 
1936  }, //end setFieldValuesForRecords handler
1937  _modifiedTables); //end setFieldValuesForRecords
1938  } //end localSetupApp()
1939 
1941  function localCreateApp(name)
1942  {
1943  Debug.log("localCreateApp " + name);
1945  //create new record
1946  ConfigurationAPI.addSubsetRecords(
1947  _XDAQAPP_BASE_PATH,
1948  name,
1950  function(modifiedTables,err) //start addSubsetRecords handler
1951  {
1952  Debug.log("modifiedTables length " + modifiedTables.length);
1953  if(!modifiedTables.length)
1954  {
1955  //really an error
1956  Debug.log("There was an error while creating the XDAQ Application '" +
1957  name + ".' " + err,
1958  Debug.HIGH_PRIORITY);
1959  return;
1960  }
1961  _modifiedTables = modifiedTables;
1962 
1963  //at this point new app was created
1964  Debug.log("New app '" + name + "' was successfully created!");
1965 
1966  //add to app list for going back
1967  // Note may need to initialize things, if skipped _STEP_WHICH_APP to get here
1968  if(!_paramObjMap[_STEP_WHICH_APP]) _paramObjMap[_STEP_WHICH_APP] = {};//initialize if needed
1969  if(!_paramObjMap[_STEP_WHICH_APP]["apps"]) _paramObjMap[_STEP_WHICH_APP]["apps"] = []; //initialize if needed
1970  if(_paramObjMap[_STEP_WHICH_APP]["apps"].indexOf(name) == -1)
1971  _paramObjMap[_STEP_WHICH_APP]["apps"].push(name);
1972  _paramObjMap[_STEP_WHICH_APP]["isNewApp"] = true;
1973 
1974  localSetupApp(name);
1975 
1976  }, //end addSubsetRecords handler
1977  _modifiedTables,
1978  true /*silenceErrors*/); //end addSubsetRecords
1979  } //end localCreateApp()
1980 
1982  function localSetupApp(name)
1983  {
1984  var context = _paramObjMap[_STEP_WHICH_CONTEXT]["contextName"];
1985  var appGroupId = _paramObjMap[_STEP_SET_CONTEXT_HOST]["appGroupId"];
1986 
1987  Debug.log("localSetupApp " + name + " in context=" + context + " groupId=" + appGroupId);
1988 
1989  var fieldArr,valueArr;
1990 
1991  if(1)//_recordAlias == _RECORD_TYPE_FE)
1992  {
1993  fieldArr = [
1994  "Status",
1995  "ApplicationGroupID",
1996  "LinkToSupervisorTable",
1997  "LinkToSupervisorUID",
1998  "Class",
1999  "Instance",
2000  "Module",
2001  "CommentDescription"
2002  ];
2003 
2004  valueArr = [
2005  "1",//"Status",
2006  appGroupId,//"ApplicationGroupID",
2007  getAppConfiguration(),//"LinkToSupervisorTable",
2008  name+"Config",//"LinkToSupervisorUID",
2009  getAppClass(),//"Class",
2010  "1",//"Instance",
2011  getAppModule(),//"Module",
2012  _DEFAULT_WIZ_COMMENT//"CommentDescription"
2013  ];
2014  }
2015  // else if(_recordAlias == _RECORD_TYPE_PROCESSOR
2016  // )
2017  // {
2018  // throw("TODO.");
2019  // }
2020 
2021  ConfigurationAPI.setFieldValuesForRecords(
2022  _XDAQAPP_BASE_PATH,
2023  name, //recordArr
2024  fieldArr, //fieldArr
2025  valueArr, //valueArr
2026  function(modifiedTables)
2027  {
2028  Debug.log("modifiedTables length " + modifiedTables.length);
2029 
2030  if(!modifiedTables.length)
2031  {
2032  Debug.log("There was an error while writing the values for the App.",
2033  Debug.HIGH_PRIORITY);
2034  return;
2035  }
2036  _modifiedTables = modifiedTables;
2037 
2038  // now setup specific supervisor config
2039  localCreateAppConfig(name+"Config");
2040 
2041  }, //end setFieldValuesForRecords handler
2042  _modifiedTables); //end setFieldValuesForRecords
2043  } //end localSetupApp()
2044 
2046  function localCreateAppConfig(name)
2047  {
2048  Debug.log("localCreateAppConfig " + name);
2050  //create new record
2051  ConfigurationAPI.addSubsetRecords(
2052  getAppConfiguration(),
2053  name,
2055  function(modifiedTables,err) //start addSubsetRecords handler
2056  {
2057  Debug.log("modifiedTables length " + modifiedTables.length);
2058  if(!modifiedTables.length)
2059  {
2060  //really an error
2061  Debug.log("There was an error while creating the XDAQ Application '" +
2062  name + ".' " + err,
2063  Debug.HIGH_PRIORITY);
2064  return;
2065  }
2066  _modifiedTables = modifiedTables;
2067 
2068  //at this point new app config was created
2069  Debug.log("New app config '" + name + "' was successfully created!");
2070 
2071  //now setup app config
2072  localSetupAppConfig(name);
2073 
2074  }, //end addSubsetRecords handler
2075  _modifiedTables,
2076  true /*silenceErrors*/); //end addSubsetRecords
2077  } //end localCreateAppConfig()
2078 
2080  function localSetupAppConfig(name)
2081  {
2082  var context = _paramObjMap[_STEP_WHICH_CONTEXT]["contextName"];
2083  Debug.log("localSetupAppConfig " + name + " in context=" + context);
2084 
2085  var fieldArr,valueArr;
2086  var groupSuffix;
2087 
2088  _intermediateLevel = 0; //reset
2089 
2090  if(_recordAlias == _RECORD_TYPE_FE)
2091  {
2092  fieldArr = [
2093  "LinkToFEInterfaceTable",
2094  "LinkToFEInterfaceGroupID",
2095  "CommentDescription"
2096  ];
2097  groupSuffix = "FEGroup";
2098 
2099  valueArr = [
2100  getRecordConfiguration(),//"LinkToFEInterfaceTable",
2101  name+groupSuffix,//"LinkToFEInterfaceGroupID",
2102  _DEFAULT_WIZ_COMMENT//"CommentDescription"
2103  ];
2104  }
2105  else if(_recordAlias == _RECORD_TYPE_PROCESSOR
2106  )
2107  {
2108 
2109  fieldArr = [
2110  "LinkToDataBufferTable",
2111  "LinkToDataManagerGroupID",
2112  "CommentDescription"
2113  ];
2114 
2115  groupSuffix = "DMGroup";
2116 
2117  valueArr = [
2118  getIntermediateTable(),//"LinkToFEInterfaceTable",
2119  name+groupSuffix,//"LinkToFEInterfaceGroupID",
2120  _DEFAULT_WIZ_COMMENT//"CommentDescription"
2121  ];
2122  }
2123  else throw("?");
2124 
2125  ConfigurationAPI.setFieldValuesForRecords(
2126  getAppConfiguration(),
2127  name, //recordArr
2128  fieldArr, //fieldArr
2129  valueArr, //valueArr
2130  function(modifiedTables)
2131  {
2132  Debug.log("modifiedTables length " + modifiedTables.length);
2133 
2134  if(!modifiedTables.length)
2135  {
2136  Debug.log("There was an error while writing the values for the App.",
2137  Debug.HIGH_PRIORITY);
2138  return;
2139  }
2140  _modifiedTables = modifiedTables;
2141 
2142  //save group name for later
2143  // Note may need to initialize things, if skipped _STEP_WHICH_APP to get here
2144  if(!_paramObjMap[_STEP_WHICH_APP]) _paramObjMap[_STEP_WHICH_APP] = {};//initialize if needed
2145 
2146 
2147  _paramObjMap[_STEP_WHICH_APP]["appChildGroupName"] = name+groupSuffix;
2148 
2149  if(_recordAlias == _RECORD_TYPE_FE)
2150  {
2151  Debug.log("Creating record...");
2152  // now setup specific plugin
2153  localCreateRecord(getRecordConfiguration());
2154  }
2155  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2156  {
2157  Debug.log("Setting up extra buffer level...");
2158  localHandleIntermediateLevel();
2159  }
2160  else throw("?");
2161 
2162  }, //end setFieldValuesForRecords handler
2163  _modifiedTables); //end setFieldValuesForRecords
2164  } //end localSetupAppConfig()
2165 
2166 
2168  // _intermediateLevel is incremented by some handler, if needed
2169  function localHandleIntermediateLevel()
2170  {
2171  if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2172  {
2173  switch(_intermediateLevel)
2174  {
2175  case 0: //create Data Buffer in Data Manager
2176  {
2177 
2178  var bufferGroupId = _paramObjMap[_STEP_WHICH_APP]["appChildGroupName"];
2179  var appName = _paramObjMap[_STEP_WHICH_APP]["appName"];
2180 
2181 
2182  Debug.log("localCreateIntermediateLevel-" + _intermediateLevel +
2183  " DataManager=" + appName);
2184 
2185  //Steps:
2186  // get all buffers, then all buffers associated with data manager
2187  // if 0, make new one
2188  // if some, present choices to user (new or existing)
2189 
2190  // get all existing apps
2191  ConfigurationAPI.getSubsetRecords(
2192  getIntermediateTable(),
2193  "" /*_recordPreFilterList*/,
2194  function(allRecords)
2195  {
2196  Debug.log("all buffers found = " + allRecords.length);
2197  console.log(allRecords);
2198 
2199  //store allBuffers for later
2200  if(!_paramObjMap[_STEP_PROC_WHICH_BUFFER]) _paramObjMap[_STEP_PROC_WHICH_BUFFER] = {}; //init if needed
2201  _paramObjMap[_STEP_PROC_WHICH_BUFFER]["allBuffers"] = allRecords;
2202 
2203  // get existing apps of appClass
2204  ConfigurationAPI.getSubsetRecords(
2205  getIntermediateTable(),
2206  "DataManagerGroupID="+
2207  encodeURIComponent(bufferGroupId) /*_recordPreFilterList*/,
2208  function(records)
2209  {
2210  Debug.log("buffers of DataManager '" + appName +
2211  "' found = " + records.length);
2212  console.log(records);
2213 
2214  // var bufferName = "";
2215  // if(_paramObjMap[_STEP_PROC_WHICH_BUFFER]["bufferName"])
2216  // bufferName = _paramObj["level" + _intermediateLevel + "RecordName"];
2217  //else
2218  // _paramObj["level" + _intermediateLevel + "RecordName"] =
2219  // (bufferName = ConfigurationAPI.createNewRecordName(listOfExisting)appName + "DB"); //generate the buffer name
2220 
2221  //Debug.log("bufferName " + bufferName);
2222 
2223  if(records.length == 0)
2224  {
2225  //if no buffers in context, create buffer
2226  // with made up name
2227 
2228  var bufferName = ConfigurationAPI.createNewRecordName("Buffer",allRecords);
2229 
2230  //store bufferName for later
2231  _paramObjMap[_STEP_PROC_WHICH_BUFFER]["bufferName"] = bufferName;
2232 
2233  localCreateIntermediateLevelRecord(appName);
2234  }
2235  else //if buffers in context, ask if adding to existing
2236  {
2237  _paramObjMap[_STEP_PROC_WHICH_BUFFER]["buffers"] = records;
2238  showPrompt(_STEP_PROC_WHICH_BUFFER);
2239  }
2240 
2241  }, //end all getSubsetRecords handler
2242  _modifiedTables); //end all getSubsetRecords
2243 
2244  }, //end all getSubsetRecords handler
2245  _modifiedTables); //end all getSubsetRecords
2246 
2247  var bufferName
2248  }
2249  break; //end create Data Buffer in Data Manager
2250  default: throw("?");
2251  }
2252 
2253  }
2254  else throw("?");
2255 
2256  } //end localCreateIntermediateLevel()
2257 
2259  //for case when using existing intermediate (e.g. Buffer)
2260  function localGetExistingIntermediateTargetGroupID(intermediateName)
2261  {
2262 
2263  Debug.log("localGetExistingSupervisorTargetGroupID " + intermediateName +
2264  " of type " + getIntermediateTypeName());
2265 
2266  ConfigurationAPI.getTree(
2267  getIntermediateTable() + "/" + intermediateName,
2268  4 /*depth*/,
2269  _modifiedTables,
2270  function(tree)
2271  {
2272  console.log(tree);
2273 
2274  var table;
2275  var groupId;
2276 
2277  try
2278  { //accessing tree GroupID location directly
2279 
2280  if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2281  {
2282 
2283  if(tree.children[1].children[0].nodeName !=
2284  "GroupID")
2285  throw("Invalid GroupID location in tree.");
2286  if(tree.children[1].children[1].nodeName !=
2287  "LinkTableName")
2288  throw("Invalid Link Table location in tree.");
2289 
2290  groupId =
2291  tree.children[1].children[0].getAttribute("value");
2292  table =
2293  tree.children[1].children[1].getAttribute("value");
2294  }
2295  else throw("?");
2296  }
2297  catch(e)
2298  {
2299  Debug.log("Error locating group in configuration for the new record. " + e,
2300  Debug.HIGH_PRIORITY);
2301  return;
2302  }
2303  Debug.log("Group Link found as " + table + ":" + groupId);
2304 
2305  //save group name for later
2306  // Note may need to initialize things, if skipped _STEP_WHICH_APP to get here
2307 
2308 
2309  if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2310  {
2311  if(!_paramObjMap[_STEP_PROC_WHICH_BUFFER]) _paramObjMap[_STEP_PROC_WHICH_BUFFER] = {};//initialize if needed
2312  _paramObjMap[_STEP_PROC_WHICH_BUFFER]["recordGroupName"] = groupId;
2313  localCreateRecord(table);
2314  Debug.log("Setting up extra buffer level...");
2315  }
2316  else throw("?");
2317 
2318 
2319  }); //end getTree
2320 
2321 
2322  } //end localGetExistingIntermediateTargetGroupID()
2323 
2325  //for case when using existing supervisor
2326  function localGetExistingSupervisorTargetGroupID(supervisorName)
2327  {
2328  Debug.log("localGetExistingSupervisorTargetGroupID " + supervisorName);
2329 
2330  ConfigurationAPI.getTree(
2331  _XDAQAPP_BASE_PATH + "/" + supervisorName,
2332  4 /*depth*/,
2333  _modifiedTables,
2334  function(tree)
2335  {
2336  console.log(tree);
2337 
2338  var table;
2339  var groupId;
2340 
2341  try
2342  { //accessing tree GroupID location directly
2343 
2344  if(tree.children[1].children[4].children[0].nodeName !=
2345  "GroupID")
2346  throw("Invalid GroupID location in tree.");
2347  if(tree.children[1].children[4].children[1].nodeName !=
2348  "LinkTableName")
2349  throw("Invalid Link Table location in tree.");
2350 
2351  groupId =
2352  tree.children[1].children[4].children[0].getAttribute("value");
2353  table =
2354  tree.children[1].children[4].children[1].getAttribute("value");
2355 
2356  }
2357  catch(e)
2358  {
2359  Debug.log("Error locating group in configuration for the new record. " + e,
2360  Debug.HIGH_PRIORITY);
2361  return;
2362  }
2363  Debug.log("Group Link found as " + table + ":" + groupId);
2364 
2365  //save group name for later
2366  // Note may need to initialize things, if skipped _STEP_WHICH_APP to get here
2367  if(!_paramObjMap[_STEP_WHICH_APP]) _paramObjMap[_STEP_WHICH_APP] = {};//initialize if needed
2368  _paramObjMap[_STEP_WHICH_APP]["appChildGroupName"] = groupId;
2369 
2370  if(_recordAlias == _RECORD_TYPE_FE)
2371  {
2372  Debug.log("Creating record...");
2373  localCreateRecord(table);
2374  }
2375  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2376  {
2377  Debug.log("Setting up extra buffer level...");
2378  _intermediateLevel = 0; //reset
2379  localHandleIntermediateLevel();
2380  }
2381  else throw("?");
2382 
2383 
2384  }); //end getTree
2385 
2386  } //end localGetExistingSupervisorTargetGroupID()
2387 
2388 
2390  function localCreateRecord(table)
2391  {
2392  Debug.log("localCreateRecord " + recordName + " in table=" + table);
2393 
2395  //create new record
2396  ConfigurationAPI.addSubsetRecords(
2397  table,
2398  recordName,
2400  function(modifiedTables,err) //start addSubsetRecords handler
2401  {
2402  Debug.log("modifiedTables length " + modifiedTables.length);
2403  if(!modifiedTables.length || err)
2404  {
2405  var reallyAnError = true;
2406  if(_furthestStep >= _STEP_SET_RECORD_FIELDS)
2407  {
2408  //then already created record, so ignore error that it exists
2409  if(err.indexOf("Entries in UID are not unique") >= 0)
2410  {
2411  Debug.log("Ignoring UID not unique error since likely already created..." +
2412  err);
2413  reallyAnError = false;
2414  }
2415  }
2416 
2417  if(reallyAnError)
2418  {
2419  //really an error
2420  Debug.log("There was an error while creating the " + _recordAlias +
2421  " record named '" +
2422  recordName + ".' " + err,
2423  Debug.HIGH_PRIORITY);
2424  return;
2425  }
2426  }
2427  else
2428  _modifiedTables = modifiedTables;
2429 
2430  console.log("_modifiedTables",_modifiedTables);
2431 
2432  //at this point new app config was created
2433  Debug.log("New " + _recordAlias + " record named '" + recordName + "' was successfully created!");
2434 
2435  //now get helper valuse for record details
2436  localGetHelperValuesForRecord();
2437 
2438  }, //end addSubsetRecords handler
2439  _modifiedTables,
2440  true /*silenceErrors*/); //end addSubsetRecords
2441  } //end localCreateRecord()
2442 
2444  //localGetHelperValuesForRecord
2445  function localGetHelperValuesForRecord()
2446  {
2447  Debug.log("localGetHelperValuesForRecord " + recordName);
2448 
2449  ConfigurationAPI.getFieldsOfRecords(
2450  getRecordConfiguration(),
2451  recordName,
2452  "!*Comment*,!*SlowControls*,!Status,!" + getRecordGroupIDField()/*fieldList*/,
2453  -1 /*maxDepth*/,
2454  function(recordFields)
2455  {
2456  newParamObj["fields"] = recordFields;
2457  Debug.log("recordFields found = " + recordFields.length);
2458  console.log(recordFields);
2459 
2460  //specifically go to _STEP_SET_RECORD_FIELDS (because may have jumped here)
2461  showPrompt(_STEP_SET_RECORD_FIELDS,newParamObj);
2462 
2463  }, //end getFieldsOfRecords handler
2464  _modifiedTables); //end getFieldsOfRecords
2465 
2466  } //end localGetHelperValuesForRecord
2467 
2468  } //end fake scope for shared handler functions
2469 
2470 
2471 
2472 
2473 
2474 
2476  //add handlers for all steps
2477  try
2478  {
2479  document.getElementsByClassName(stepString + "nextButton")[0].onclick =
2480  localNextButtonHandler;
2481  document.getElementsByClassName(stepString + "nextButton")[1].onclick =
2482  localNextButtonHandler;
2483 
2484  function localNextButtonHandler()
2485  {
2486 
2487  //extract specific step parameters
2488  switch(stepIndex)
2489  {
2490  case _STEP_SET_RECORD_FIELDS:
2491 
2492  //set record fields and save modified tables
2493  localScopeSetRecordFieldsDoIt();
2494 
2496  function localScopeSetRecordFieldsDoIt() //function just for scoped vars
2497  {
2498  Debug.log("localScopeSetRecordFieldsDoIt");
2499 
2500  var recordFields = paramObj["fields"];
2501 
2502  var groupName = "";
2503 
2504  if(_recordAlias == _RECORD_TYPE_FE)
2505  groupName = _paramObjMap[_STEP_WHICH_APP]["appChildGroupName"];
2506  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2507  groupName = _paramObjMap[_STEP_PROC_WHICH_BUFFER]["recordGroupName"];
2508  else throw("?");
2509 
2510 
2511  //make arrays for all field/values pairs
2512  var fieldArr = [];
2513  var valueArr = [];
2514 
2515  //for each field, get value
2516  for(var i=0;i<recordFields.length;++i)
2517  {
2518  fieldArr.push(recordFields[i].fieldRelativePath +
2519  recordFields[i].fieldColumnName);
2520  valueArr.push(ConfigurationAPI.getEditableFieldValue(
2521  recordFields[i],
2522  i));
2523  }
2524 
2525  //add groupId field to modify
2526  // and comment, etc.
2527  fieldArr.push(getRecordGroupIDField());
2528  valueArr.push(groupName);
2529  fieldArr.push("CommentDescription");
2530  valueArr.push(_DEFAULT_WIZ_COMMENT);
2531  fieldArr.push("Status");
2532  valueArr.push("1");
2533 
2534  ConfigurationAPI.setFieldValuesForRecords(
2535  getRecordConfiguration(),
2536  recordName, //recordArr
2537  fieldArr, //fieldArr
2538  valueArr, //valueArr
2539  function(modifiedTables)
2540  {
2541  Debug.log("modifiedTables length " + modifiedTables.length);
2542 
2543  if(!modifiedTables.length)
2544  {
2545  Debug.log("There was an error while writing the values.",
2546  Debug.HIGH_PRIORITY);
2547  return;
2548  }
2549 
2550  _modifiedTables = modifiedTables;
2551 
2552  //proceed to save (quietly) tables, groups, aliases
2553  ConfigurationAPI.saveModifiedTables(_modifiedTables,
2554  function(savedTables, savedGroups, savedAliases)
2555  {
2556  if(!savedTables.length)
2557  {
2558  Debug.log("There was an error while saving the values.",
2559  Debug.HIGH_PRIORITY);
2560  return;
2561  }
2562 
2563  Debug.log("The new " +
2564  _recordAlias + " named '" + recordName + "' was successfully created!",
2565  Debug.INFO_PRIORITY);
2566 
2567  _modifiedTables = undefined; //clear after save
2568 
2569  _aRecordWasModified = true;
2570 
2571  initRecordWizard(); //start over if no done handler
2572 
2573  }); //end saveModifiedTables handler
2574 
2575  }, //end setFieldValuesForRecords handler
2576  _modifiedTables); //end setFieldValuesForRecords
2577 
2578  } //end localScopeSetRecordFieldsDoIt()
2579 
2580  return; //prevent default next action
2581 
2582  break; //end _STEP_SET_RECORD_FIELDS
2583 
2584  case _STEP_SET_CONTEXT_HOST:
2585 
2586  //set fields for selected context
2587  localHandleSetupContext();
2588 
2590  function localHandleSetupContext() //function just for scoped vars
2591  {
2592  Debug.log("localHandleSetupContext");
2593 
2594  var context = _paramObjMap[_STEP_WHICH_CONTEXT]["contextName"];
2595  var address = document.getElementById(stepString + "address").value.trim();
2596  var port = document.getElementById(stepString + "port").value.trim();
2597 
2598  //save name to param for this step
2599  paramObj["address"] = address;
2600 
2601  //save name to param for this step
2602  paramObj["port"] = port;
2603 
2604  var appGroupId = context+"Apps";
2605  if(!paramObj["isNewContext"])
2606  appGroupId = paramObj["appGroupId"];
2607  else
2608  paramObj["appGroupId"] = appGroupId;
2609 
2610  var fieldArr = ["Status",
2611  "LinkToApplicationTable",
2612  "ApplicationGroupID",
2613  "Address",
2614  "Port",
2615  "CommentDescription"
2616  ];
2617 
2618  var valueArr = ["1",//"Status",
2619  _XDAQAPP_BASE_PATH,//"LinkToApplicationTable",
2620  appGroupId,//"ApplicationGroupID",
2621  address,//"Address"
2622  port,//"Port"
2623  _DEFAULT_WIZ_COMMENT//"CommentDescription"
2624  ];
2625 
2626  ConfigurationAPI.setFieldValuesForRecords(
2627  _XDAQ_BASE_PATH,
2628  context, //recordArr
2629  fieldArr, //fieldArr
2630  valueArr, //valueArr
2631  function(modifiedTables)
2632  {
2633  Debug.log("modifiedTables length " + modifiedTables.length);
2634 
2635  if(!modifiedTables.length)
2636  {
2637  Debug.log("There was an error while writing the values.",
2638  Debug.HIGH_PRIORITY);
2639  return;
2640  }
2641  _modifiedTables = modifiedTables;
2642 
2643  //create Apps now
2644 
2645  //if FE
2646  // if no apps in context, create FESupervisor
2647  // if apps in context, ask if adding to existing
2648  //if consumer/producer
2649  // if no apps in context, create DataManagerSupervisor
2650  // if apps in context, ask if adding to existing
2651 
2652  localGetAppInfo();
2653 
2654  }, //end setFieldValuesForRecords handler
2655  _modifiedTables); //end setFieldValuesForRecords
2656 
2658  function localGetAppInfo()
2659  {
2660  var appGroupId = paramObj["appGroupId"];
2661  Debug.log("localGetAppInfo for context app group " + appGroupId);
2662 
2663  // get all existing apps
2664  ConfigurationAPI.getSubsetRecords(
2665  _XDAQAPP_BASE_PATH,
2666  "" /*_recordPreFilterList*/,
2667  function(allApps)
2668  {
2669  Debug.log("all apps found = " + allApps.length);
2670 
2671  console.log(allApps);
2672 
2673  if(!_paramObjMap[_STEP_WHICH_APP]) _paramObjMap[_STEP_WHICH_APP] = {}; //init if needed
2674 
2675  //store all apps for later
2676  _paramObjMap[_STEP_WHICH_APP]["allApps"] = allApps;
2677 
2678  // get existing apps of appClass
2679  ConfigurationAPI.getSubsetRecords(
2680  _XDAQAPP_BASE_PATH,
2681  "Class=" +
2682  encodeURIComponent(getAppClass()) +
2683  ";ApplicationGroupID="+
2684  //For DEBUG "testContextApps",
2685  encodeURIComponent(appGroupId) /*_recordPreFilterList*/,
2686  function(records)
2687  {
2688  Debug.log("apps of appClass found = " + records.length);
2689  console.log(records);
2690 
2691  if(records.length == 0)
2692  {
2693  //if no apps in context, create XDAQ App
2694  // with made up name
2695 
2696  var appName = ConfigurationAPI.createNewRecordName(
2697  getApp() +
2698  _paramObjMap[_STEP_GET_RECORD_NAME].recordName,
2699  allApps);
2700 
2701  //store app name for later
2702  _paramObjMap[_STEP_WHICH_APP]["appName"] = appName;
2703 
2704  localCreateApp(appName);
2705  }
2706  else //if apps in context, ask if adding to existing
2707  {
2708  _paramObjMap[_STEP_WHICH_APP]["apps"] = records;
2709  showPrompt(_STEP_WHICH_APP);
2710  }
2711 
2712  }, //end type class getSubsetRecords handler
2713  _modifiedTables); //end type class getSubsetRecords
2714  }, //end all getSubsetRecords handler
2715  _modifiedTables); //end all getSubsetRecords
2716  } //end localGetAppInfo()
2717 
2718  } //end localHandleSetupContext()
2719 
2720  return; //stop standard next call
2721 
2722  break; //end _STEP_SET_CONTEXT_HOST next handler
2723 
2724  case _STEP_GET_RECORD_NAME:
2725 
2726  //save name to param for this step
2727  recordName = document.getElementById(stepString + "recordName").value.trim();
2728  paramObj["recordName"] = recordName;
2729 
2730  if(recordName.length < 1)
2731  {
2732  Debug.log("Invalid " + _recordAlias + " name ' " +
2733  recordName + "' (too short). Please enter a valid name.",
2734  Debug.HIGH_PRIORITY);
2735  return;
2736  }
2737 
2738  for(var i=0;i<_subsetUIDs.length;++i)
2739  if(_subsetUIDs[i] == recordName)
2740  {
2741  Debug.log("Invalid " + _recordAlias + " name ' " +
2742  recordName + "' (name already in use in the active configuration). Please enter a valid name.",
2743  Debug.HIGH_PRIORITY);
2744  return;
2745  }
2746 
2747  //get existing contexts and give as parameter
2748  ConfigurationAPI.getSubsetRecords(
2749  _XDAQ_BASE_PATH,
2750  "",
2751  function(records)
2752  {
2753  newParamObj["contexts"] = records;
2754  Debug.log("contexts found = " + records.length);
2755  console.log(records);
2756 
2757  showPrompt(nextStepIndex,newParamObj);
2758 
2759  }); //end getSubsetRecords handler
2760  return; //prevent default show prompt, do in handler
2761  break; //end _STEP_GET_RECORD_NAME next handler
2762 
2763  case _STEP_WHICH_RECORD_TYPE:
2764 
2766  if(scopeWhichRecordTypeNext())
2767  return; //prevent default show prompt, do initRecordWizard
2768 
2769  function scopeWhichRecordTypeNext()
2770  {
2771  var newRecordAlias = document.getElementById(stepString + "recordTypes").value.trim();
2772 
2773  var needToInit = (_recordAlias != newRecordAlias);
2774 
2775  _recordAlias = newRecordAlias;
2776  Debug.log("_recordAlias chosen as " + _recordAlias);
2777 
2778  if(needToInit) initRecordWizard();
2779  return needToInit;
2780  } //end scopeWhichRecordTypeNext()
2781 
2782  break; //end _STEP_WHICH_RECORD_TYPE next handler
2783  default:;
2784  }
2785  showPrompt(nextStepIndex,newParamObj);
2786  } //end next handler
2787  }
2788  catch(e){ Debug.log("Caught ERROR: " + e.stack);}
2789 
2790  try
2791  {
2792  document.getElementsByClassName(stepString + "prevButton")[0].onclick =
2793  localPrevButtonHandler;
2794  document.getElementsByClassName(stepString + "prevButton")[1].onclick =
2795  localPrevButtonHandler;
2796 
2797  function localPrevButtonHandler()
2798  {
2799  //extract specific step parameters
2800  switch(stepIndex)
2801  {
2802  case _STEP_WHICH_RECORD_TYPE:
2803 
2804  //close window and clear data
2805 
2806  _subsetUIDs = []; //reset
2807  _modifiedTables = undefined; //reset
2808  _furthestStep = -1; // reset
2809  _paramObjMap = {}; //reset
2810  _systemGroups = {}; //reset
2811 
2812  //remove all existing dialogs
2813  ConfigurationAPI.removeAllPopUps();
2814 
2815  if(_doneHandler) _doneHandler(_aRecordWasModified);
2816  return; //prevent default prev showPrompt
2817  break;
2818  default:;
2819  }
2820  showPrompt(prevStepIndex);
2821  } //end prev handler
2822  }
2823  catch(e){ Debug.log("Caught ERROR: " + e.stack);}
2824 
2825  } //end localAddHandlers()
2826 
2827  } //end showPrompt()
2828 
2829 
2830  //=====================================================================================
2831  //getApp ~~
2832  function getApp()
2833  {
2834  var retVal = "";
2835  if(_recordAlias == _RECORD_TYPE_FE)
2836  retVal = "FESupervisor";
2837  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2838  retVal = "DataManagerSupervisor";
2839  else
2840  throw("?");
2841 
2842  return retVal;
2843  } //end getApp()
2844 
2845  //=====================================================================================
2846  //getAppClass ~~
2847  function getAppClass()
2848  {
2849  return "ots::" + getApp();
2850  } //end getAppClass()
2851 
2852  //=====================================================================================
2853  //getAppModule ~~
2854  function getAppModule()
2855  {
2856  var otsModule = "";
2857  if(_recordAlias == _RECORD_TYPE_FE)
2858  otsModule = "${OTSDAQ_LIB}/libCoreSupervisors.so";
2859  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2860  otsModule = "${OTSDAQ_LIB}/libCoreSupervisors.so";
2861  else
2862  throw("?");
2863 
2864  return otsModule;
2865  } //end getAppModule()
2866 
2867  //=====================================================================================
2868  //getAppConfiguration ~~
2869  function getAppConfiguration()
2870  {
2871  var retVal = "";
2872  if(_recordAlias == _RECORD_TYPE_FE)
2873  retVal = "FESupervisorTable";
2874  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2875  retVal = "DataManagerSupervisorTable";
2876  else
2877  throw("?");
2878 
2879  return retVal;
2880  } //end getAppConfiguration()
2881 
2882  //=====================================================================================
2883  //getRecordConfiguration ~~
2884  function getRecordConfiguration()
2885  {
2886  var retVal = "";
2887  if(_recordAlias == _RECORD_TYPE_FE)
2888  retVal = "FEInterfaceTable";
2889  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2890  retVal = "DataBufferTable";
2891  else
2892  throw("?");
2893 
2894  return retVal;
2895  } //end getRecordConfiguration()
2896 
2897  //=====================================================================================
2898  //getRecordGroupIDField ~~
2899  function getRecordGroupIDField()
2900  {
2901  var retVal = "";
2902  if(_recordAlias == _RECORD_TYPE_FE)
2903  retVal = "FEInterfaceGroupID";
2904  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2905  retVal = "DataBufferGroupID";
2906  else
2907  throw("?");
2908 
2909  return retVal;
2910  } //end getRecordGroupIDField()
2911 
2912 
2913  //=====================================================================================
2914  //getRecordFilter ~~
2915  function getRecordFilter()
2916  {
2917  var retVal = "";
2918  if(_recordAlias == _RECORD_TYPE_FE)
2919  retVal = " ";
2920  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2921  retVal = " ";//"ProcessorType=" + _recordAlias;
2922 
2923  if(retVal == "")
2924  throw("Invalid getRecordFilter");
2925 
2926  return retVal;
2927  } //end getRecordFilter()
2928 
2929 
2930  //=====================================================================================
2931  //getIntermediateTable() ~~
2932  // based on _intermediateLevel and _recordAlias
2933  function getIntermediateTable()
2934  {
2935  var retVal = "";
2936  if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2937  {
2938  if(_intermediateLevel == 0)
2939  retVal = "DataManagerTable";
2940  }
2941 
2942  if(retVal == "")
2943  throw("Invalid getIntermediateTable");
2944 
2945  return retVal;
2946  } //end getIntermediateTable()
2947 
2948  //=====================================================================================
2949  //getIntermediateTypeName() ~~
2950  // based on _intermediateLevel and _recordAlias
2951  function getIntermediateTypeName()
2952  {
2953  var retVal = "";
2954  if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2955  {
2956  if(_intermediateLevel == 0)
2957  retVal = "Buffer";
2958  }
2959 
2960  if(retVal == "")
2961  throw("Invalid getIntermediateTypeName");
2962 
2963  return retVal;
2964  } //end getIntermediateTypeName()
2965 
2966  //=====================================================================================
2967  //getParentTable() ~~
2968  // based on generationsBack and _recordAlias
2969  function getParentTable(generationsBack)
2970  {
2971  if(generationsBack == 0) return getRecordConfiguration();
2972 
2973  var retVal = "";
2974 
2975  if(_recordAlias == _RECORD_TYPE_FE)
2976  {
2977  if(generationsBack == 1)
2978  retVal = "FESupervisorTable";
2979  else if(generationsBack == 2)
2980  retVal = _XDAQAPP_BASE_PATH;
2981  }
2982  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
2983  {
2984  if(generationsBack == 1)
2985  retVal = "DataManagerTable";
2986  else if(generationsBack == 2)
2987  retVal = "DataManagerSupervisorTable";
2988  else if(generationsBack == 3)
2989  retVal = _XDAQAPP_BASE_PATH;
2990  }
2991 
2992  if(retVal == "")
2993  throw("Invalid getParentTable");
2994 
2995  return retVal;
2996  } //end getParentTable()
2997 
2998  //=====================================================================================
2999  //getParentType() ~~
3000  // based on generationsBack and _recordAlias
3001  function getParentType(generationsBack)
3002  {
3003  if(generationsBack == 0) return _recordAlias;
3004 
3005  var retVal = "";
3006 
3007  if(_recordAlias == _RECORD_TYPE_FE)
3008  {
3009  if(generationsBack == 1)
3010  retVal = "FESupervisorTable";
3011  else if(generationsBack == 2)
3012  retVal = "FESupervisor";
3013  }
3014  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
3015  {
3016  if(generationsBack == 1)
3017  retVal = "Buffer";
3018  else if(generationsBack == 2)
3019  retVal = "DataManagerSupervisorTable";
3020  else if(generationsBack == 3)
3021  retVal = "DataManagerSupervisor";
3022  }
3023 
3024  if(retVal == "")
3025  throw("Invalid getParentType");
3026 
3027  return retVal;
3028  } //end getParentType()
3029 
3030  //=====================================================================================
3031  //getParentLinkField() ~~
3032  // based on generationsBack and _recordAlias
3033  function getParentLinkField(generationsBack)
3034  {
3035  var retVal = "";
3036 
3037  if(_recordAlias == _RECORD_TYPE_FE)
3038  {
3039  if(generationsBack == 1)
3040  retVal = "LinkToFEInterfaceTable";
3041  else if(generationsBack == 2)
3042  retVal = "LinkToSupervisorTable";
3043  }
3044  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
3045  {
3046  if(generationsBack == 1)
3047  retVal = "LinkToDataProcessorTable";
3048  else if(generationsBack == 2)
3049  retVal = "LinkToDataBufferTable";
3050  else if(generationsBack == 3)
3051  retVal = "LinkToSupervisorTable";
3052  }
3053 
3054  if(retVal == "")
3055  throw("Invalid getParentLinkField");
3056 
3057  return retVal;
3058  } //end getParentLinkField()
3059 
3060  //=====================================================================================
3061  //getParentFilter() ~~
3062  // based on generationsBack and _recordAlias
3063  function getParentFilter(generationsBack)
3064  {
3065  var retVal = "";
3066 
3067  if(_recordAlias == _RECORD_TYPE_FE)
3068  {
3069  if(generationsBack == 1)
3070  retVal = " ";
3071  else if(generationsBack == 2)
3072  retVal = "Class=ots::FESupervisor";
3073  }
3074  else if(_recordAlias == _RECORD_TYPE_PROCESSOR)
3075  {
3076  if(generationsBack == 1)
3077  retVal = " ";
3078  else if(generationsBack == 2)
3079  retVal = " ";
3080  else if(generationsBack == 3)
3081  retVal = "Class=ots::DataManagerSupervisor,ots::ARTDAQDataManagerSupervisor," +
3082  "ots::VisualSupervisor";
3083  }
3084 
3085  if(retVal == "")
3086  throw("Invalid getParentFilter");
3087 
3088  return retVal;
3089  } //end getParentFilter()
3090 
3091  //=====================================================================================
3092  //htmlOpen ~~
3093  // tab name and attribute/value map object
3094  function htmlOpen(tag,attObj,innerHTML,doCloseTag)
3095  {
3096  var str = "";
3097  var attKeys = Object.keys(attObj);
3098  str += "<" + tag + " ";
3099  for(var i=0;i<attKeys.length;++i)
3100  str += " " + attKeys[i] + "='" +
3101  attObj[attKeys[i]] + "' ";
3102  str += ">";
3103  if(innerHTML) str += innerHTML;
3104  if(doCloseTag)
3105  str += "</" + tag + ">";
3106  return str;
3107  } // end htmlOpen()
3108 
3109  //=====================================================================================
3110  //htmlClearDiv ~~
3111  function htmlClearDiv()
3112  {
3113  return "<div id='clearDiv'></div>";
3114  } //end htmlClearDiv()
3115 
3116 
3117 }; //end RecordWiz.createWiz()
3118 
3119 
3120 
3121 
3122 
3123 
3124 
3125 
3126