00001
00002 var test_numSet_ = [1, 34, 500, 432, 098, 124, 234, 3464, 12];
00003 var barValue_;
00004 var updateTimeout_;
00005 var test_numSetIndex = 0;
00006 var switchValue_;
00007
00008 var pvNames_ = new Array(2);
00009
00010 function init()
00011 {
00012 console.log("init called");
00013 switchValue_ = false;
00014 barValue_ = 0;
00015 drawSwitch();
00016 drawBar();
00017 window.parent.setupWidget(window.frameElement.id);
00018
00019
00020
00021
00022
00023
00024
00025 }
00026
00027 function newWidget(widget)
00028 {
00029 console.log(widget);
00030 for(var pvi=0;pvi< Object.keys(widget.PVList).length && pvi< 2;++pvi)
00031 {
00032 console.log(pvi);
00033
00034 pvNames_[pvi] = Object.keys(widget.PVList)[pvi];
00035
00036 }
00037
00038 }
00039
00040 function setupPVs(settings)
00041 {
00042 console.log("setupPVs() : " + settings);
00043 }
00044
00045 function newValue(pvName, pvValue, pvTime, pvStatus, pvSeverity)
00046 {
00047 var pvi = 0;
00048 for(;pvi<pvNames_.length;++pvi)
00049 {
00050 if(pvNames_[pvi] == pvName)
00051 break;
00052 }
00053
00054 if(pvi == pvNames_.length)
00055 {
00056 console.log("Invalid new value for PV name:" + pvName);
00057 return;
00058 }
00059
00060
00061
00062 if(pvi == 0)
00063 {
00064 switchValue_ = ((pvValue>>1)|0)%2;
00065 drawSwitch();
00066 }
00067 else if(pvi == 1)
00068 {
00069 barValue_ = (pvValue|0)%100;
00070 drawBar();
00071 }
00072
00073 }
00074
00075
00076
00077 function updateSwitch()
00078 {
00079 switchValue_ = !switchValue_;
00080 drawSwitch();
00081 }
00082
00083 function drawSwitch()
00084 {
00085
00086 var elem = document.getElementById("switch_rounded");
00087 if (switchValue_)
00088 {
00089
00090 elem.checked = true;
00091
00092 }
00093 else
00094 {
00095 elem.checked = false;
00096 }
00097 }
00098
00099 function updateBar()
00100 {
00101 console.log("updateBar called " + barValue_);
00102 drawBar();
00103 if (barValue_ == 100)
00104 {
00105 window.clearInterval(updateTimeout_);
00106 return;
00107 }
00108 ++barValue_;
00109 }
00110
00111 function updateBar2() {
00112
00113 barValue_ = test_numSet_[test_numSetIndex];
00114 test_numSetIndex++;
00115 drawBar();
00116 if (test_numSetIndex == test_numSet_.length) {
00117
00118 test_numSetIndex = 0;
00119 return;
00120 }
00121
00122 }
00123
00124 function drawBar()
00125 {
00126
00127 var elem = document.getElementById("weather_bar");
00128 var elem2 = document.getElementById("weatherBar_bg");
00129 var width = 100 - barValue_;
00130
00131
00132 if(barValue_ < 0 || barValue_ > 100)
00133 {
00134
00135 elem.innerHTML = 'Illegal';
00136 elem.style.width = 100 + "%";
00137 elem.style.left = 0 + "%";
00138 elem.style.backgroundColor = "red";
00139 }
00140 else
00141 {
00142 elem.style.width = width + '%';
00143 elem.style.left = barValue_ + '%';
00144 elem2.innerHTML = barValue_ + '%';
00145 elem.innerHTML = "";
00146 elem.style.backgroundColor = "white";
00147
00148 }
00149 }