otsdaq_utilities  v2_05_02_indev
WidgetLibrary.js
1 
2 var test_numSet_ = [1, 34, 500, 432, 098, 124, 234, 3464, 12];
3 var barValue_;
4 var updateTimeout_;
5 var test_numSetIndex = 0;
6 var switchValue_;
7 
8 var pvNames_ = new Array(2);
9 
10 function init()
11 {
12  console.log("init called");
13  switchValue_ = false;
14  barValue_ = 0;
15  drawSwitch();
16  drawBar();
17  window.parent.setupWidget(window.frameElement.id);
18 
19  //window.setInterval(updateSwitch, 1000);
20 
21  //barValue_ = 0;
22  //updateTimeout_ = window.setInterval(updateBar, 20);
23 
24  //updateTimeout_ = window.setInterval(updateBar2, 1000)
25 }
26 
27 function newWidget(widget)
28 {
29  console.log(widget);
30  for(var pvi=0;pvi< Object.keys(widget.PVList).length && pvi< 2;++pvi)
31  {
32  console.log(pvi);
33 
34  pvNames_[pvi] = Object.keys(widget.PVList)[pvi];
35 
36  }
37 
38 }
39 
40 function setupPVs(settings)
41 {
42  console.log("setupPVs() : " + settings);
43 }
44 
45 function newValue(pvName, pvValue, pvTime, pvStatus, pvSeverity)
46 {
47  var pvi = 0;
48  for(;pvi<pvNames_.length;++pvi)
49  {
50  if(pvNames_[pvi] == pvName)
51  break;
52  }
53 
54  if(pvi == pvNames_.length)
55  {
56  console.log("Invalid new value for PV name:" + pvName);
57  return;
58  }
59 
60  //console.log("Found valid value for PV:" + pvName + " pvi: " + pvi + " value: " + pvValue);
61 
62  if(pvi == 0) //use as switch
63  {
64  switchValue_ = ((pvValue>>1)|0)%2;
65  drawSwitch();
66  }
67  else if(pvi == 1) //use as bar
68  {
69  barValue_ = (pvValue|0)%100;
70  drawBar();
71  }
72 
73 }
74 
75 
76 
77 function updateSwitch()
78 {
79  switchValue_ = !switchValue_;
80  drawSwitch();
81 }
82 
83 function drawSwitch()
84 {
85  //console.log("switchValue called " + switchValue_);
86  var elem = document.getElementById("switch_rounded");
87  if (switchValue_)
88  {
89 
90  elem.checked = true;
91 
92  }
93  else
94  {
95  elem.checked = false;
96  }
97 }
98 
99 function updateBar()
100 {
101  console.log("updateBar called " + barValue_);
102  drawBar();
103  if (barValue_ == 100)
104  {
105  window.clearInterval(updateTimeout_);
106  return;
107  }
108  ++barValue_;
109 }
110 
111 function updateBar2() {
112  //console.log("updateBar called " + barValue_);
113  barValue_ = test_numSet_[test_numSetIndex];
114  test_numSetIndex++;
115  drawBar();
116  if (test_numSetIndex == test_numSet_.length) {
117  // window.clearInterval(updateTimeout_);
118  test_numSetIndex = 0;
119  return;
120  }
121 
122 }
123 
124 function drawBar()
125 {
126  //console.log("drawBar() called " + barValue_);
127  var elem = document.getElementById("weather_bar");
128  var elem2 = document.getElementById("weatherBar_bg");
129  var width = 100 - barValue_;
130 
131 
132  if(barValue_ < 0 || barValue_ > 100)
133  {
134  // console.log("illegal value");
135  elem.innerHTML = 'Illegal';
136  elem.style.width = 100 + "%";
137  elem.style.left = 0 + "%";
138  elem.style.backgroundColor = "red";
139  }
140  else
141  {
142  elem.style.width = width + '%';
143  elem.style.left = barValue_ + '%';
144  elem2.innerHTML = barValue_ + '%';
145  elem.innerHTML = "";
146  elem.style.backgroundColor = "white";
147 
148  }
149 }