1 // ==============================
3 // Note: this code is the main javascript library for the otsdaq online documentation
5 // created by rrivera at fnal dot gov, May 2019
6 // ==============================
9 var ots = ots || {}; //define ots namespace
11 ots.otsdaqFeatures_ = {};
13 ots.initFeatures = function()
15 console.log("ots.initFeatures()");
17 ots.HttpRequest("../contentData/otsdaq_features.json","",
20 console.log("Request text",req.responseText);
21 ots.otsdaqFeatures_ = JSON.parse(req.responseText);
22 console.log("json features",ots.otsdaqFeatures_);
24 //jumpe to anchor in url.. now that it is not iframe
25 var anchori = window.location.href.indexOf('#');
27 location.href = window.location.href.substr(anchori);
32 window.addEventListener("load",ots.initFeatures);
36 //=====================================================================================
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
42 // reqIndex is used to give the returnHandler an index to route responses to.
44 ots.HttpRequest = function(requestURL, data, returnHandler, reqIndex) {
47 var req = new XMLHttpRequest();
49 req.onreadystatechange = function() {
50 if (req.readyState==4) { //when readyState=4 return complete, status=200 for success, status=400 for fail
54 console.log("Request Response Text " + req.responseText);
60 console.log("Request Failed!");
63 if(returnHandler) returnHandler(req,reqIndex,errStr);
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");
73 } //end ots.HttpRequest()