2989 |
02 Dec 14 |
olle |
var LabEnvDbExp = function() |
2989 |
02 Dec 14 |
olle |
2 |
{ |
2989 |
02 Dec 14 |
olle |
var labenvdbexp = {}; |
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 |
labenvdbexp.initPage = function() |
2989 |
02 Dec 14 |
olle |
8 |
{ |
2989 |
02 Dec 14 |
olle |
previewTitle = Doc.element('previewTitle'); |
2989 |
02 Dec 14 |
olle |
previewList = Doc.element('previewList'); |
2989 |
02 Dec 14 |
olle |
11 |
|
2989 |
02 Dec 14 |
olle |
// Step 1 |
2989 |
02 Dec 14 |
olle |
Events.addEventHandler('fromDate', 'blur', labenvdbexp.fromDateTimeOnChange); |
2989 |
02 Dec 14 |
olle |
Events.addEventHandler('fromTime', 'blur', labenvdbexp.fromDateTimeOnChange); |
2989 |
02 Dec 14 |
olle |
Events.addEventHandler('toDate', 'blur', labenvdbexp.toDateTimeOnChange); |
2989 |
02 Dec 14 |
olle |
Events.addEventHandler('toTime', 'blur', labenvdbexp.toDateTimeOnChange); |
2989 |
02 Dec 14 |
olle |
17 |
|
2989 |
02 Dec 14 |
olle |
// Navigation |
2989 |
02 Dec 14 |
olle |
Buttons.addClickHandler('goexport', labenvdbexp.goExport); |
2989 |
02 Dec 14 |
olle |
Buttons.addClickHandler('gopreview', labenvdbexp.goPreview); |
2989 |
02 Dec 14 |
olle |
21 |
|
2989 |
02 Dec 14 |
olle |
// Create lab sensor menu from configuration data |
2989 |
02 Dec 14 |
olle |
labenvdbexp.createSensorMenu(); |
2989 |
02 Dec 14 |
olle |
24 |
|
2989 |
02 Dec 14 |
olle |
Doc.show('step-1'); |
2989 |
02 Dec 14 |
olle |
Doc.show('gopreview'); |
2989 |
02 Dec 14 |
olle |
Doc.show('goexport'); |
2989 |
02 Dec 14 |
olle |
28 |
} |
2989 |
02 Dec 14 |
olle |
29 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.createSensorMenu = function() |
2989 |
02 Dec 14 |
olle |
31 |
{ |
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'; |
2989 |
02 Dec 14 |
olle |
35 |
|
2989 |
02 Dec 14 |
olle |
Wizard.asyncJsonRequest(url, labenvdbexp.createSensorMenu2); |
2989 |
02 Dec 14 |
olle |
37 |
} |
2989 |
02 Dec 14 |
olle |
38 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.createSensorMenu2 = function(response) |
2989 |
02 Dec 14 |
olle |
40 |
{ |
2989 |
02 Dec 14 |
olle |
Doc.show('navigation'); |
2989 |
02 Dec 14 |
olle |
if (response.status != 'ok') |
2989 |
02 Dec 14 |
olle |
43 |
{ |
2989 |
02 Dec 14 |
olle |
setFatalError(response.message); |
2989 |
02 Dec 14 |
olle |
return false; |
2989 |
02 Dec 14 |
olle |
46 |
} |
2989 |
02 Dec 14 |
olle |
// Get sensor configurations information from the AJAX response |
4527 |
20 Jun 17 |
nicklas |
var labSensorConfigList = response.sensors; |
2989 |
02 Dec 14 |
olle |
if (labSensorConfigList != null) |
2989 |
02 Dec 14 |
olle |
50 |
{ |
2989 |
02 Dec 14 |
olle |
// Construct lab sensor menu from JSON data |
2989 |
02 Dec 14 |
olle |
var sensorSelect = document.getElementById('sensorSelectId'); |
2989 |
02 Dec 14 |
olle |
for (var i=0; i < labSensorConfigList.length; i++) |
2989 |
02 Dec 14 |
olle |
54 |
{ |
2989 |
02 Dec 14 |
olle |
// Get URL and name for lab sensor number 'i' |
2989 |
02 Dec 14 |
olle |
var labSensorConfig = labSensorConfigList[i]; |
2989 |
02 Dec 14 |
olle |
var sensorUrl = labSensorConfig['url']; |
2989 |
02 Dec 14 |
olle |
var sensorName = labSensorConfig['name']; |
2989 |
02 Dec 14 |
olle |
// Create and add new option element to select menu |
2989 |
02 Dec 14 |
olle |
var optionEl = document.createElement('option'); |
2989 |
02 Dec 14 |
olle |
optionEl.setAttribute('value',sensorUrl); |
2989 |
02 Dec 14 |
olle |
optionEl.innerHTML = sensorName; |
2989 |
02 Dec 14 |
olle |
sensorSelect.appendChild(optionEl); |
2989 |
02 Dec 14 |
olle |
64 |
} |
2989 |
02 Dec 14 |
olle |
65 |
} |
2989 |
02 Dec 14 |
olle |
66 |
} |
2989 |
02 Dec 14 |
olle |
67 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.goPreview = function() |
2989 |
02 Dec 14 |
olle |
69 |
{ |
2989 |
02 Dec 14 |
olle |
labenvdbexp.doExport(true); |
2989 |
02 Dec 14 |
olle |
71 |
} |
2989 |
02 Dec 14 |
olle |
72 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.goExport = function() |
2989 |
02 Dec 14 |
olle |
74 |
{ |
2989 |
02 Dec 14 |
olle |
labenvdbexp.doExport(false); |
2989 |
02 Dec 14 |
olle |
76 |
} |
2989 |
02 Dec 14 |
olle |
77 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.doExport = function(preview) |
2989 |
02 Dec 14 |
olle |
79 |
{ |
2989 |
02 Dec 14 |
olle |
var frm = document.forms['labenv']; |
2989 |
02 Dec 14 |
olle |
var url = '../LabEnvironment.servlet?ID='+App.getSessionId(); |
2989 |
02 Dec 14 |
olle |
url += '&cmd=LabEnvironmentDatabaseQuery'; |
2989 |
02 Dec 14 |
olle |
if (frm.sensorSelect.value != null) url += '&sensorurl='+frm.sensorSelect.value; |
2989 |
02 Dec 14 |
olle |
var sensorUrlText = frm.sensorSelect[frm.sensorSelect.selectedIndex].text; |
2989 |
02 Dec 14 |
olle |
url += '&sensorname='+sensorUrlText; |
2989 |
02 Dec 14 |
olle |
url += '&fdate='+frm.fromDate.value; |
2989 |
02 Dec 14 |
olle |
url += '&ftime='+frm.fromTime.value; |
2989 |
02 Dec 14 |
olle |
url += '&tdate='+frm.toDate.value; |
2989 |
02 Dec 14 |
olle |
url += '&ttime='+frm.toTime.value; |
2989 |
02 Dec 14 |
olle |
if (frm.displayIndexSelect.value != null) url += '&displayindex='+frm.displayIndexSelect.value; |
2989 |
02 Dec 14 |
olle |
url += '&returntype=export'; |
2989 |
02 Dec 14 |
olle |
if (preview) |
2989 |
02 Dec 14 |
olle |
93 |
{ |
2989 |
02 Dec 14 |
olle |
var previewTitle = document.getElementById('previewTitle'); |
2989 |
02 Dec 14 |
olle |
var previewList = document.getElementById('previewList'); |
2989 |
02 Dec 14 |
olle |
96 |
|
2989 |
02 Dec 14 |
olle |
Doc.hide('previewWrapper'); |
2989 |
02 Dec 14 |
olle |
previewTitle.innerHTML = 'Working...'; |
2989 |
02 Dec 14 |
olle |
previewList.innerHTML = ''; |
2989 |
02 Dec 14 |
olle |
100 |
|
2989 |
02 Dec 14 |
olle |
url += '&preview=1'; |
2989 |
02 Dec 14 |
olle |
102 |
|
2989 |
02 Dec 14 |
olle |
Wizard.showLoadingAnimation('Working...'); |
2989 |
02 Dec 14 |
olle |
Doc.hide('navigation'); |
2989 |
02 Dec 14 |
olle |
Wizard.asyncJsonRequest(url, labenvdbexp.onPreviewLoaded); |
2989 |
02 Dec 14 |
olle |
106 |
} |
2989 |
02 Dec 14 |
olle |
else |
2989 |
02 Dec 14 |
olle |
108 |
{ |
2989 |
02 Dec 14 |
olle |
window.location = url; |
2989 |
02 Dec 14 |
olle |
110 |
} |
2989 |
02 Dec 14 |
olle |
111 |
} |
2989 |
02 Dec 14 |
olle |
112 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.onPreviewLoaded = function(response) |
2989 |
02 Dec 14 |
olle |
114 |
{ |
2989 |
02 Dec 14 |
olle |
Doc.show('navigation'); |
2989 |
02 Dec 14 |
olle |
var frm = document.forms['labenv']; |
2989 |
02 Dec 14 |
olle |
var allLines = response.split('\n'); |
2989 |
02 Dec 14 |
olle |
var numLines = allLines.length - 2; // First line is a header line |
2989 |
02 Dec 14 |
olle |
119 |
|
2989 |
02 Dec 14 |
olle |
var html = '<tr><th>'+allLines[0].replace(/\t/g, '</th><th>')+'</th></tr>'; |
2989 |
02 Dec 14 |
olle |
for (var i = 1 ; i <= numLines; i++) |
2989 |
02 Dec 14 |
olle |
122 |
{ |
2989 |
02 Dec 14 |
olle |
var line = allLines[i]; |
2989 |
02 Dec 14 |
olle |
var cols = line.split(/\t/); |
2989 |
02 Dec 14 |
olle |
var rowClass = ''; |
2989 |
02 Dec 14 |
olle |
html += '<tr class="'+rowClass+'"><td>'+cols.join('</td><td>')+'</td></tr>'; |
2989 |
02 Dec 14 |
olle |
127 |
} |
2989 |
02 Dec 14 |
olle |
128 |
|
2989 |
02 Dec 14 |
olle |
var sensorUrlText = frm.sensorSelect[frm.sensorSelect.selectedIndex].text; |
2989 |
02 Dec 14 |
olle |
previewTitle.innerHTML = 'Sensor - ' + sensorUrlText; |
2989 |
02 Dec 14 |
olle |
previewList.innerHTML = '<table>'+html+'</table>'; |
2989 |
02 Dec 14 |
olle |
Doc.show('previewWrapper'); |
2989 |
02 Dec 14 |
olle |
133 |
} |
2989 |
02 Dec 14 |
olle |
134 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.addEventHandlers = function(elements, eventName, handler) |
2989 |
02 Dec 14 |
olle |
136 |
{ |
2989 |
02 Dec 14 |
olle |
for (var i = 0; i < elements.length; i++) |
2989 |
02 Dec 14 |
olle |
138 |
{ |
2989 |
02 Dec 14 |
olle |
Events.addEventHandler(elements[i], eventName, handler); |
2989 |
02 Dec 14 |
olle |
140 |
} |
2989 |
02 Dec 14 |
olle |
141 |
} |
2989 |
02 Dec 14 |
olle |
142 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.fromDateTimeOnChange = function() |
2989 |
02 Dec 14 |
olle |
144 |
{ |
2989 |
02 Dec 14 |
olle |
var frm = document.forms['labenv']; |
2989 |
02 Dec 14 |
olle |
var todaysDate = new Date(); |
2989 |
02 Dec 14 |
olle |
fromDateIsValid = false; |
2989 |
02 Dec 14 |
olle |
setInputStatus('fromDate', '', ''); |
2989 |
02 Dec 14 |
olle |
149 |
|
2989 |
02 Dec 14 |
olle |
var fromDate = frm.fromDate.value; |
2989 |
02 Dec 14 |
olle |
var fromTime = frm.fromTime.value; |
2989 |
02 Dec 14 |
olle |
152 |
|
2989 |
02 Dec 14 |
olle |
if (fromDate != '' || fromTime != '') |
2989 |
02 Dec 14 |
olle |
154 |
{ |
2989 |
02 Dec 14 |
olle |
// Auto-fill the date if it's only given with 4(MMdd) or 6(yyMMdd) digits. |
2989 |
02 Dec 14 |
olle |
fromDate = autoFillDate(fromDate); |
2989 |
02 Dec 14 |
olle |
frm.fromDate.value = fromDate; |
2989 |
02 Dec 14 |
olle |
158 |
|
2989 |
02 Dec 14 |
olle |
fromTime = autoFillTime(fromTime); |
2989 |
02 Dec 14 |
olle |
frm.fromTime.value = fromTime; |
2989 |
02 Dec 14 |
olle |
161 |
|
2989 |
02 Dec 14 |
olle |
if (!Dates.isDate(fromDate, 'yyyyMMdd')) |
2989 |
02 Dec 14 |
olle |
163 |
{ |
2989 |
02 Dec 14 |
olle |
setInputStatus('fromDate', 'Not a valid date', 'invalid'); |
2989 |
02 Dec 14 |
olle |
return; |
2989 |
02 Dec 14 |
olle |
166 |
} |
2989 |
02 Dec 14 |
olle |
167 |
|
2989 |
02 Dec 14 |
olle |
if (!Dates.isDate(fromDate + ' ' + fromTime, 'yyyyMMdd HHmm')) |
2989 |
02 Dec 14 |
olle |
169 |
{ |
2989 |
02 Dec 14 |
olle |
if (fromDate != '') setInputStatus('fromDate', 'Not a valid time (if time unknown, also leave date field blank)', 'invalid'); |
2989 |
02 Dec 14 |
olle |
return; |
2989 |
02 Dec 14 |
olle |
172 |
} |
2989 |
02 Dec 14 |
olle |
setInputStatus('fromDate', '', 'valid'); |
2989 |
02 Dec 14 |
olle |
174 |
} |
2989 |
02 Dec 14 |
olle |
fromDateIsValid = true; |
2989 |
02 Dec 14 |
olle |
toDateTimeOnChange(); |
2989 |
02 Dec 14 |
olle |
177 |
} |
2989 |
02 Dec 14 |
olle |
178 |
|
2989 |
02 Dec 14 |
olle |
labenvdbexp.toDateTimeOnChange = function() |
2989 |
02 Dec 14 |
olle |
180 |
{ |
2989 |
02 Dec 14 |
olle |
var frm = document.forms['labenv']; |
2989 |
02 Dec 14 |
olle |
var todaysDate = new Date(); |
2989 |
02 Dec 14 |
olle |
toDateIsValid = false; |
2989 |
02 Dec 14 |
olle |
setInputStatus('toDate', '', ''); |
2989 |
02 Dec 14 |
olle |
185 |
|
2989 |
02 Dec 14 |
olle |
var toDate = frm.toDate.value; |
2989 |
02 Dec 14 |
olle |
var toTime = frm.toTime.value; |
2989 |
02 Dec 14 |
olle |
188 |
|
2989 |
02 Dec 14 |
olle |
if (toDate != '' || toTime != '') |
2989 |
02 Dec 14 |
olle |
190 |
{ |
2989 |
02 Dec 14 |
olle |
// Auto-fill the date if it's only given with 4(MMdd) or 6(yyMMdd) digits. |
2989 |
02 Dec 14 |
olle |
toDate = autoFillDate(toDate); |
2989 |
02 Dec 14 |
olle |
frm.toDate.value = toDate; |
2989 |
02 Dec 14 |
olle |
194 |
|
2989 |
02 Dec 14 |
olle |
toTime = autoFillTime(toTime); |
2989 |
02 Dec 14 |
olle |
frm.toTime.value = toTime; |
2989 |
02 Dec 14 |
olle |
197 |
|
2989 |
02 Dec 14 |
olle |
if (!Dates.isDate(toDate, 'yyyyMMdd')) |
2989 |
02 Dec 14 |
olle |
199 |
{ |
2989 |
02 Dec 14 |
olle |
setInputStatus('toDate', 'Not a valid date', 'invalid'); |
2989 |
02 Dec 14 |
olle |
return; |
2989 |
02 Dec 14 |
olle |
202 |
} |
2989 |
02 Dec 14 |
olle |
203 |
|
2989 |
02 Dec 14 |
olle |
if (!Dates.isDate(toDate + ' ' + toTime, 'yyyyMMdd HHmm')) |
2989 |
02 Dec 14 |
olle |
205 |
{ |
2989 |
02 Dec 14 |
olle |
if (toDate != '') setInputStatus('toDate', 'Not a valid time (if time unknown, also leave date field blank)', 'invalid'); |
2989 |
02 Dec 14 |
olle |
return; |
2989 |
02 Dec 14 |
olle |
208 |
} |
2989 |
02 Dec 14 |
olle |
setInputStatus('toDate', '', 'valid'); |
2989 |
02 Dec 14 |
olle |
210 |
} |
2989 |
02 Dec 14 |
olle |
toDateIsValid = true; |
2989 |
02 Dec 14 |
olle |
212 |
} |
2989 |
02 Dec 14 |
olle |
213 |
|
2989 |
02 Dec 14 |
olle |
return labenvdbexp; |
2989 |
02 Dec 14 |
olle |
215 |
}(); |
2989 |
02 Dec 14 |
olle |
216 |
|
2989 |
02 Dec 14 |
olle |
Doc.onLoad(LabEnvDbExp.initPage); |