reset button, refined css, loader, improved timeout calculation

This commit is contained in:
2016-04-01 02:06:24 +02:00
parent 2ffaf1a4af
commit 7a6bdef334
28 changed files with 262 additions and 10319 deletions
+6 -1
View File
@@ -616,12 +616,17 @@
// prevent caching
url += (url.indexOf('?') === -1) ? '?' + timestamp : '&' + timestamp;
$('#loader').addClass('show');
// Douglas Crockford: "Synchronous programming is disrespectful and should not be employed in applications which are used by people"
xhr.open(type, url, true);
xhr.timeout = 15000; // a default value. TODO way to set it for the caller
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (callback) {
$('#loader').removeClass('show');
if (callback && xhr.status != 0) { // xhr.status 0 means "aborted"
callback(xhr.responseText, xhr.status);
}
}
+36 -29
View File
@@ -137,22 +137,27 @@ var page_waveform = (function () {
readoutPending = false;
if (status != 200) {
if (status != 0) { // 0 = aborted
alert("Request failed.");
console.error("Request failed.");
if (autoReload)
toggleAutoReload(); // turn it off.
} else {
var j = JSON.parse(resp);
if (!j.success) {
console.error("Sampling / readout failed.");
if (autoReload)
toggleAutoReload(); // turn it off.
return;
}
return;
buildChart(j);
if (autoReload)
arTimeout = setTimeout(requestReload, autoReloadTime);
}
var j = JSON.parse(resp);
if (!j.success) {
alert("Sampling failed.");
return;
}
if (autoReload)
arTimeout = setTimeout(requestReload, autoReloadTime);
buildChart(j);
}
function requestReload() {
@@ -171,6 +176,22 @@ var page_waveform = (function () {
return true;
}
function toggleAutoReload() {
autoReloadTime = +$('#ar-time').val() * 1000; // ms
autoReload = !autoReload;
if (autoReload) {
requestReload();
} else {
clearTimeout(arTimeout);
}
$('#ar-btn')
.toggleClass('btn-blue')
.toggleClass('btn-red')
.val(autoReload ? 'Stop' : 'Auto');
}
wfm.init = function (format) {
// --- Load data ---
dataFormat = format;
@@ -211,21 +232,7 @@ var page_waveform = (function () {
});
// auto-reload button
$('#ar-btn').on('click', function() {
autoReloadTime = +$('#ar-time').val() * 1000; // ms
autoReload = !autoReload;
if (autoReload) {
requestReload();
} else {
clearTimeout(arTimeout);
}
$('#ar-btn')
.toggleClass('btn-blue')
.toggleClass('btn-red')
.val(autoReload ? 'Stop' : 'Auto');
});
$('#ar-btn').on('click', toggleAutoReload);
};
return wfm;