otsdaq_utilities  v2_05_02_indev
otsdaq_doc_library.js
1 // ==============================
2 //
3 // Note: this code is the main javascript library for the otsdaq online documentation
4 //
5 // created by rrivera at fnal dot gov, May 2019
6 // ==============================
7 
8 
9 var ots = ots || {}; //define ots namespace
10 
11 ots.otsdaqFeatures_ = {};
12 
13 ots.initFeatures = function()
14 {
15  console.log("ots.initFeatures()");
16 
17  ots.HttpRequest("../contentData/otsdaq_features.json","",
18  function(req)
19  {
20  console.log("Request text",req.responseText);
21  ots.otsdaqFeatures_ = JSON.parse(req.responseText);
22  console.log("json features",ots.otsdaqFeatures_);
23 
24  //jumpe to anchor in url.. now that it is not iframe
25  var anchori = window.location.href.indexOf('#');
26  if(anchori > 0)
27  location.href = window.location.href.substr(anchori);
28 
29  });
30 }
31 
32 window.addEventListener("load",ots.initFeatures);
33 
34 
35 
36 //=====================================================================================
37 //ots.HttpRequest ~~
38 // forms request properly for ots server, POSTs data
39 // and when request is returned, returnHandler is called with
40 // req result on success, if failure do to bad url called with 0
41 //
42 // reqIndex is used to give the returnHandler an index to route responses to.
43 //
44 ots.HttpRequest = function(requestURL, data, returnHandler, reqIndex) {
45 
46  var errStr = "";
47  var req = new XMLHttpRequest();
48 
49  req.onreadystatechange = function() {
50  if (req.readyState==4) { //when readyState=4 return complete, status=200 for success, status=400 for fail
51  if(req.status==200)
52  {
53  //response received
54  console.log("Request Response Text " + req.responseText);
55  }
56  else
57  {
58  //response failure
59 
60  console.log("Request Failed!");
61  }
62 
63  if(returnHandler) returnHandler(req,reqIndex,errStr);
64  }
65  }
66 
67  //requestURL = "/urn:xdaq-application:lid="+urnLid+"/"+requestURL;
68  //Debug.log("Post " + requestURL + "\n\tData: " + data);
69  req.open("POST",requestURL,true);
70  //req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
71  req.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
72  req.send(data);
73 } //end ots.HttpRequest()