2989 |
02 Dec 14 |
olle |
var LabSensInf = function() |
2989 |
02 Dec 14 |
olle |
2 |
{ |
2989 |
02 Dec 14 |
olle |
var labsensinf = {}; |
2989 |
02 Dec 14 |
olle |
var debug = 1; |
2989 |
02 Dec 14 |
olle |
5 |
|
2989 |
02 Dec 14 |
olle |
// Page initialization |
2989 |
02 Dec 14 |
olle |
labsensinf.initPage = function() |
2989 |
02 Dec 14 |
olle |
8 |
{ |
4524 |
15 Jun 17 |
nicklas |
labsensinf.getSensorInfo(); |
2989 |
02 Dec 14 |
olle |
10 |
} |
2989 |
02 Dec 14 |
olle |
11 |
|
4524 |
15 Jun 17 |
nicklas |
labsensinf.getSensorInfo = function() |
2989 |
02 Dec 14 |
olle |
13 |
{ |
2989 |
02 Dec 14 |
olle |
var url = '../LabEnvironment.servlet?ID='+App.getSessionId(); |
4524 |
15 Jun 17 |
nicklas |
url += '&cmd=GetSensorInfo'; |
4524 |
15 Jun 17 |
nicklas |
Wizard.showLoadingAnimation('Loading sensor information. Please wait...'); |
4524 |
15 Jun 17 |
nicklas |
Wizard.asyncJsonRequest(url, labsensinf.onSensorInfoLoaded); |
2989 |
02 Dec 14 |
olle |
18 |
} |
4524 |
15 Jun 17 |
nicklas |
19 |
|
4524 |
15 Jun 17 |
nicklas |
labsensinf.onSensorInfoLoaded = function(response) |
2989 |
02 Dec 14 |
olle |
21 |
{ |
4524 |
15 Jun 17 |
nicklas |
var template = Doc.element('row-template'); |
4524 |
15 Jun 17 |
nicklas |
var cols = template.getElementsByTagName('th'); |
4524 |
15 Jun 17 |
nicklas |
var rows = Doc.element('all-rows'); |
4524 |
15 Jun 17 |
nicklas |
25 |
|
4524 |
15 Jun 17 |
nicklas |
var sensors = response.sensors; |
4524 |
15 Jun 17 |
nicklas |
for (var sensorNo = 0; sensorNo < sensors.length; sensorNo++) |
2989 |
02 Dec 14 |
olle |
28 |
{ |
4524 |
15 Jun 17 |
nicklas |
var sensor = sensors[sensorNo]; |
4524 |
15 Jun 17 |
nicklas |
30 |
|
4524 |
15 Jun 17 |
nicklas |
var row = document.createElement('tr'); |
4524 |
15 Jun 17 |
nicklas |
row.className = sensorNo % 2 == 0 ? 'evenrow highlight' : 'oddrow highlight'; |
4524 |
15 Jun 17 |
nicklas |
33 |
|
4524 |
15 Jun 17 |
nicklas |
for (var colNo = 0; colNo < cols.length; colNo++) |
2989 |
02 Dec 14 |
olle |
35 |
{ |
4524 |
15 Jun 17 |
nicklas |
var cell = document.createElement('td'); |
4524 |
15 Jun 17 |
nicklas |
cell.className = 'cell'; |
4524 |
15 Jun 17 |
nicklas |
var colId = cols[colNo].id; |
4524 |
15 Jun 17 |
nicklas |
if (colId == 'sensors.sensorId') |
4524 |
15 Jun 17 |
nicklas |
40 |
{ |
4524 |
15 Jun 17 |
nicklas |
cell.className = 'id-col'; |
4524 |
15 Jun 17 |
nicklas |
cell.innerHTML = sensor.id; |
4524 |
15 Jun 17 |
nicklas |
43 |
} |
4524 |
15 Jun 17 |
nicklas |
else if (colId == 'sensors.sensorName') |
4524 |
15 Jun 17 |
nicklas |
45 |
{ |
4524 |
15 Jun 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(sensor.name); |
4524 |
15 Jun 17 |
nicklas |
47 |
} |
4524 |
15 Jun 17 |
nicklas |
else if (colId == 'sensors.url') |
4524 |
15 Jun 17 |
nicklas |
49 |
{ |
4524 |
15 Jun 17 |
nicklas |
cell.innerHTML = '<a href="'+Strings.encodeTags(sensor.url)+'" target="_blank" rel="noopener noreferrer">'+Strings.encodeTags(sensor.url)+'</a>'; |
4524 |
15 Jun 17 |
nicklas |
51 |
} |
4524 |
15 Jun 17 |
nicklas |
else if (colId == 'sensors.serial') |
4524 |
15 Jun 17 |
nicklas |
53 |
{ |
4524 |
15 Jun 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(sensor.serial); |
4524 |
15 Jun 17 |
nicklas |
55 |
} |
4524 |
15 Jun 17 |
nicklas |
else if (colId == 'sensors.time') |
4524 |
15 Jun 17 |
nicklas |
57 |
{ |
4524 |
15 Jun 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(sensor.time); |
4524 |
15 Jun 17 |
nicklas |
59 |
} |
4524 |
15 Jun 17 |
nicklas |
else if (colId == 'sensors.temperature') |
4524 |
15 Jun 17 |
nicklas |
61 |
{ |
4524 |
15 Jun 17 |
nicklas |
cell.innerHTML = Numbers.formatNumber(sensor.temperature, 1); |
4524 |
15 Jun 17 |
nicklas |
63 |
} |
4524 |
15 Jun 17 |
nicklas |
else if (colId == 'sensors.humidity') |
4524 |
15 Jun 17 |
nicklas |
65 |
{ |
4524 |
15 Jun 17 |
nicklas |
cell.innerHTML = Numbers.formatNumber(sensor.humidity, 1); |
4524 |
15 Jun 17 |
nicklas |
67 |
} |
4534 |
21 Jun 17 |
nicklas |
else if (colId == 'sensors.alarm') |
4534 |
21 Jun 17 |
nicklas |
69 |
{ |
4534 |
21 Jun 17 |
nicklas |
var html = ''; |
4534 |
21 Jun 17 |
nicklas |
if (sensor.alarms && sensor.alarms.length > 0) |
4534 |
21 Jun 17 |
nicklas |
72 |
{ |
4534 |
21 Jun 17 |
nicklas |
html += '<ul>'; |
4534 |
21 Jun 17 |
nicklas |
for (var alarmNo = 0; alarmNo < sensor.alarms.length; alarmNo++) |
4534 |
21 Jun 17 |
nicklas |
75 |
{ |
4534 |
21 Jun 17 |
nicklas |
html += '<li>'+Strings.encodeTags(sensor.alarms[alarmNo]); |
4534 |
21 Jun 17 |
nicklas |
77 |
} |
4534 |
21 Jun 17 |
nicklas |
html += '</ul>'; |
4534 |
21 Jun 17 |
nicklas |
79 |
} |
4534 |
21 Jun 17 |
nicklas |
cell.innerHTML = html; |
4534 |
21 Jun 17 |
nicklas |
81 |
} |
4525 |
15 Jun 17 |
nicklas |
else if (colId == 'sensors.actions') |
4525 |
15 Jun 17 |
nicklas |
83 |
{ |
4525 |
15 Jun 17 |
nicklas |
if (sensor.active) |
4525 |
15 Jun 17 |
nicklas |
85 |
{ |
4525 |
15 Jun 17 |
nicklas |
var html = '<span class="link daily-plot"'; |
4525 |
15 Jun 17 |
nicklas |
html += ' data-sensor-url="'+Strings.encodeTags(sensor.url)+'"'; |
4525 |
15 Jun 17 |
nicklas |
html += ' data-sensor-name="'+Strings.encodeTags(sensor.name)+'"'; |
4526 |
19 Jun 17 |
nicklas |
html += '><img src="../images/chart_curve.png"> Last 24 hours</span>'; |
4525 |
15 Jun 17 |
nicklas |
cell.innerHTML = html; |
4525 |
15 Jun 17 |
nicklas |
91 |
} |
4525 |
15 Jun 17 |
nicklas |
92 |
} |
4524 |
15 Jun 17 |
nicklas |
row.appendChild(cell); |
2989 |
02 Dec 14 |
olle |
94 |
} |
4524 |
15 Jun 17 |
nicklas |
rows.appendChild(row); |
2989 |
02 Dec 14 |
olle |
96 |
} |
2989 |
02 Dec 14 |
olle |
97 |
|
4525 |
15 Jun 17 |
nicklas |
var dailyPlots = document.getElementsByClassName('daily-plot'); |
4525 |
15 Jun 17 |
nicklas |
for (var itemNo = 0; itemNo < dailyPlots.length; itemNo++) |
4525 |
15 Jun 17 |
nicklas |
100 |
{ |
4525 |
15 Jun 17 |
nicklas |
Events.addEventHandler(dailyPlots[itemNo], 'click', labsensinf.dailyPlot); |
4525 |
15 Jun 17 |
nicklas |
102 |
} |
4525 |
15 Jun 17 |
nicklas |
103 |
|
4524 |
15 Jun 17 |
nicklas |
Doc.show('sensors'); |
2989 |
02 Dec 14 |
olle |
105 |
} |
2989 |
02 Dec 14 |
olle |
106 |
|
2989 |
02 Dec 14 |
olle |
107 |
|
4525 |
15 Jun 17 |
nicklas |
labsensinf.dailyPlot = function(event) |
4525 |
15 Jun 17 |
nicklas |
109 |
{ |
4525 |
15 Jun 17 |
nicklas |
110 |
|
4525 |
15 Jun 17 |
nicklas |
var url = 'labenvironmentdatabaseeventpopup.jsp?ID='+App.getSessionId(); |
4526 |
19 Jun 17 |
nicklas |
url += '&plotWidth=480&plotHeight=360&reportType=last24hours'; |
4525 |
15 Jun 17 |
nicklas |
url += '&labSensorUrl='+encodeURIComponent(Data.get(event.currentTarget, "sensor-url")); |
4525 |
15 Jun 17 |
nicklas |
url += '&pageTitle='+encodeURIComponent(Data.get(event.currentTarget, "sensor-name")); |
4525 |
15 Jun 17 |
nicklas |
115 |
|
4525 |
15 Jun 17 |
nicklas |
Dialogs.openPopup(url, 'test', 1000, 500); |
4525 |
15 Jun 17 |
nicklas |
117 |
} |
4525 |
15 Jun 17 |
nicklas |
118 |
|
4525 |
15 Jun 17 |
nicklas |
119 |
|
2989 |
02 Dec 14 |
olle |
return labsensinf; |
2989 |
02 Dec 14 |
olle |
121 |
}(); |
2989 |
02 Dec 14 |
olle |
122 |
|
2989 |
02 Dec 14 |
olle |
Doc.onLoad(LabSensInf.initPage); |