2989 |
02 Dec 14 |
olle |
var LabEnvAlarm = function() |
2989 |
02 Dec 14 |
olle |
2 |
{ |
2989 |
02 Dec 14 |
olle |
var labenvalarm = {}; |
2989 |
02 Dec 14 |
olle |
var debug = 1; |
4527 |
20 Jun 17 |
nicklas |
var sensors; |
2989 |
02 Dec 14 |
olle |
6 |
|
2989 |
02 Dec 14 |
olle |
// Page initialization |
2989 |
02 Dec 14 |
olle |
labenvalarm.initPage = function() |
2989 |
02 Dec 14 |
olle |
9 |
{ |
4527 |
20 Jun 17 |
nicklas |
// Navigation |
4527 |
20 Jun 17 |
nicklas |
Buttons.addClickHandler('gosetalarmblocker', Wizard.goRegister); |
4527 |
20 Jun 17 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
2989 |
02 Dec 14 |
olle |
13 |
|
4527 |
20 Jun 17 |
nicklas |
// Final registration |
4527 |
20 Jun 17 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', labenvalarm.submit); |
2989 |
02 Dec 14 |
olle |
16 |
|
2989 |
02 Dec 14 |
olle |
// Create lab environment alarms web page from configuration data |
4527 |
20 Jun 17 |
nicklas |
labenvalarm.getAlarmInfo(); |
2989 |
02 Dec 14 |
olle |
19 |
} |
2989 |
02 Dec 14 |
olle |
20 |
|
4527 |
20 Jun 17 |
nicklas |
labenvalarm.getAlarmInfo = function() |
2989 |
02 Dec 14 |
olle |
22 |
{ |
2989 |
02 Dec 14 |
olle |
// Get lab sensor configurations JSON object with Ajax |
2989 |
02 Dec 14 |
olle |
var url = '../LabEnvironment.servlet?ID='+App.getSessionId(); |
2989 |
02 Dec 14 |
olle |
url += '&cmd=GetLabSensorConfigList'; |
4527 |
20 Jun 17 |
nicklas |
Wizard.showLoadingAnimation('Loading sensor information. Please wait...'); |
4527 |
20 Jun 17 |
nicklas |
Wizard.asyncJsonRequest(url, labenvalarm.onAlarmInfoLoaded); |
2989 |
02 Dec 14 |
olle |
28 |
} |
2989 |
02 Dec 14 |
olle |
29 |
|
4527 |
20 Jun 17 |
nicklas |
labenvalarm.onAlarmInfoLoaded = function(response) |
2989 |
02 Dec 14 |
olle |
31 |
{ |
4527 |
20 Jun 17 |
nicklas |
var template = Doc.element('row-template'); |
4527 |
20 Jun 17 |
nicklas |
var cols = template.getElementsByTagName('th'); |
4527 |
20 Jun 17 |
nicklas |
var rows = Doc.element('all-rows'); |
4527 |
20 Jun 17 |
nicklas |
35 |
|
2989 |
02 Dec 14 |
olle |
// Get sensor configurations information from the Ajax response |
4527 |
20 Jun 17 |
nicklas |
sensors = response.sensors; |
4527 |
20 Jun 17 |
nicklas |
var hasAlarmPermission = false; |
4527 |
20 Jun 17 |
nicklas |
for (var sensorNo = 0; sensorNo < sensors.length; sensorNo++) |
2989 |
02 Dec 14 |
olle |
40 |
{ |
4527 |
20 Jun 17 |
nicklas |
var sensor = sensors[sensorNo]; |
4527 |
20 Jun 17 |
nicklas |
42 |
|
4527 |
20 Jun 17 |
nicklas |
var alarms = sensor.alarms; |
4527 |
20 Jun 17 |
nicklas |
for (var alarmNo = 0; alarmNo < alarms.length; alarmNo++) |
2989 |
02 Dec 14 |
olle |
45 |
{ |
4527 |
20 Jun 17 |
nicklas |
var alarm = alarms[alarmNo]; |
4527 |
20 Jun 17 |
nicklas |
47 |
|
4527 |
20 Jun 17 |
nicklas |
var row = document.createElement('tr'); |
4527 |
20 Jun 17 |
nicklas |
row.className = sensorNo % 2 == 0 ? 'evenrow highlight' : 'oddrow highlight'; |
4527 |
20 Jun 17 |
nicklas |
50 |
|
4527 |
20 Jun 17 |
nicklas |
for (var colNo = 0; colNo < cols.length; colNo++) |
2989 |
02 Dec 14 |
olle |
52 |
{ |
4527 |
20 Jun 17 |
nicklas |
var cell = document.createElement('td'); |
4527 |
20 Jun 17 |
nicklas |
cell.className = 'cell'; |
4527 |
20 Jun 17 |
nicklas |
var colId = cols[colNo].id; |
4527 |
20 Jun 17 |
nicklas |
if (colId == 'alarms.alarmId') |
2989 |
02 Dec 14 |
olle |
57 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.className = 'id-col'; |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = alarm.no; |
4527 |
20 Jun 17 |
nicklas |
60 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.sensorName') |
4527 |
20 Jun 17 |
nicklas |
62 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(sensor.name); |
4527 |
20 Jun 17 |
nicklas |
64 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.url') |
4527 |
20 Jun 17 |
nicklas |
66 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = '<a href="'+Strings.encodeTags(sensor.url)+'" target="_blank" rel="noopener noreferrer">'+Strings.encodeTags(sensor.url)+'</a>'; |
4527 |
20 Jun 17 |
nicklas |
68 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.startTime') |
4527 |
20 Jun 17 |
nicklas |
70 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(alarm.startTime); |
4527 |
20 Jun 17 |
nicklas |
72 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.endTime') |
4527 |
20 Jun 17 |
nicklas |
74 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(alarm.endTime); |
4527 |
20 Jun 17 |
nicklas |
76 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.weekdayFilter') |
4527 |
20 Jun 17 |
nicklas |
78 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(alarm.weekdayFilter); |
4527 |
20 Jun 17 |
nicklas |
80 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.minTemp') |
4527 |
20 Jun 17 |
nicklas |
82 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Numbers.formatNumber(alarm.temperatureMin, 1); |
4527 |
20 Jun 17 |
nicklas |
84 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.maxTemp') |
4527 |
20 Jun 17 |
nicklas |
86 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Numbers.formatNumber(alarm.temperatureMax, 1); |
4527 |
20 Jun 17 |
nicklas |
88 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.minHumidity') |
4527 |
20 Jun 17 |
nicklas |
90 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Numbers.formatNumber(alarm.humidityMin, 1); |
4527 |
20 Jun 17 |
nicklas |
92 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.maxHumidity') |
4527 |
20 Jun 17 |
nicklas |
94 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Numbers.formatNumber(alarm.humidityMax, 1); |
4527 |
20 Jun 17 |
nicklas |
96 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.blocked') |
4527 |
20 Jun 17 |
nicklas |
98 |
{ |
4527 |
20 Jun 17 |
nicklas |
if (alarm.alarmPermission) |
2989 |
02 Dec 14 |
olle |
100 |
{ |
4527 |
20 Jun 17 |
nicklas |
hasAlarmPermission = true; |
4527 |
20 Jun 17 |
nicklas |
var html = '<select name="alarmBlocked.'+alarm.no+'">'; |
4527 |
20 Jun 17 |
nicklas |
html += '<option value="1"' + (alarm.blocked ? 'selected' :'') + '>Yes'; |
4527 |
20 Jun 17 |
nicklas |
html += '<option value="0"' + (alarm.blocked ? '' : 'selected') + '>No'; |
4527 |
20 Jun 17 |
nicklas |
html += '</select>'; |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = html; |
2989 |
02 Dec 14 |
olle |
107 |
} |
4527 |
20 Jun 17 |
nicklas |
else |
2989 |
02 Dec 14 |
olle |
109 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = alarm.blocked ? 'Yes' : 'No'; |
2989 |
02 Dec 14 |
olle |
111 |
} |
2989 |
02 Dec 14 |
olle |
112 |
} |
4527 |
20 Jun 17 |
nicklas |
else if (colId == 'alarms.alarmText') |
4527 |
20 Jun 17 |
nicklas |
114 |
{ |
4527 |
20 Jun 17 |
nicklas |
cell.innerHTML = Strings.encodeTags(alarm.alarmText); |
4527 |
20 Jun 17 |
nicklas |
116 |
} |
4527 |
20 Jun 17 |
nicklas |
row.appendChild(cell); |
2989 |
02 Dec 14 |
olle |
118 |
} |
4527 |
20 Jun 17 |
nicklas |
rows.appendChild(row); |
4527 |
20 Jun 17 |
nicklas |
120 |
|
2989 |
02 Dec 14 |
olle |
121 |
} |
2989 |
02 Dec 14 |
olle |
122 |
} |
4527 |
20 Jun 17 |
nicklas |
123 |
|
4527 |
20 Jun 17 |
nicklas |
Doc.show('alarms'); |
4527 |
20 Jun 17 |
nicklas |
if (hasAlarmPermission) |
2989 |
02 Dec 14 |
olle |
126 |
{ |
4527 |
20 Jun 17 |
nicklas |
Doc.show("gosetalarmblocker"); |
2989 |
02 Dec 14 |
olle |
128 |
} |
2989 |
02 Dec 14 |
olle |
129 |
} |
2989 |
02 Dec 14 |
olle |
130 |
|
4527 |
20 Jun 17 |
nicklas |
labenvalarm.submit = function() |
2989 |
02 Dec 14 |
olle |
132 |
{ |
4527 |
20 Jun 17 |
nicklas |
var submitInfo = {}; |
4527 |
20 Jun 17 |
nicklas |
var frm = document.forms['alarms']; |
4527 |
20 Jun 17 |
nicklas |
135 |
|
2989 |
02 Dec 14 |
olle |
// Get sensor configurations information from the Ajax response |
4527 |
20 Jun 17 |
nicklas |
for (var sensorNo = 0; sensorNo < sensors.length; sensorNo++) |
2989 |
02 Dec 14 |
olle |
138 |
{ |
4527 |
20 Jun 17 |
nicklas |
var sensor = sensors[sensorNo]; |
4527 |
20 Jun 17 |
nicklas |
140 |
|
4527 |
20 Jun 17 |
nicklas |
var alarms = sensor.alarms; |
4527 |
20 Jun 17 |
nicklas |
for (var alarmNo = 0; alarmNo < alarms.length; alarmNo++) |
2989 |
02 Dec 14 |
olle |
143 |
{ |
4527 |
20 Jun 17 |
nicklas |
var alarm = alarms[alarmNo]; |
4527 |
20 Jun 17 |
nicklas |
frm['alarmBlocked.'+alarm.no].value; |
4527 |
20 Jun 17 |
nicklas |
var tmp = {}; |
4527 |
20 Jun 17 |
nicklas |
tmp.blocked = parseInt(frm['alarmBlocked.'+alarm.no].value) ? true : false; |
4527 |
20 Jun 17 |
nicklas |
submitInfo['alarm.'+alarm.no] = tmp; |
2989 |
02 Dec 14 |
olle |
149 |
} |
2989 |
02 Dec 14 |
olle |
150 |
} |
2989 |
02 Dec 14 |
olle |
151 |
|
4527 |
20 Jun 17 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
4527 |
20 Jun 17 |
nicklas |
var url = '../LabEnvironment.servlet?ID='+App.getSessionId(); |
4527 |
20 Jun 17 |
nicklas |
url += '&cmd=SetLabEnvAlarmConfig'; |
4527 |
20 Jun 17 |
nicklas |
Wizard.showLoadingAnimation('Updating alarm status. Please wait...'); |
4527 |
20 Jun 17 |
nicklas |
Wizard.asyncJsonRequest(url, labenvalarm.submissionResults, 'POST', JSON.stringify(submitInfo)); |
2989 |
02 Dec 14 |
olle |
157 |
} |
2989 |
02 Dec 14 |
olle |
158 |
|
4527 |
20 Jun 17 |
nicklas |
labenvalarm.submissionResults = function(response) |
2989 |
02 Dec 14 |
olle |
160 |
{ |
4527 |
20 Jun 17 |
nicklas |
Wizard.showFinalMessage(response.messages); |
4527 |
20 Jun 17 |
nicklas |
Doc.show('gorestart'); |
2989 |
02 Dec 14 |
olle |
163 |
} |
2989 |
02 Dec 14 |
olle |
164 |
|
2989 |
02 Dec 14 |
olle |
return labenvalarm; |
2989 |
02 Dec 14 |
olle |
166 |
}(); |
2989 |
02 Dec 14 |
olle |
167 |
|
2989 |
02 Dec 14 |
olle |
Doc.onLoad(LabEnvAlarm.initPage); |