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