Browse Source

Further refactor in custom.js

softuart
Xose Pérez 6 years ago
parent
commit
d0d03a7212
3 changed files with 690 additions and 691 deletions
  1. BIN
      code/espurna/data/index.html.gz
  2. +662
    -662
      code/espurna/static/index.html.gz.h
  3. +28
    -29
      code/html/custom.js

BIN
code/espurna/data/index.html.gz View File


+ 662
- 662
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 28
- 29
code/html/custom.js View File

@ -150,20 +150,15 @@ function validateForm(form) {
function getValue(element) { function getValue(element) {
var value;
if ($(element).attr("type") === "checkbox") { if ($(element).attr("type") === "checkbox") {
value = $(element).is(":checked") ? 1 : 0;
return $(element).is(":checked") ? 1 : 0;
} else if ($(element).attr("type") === "radio") { } else if ($(element).attr("type") === "radio") {
if (!$(element).is(":checked")) { if (!$(element).is(":checked")) {
return;
return null;
} }
value = $(element).val();
} else {
value = $(element).val();
} }
return value;
return $(element).val();
} }
@ -202,7 +197,9 @@ function getData(form) {
$("input,select", form).each(function() { $("input,select", form).each(function() {
var name = $(this).attr("name"); var name = $(this).attr("name");
var value = getValue(this); var value = getValue(this);
addValue(data, name, value);
if (null !== value) {
addValue(data, name, value);
}
}); });
// Post process // Post process
@ -376,7 +373,6 @@ function doAction(question, action) {
checkChanges(); checkChanges();
ask = (typeof ask === "undefined") ? true : ask;
if (question) { if (question) {
var response = window.confirm(question); var response = window.confirm(question);
if (false === response) { if (false === response) {
@ -555,10 +551,11 @@ function createMagnitudeList(data, container, template_name) {
var template = $("#" + template_name + " .pure-g")[0]; var template = $("#" + template_name + " .pure-g")[0];
for (var i=0; i<data.length; i++) { for (var i=0; i<data.length; i++) {
var magnitude = data[i];
var line = $(template).clone(); var line = $(template).clone();
$("label", line).html(magnitudeType(data[i].type) + " #" + parseInt(data[i].index, 10));
$("div.hint", line).html(data[i].name);
$("input", line).attr("tabindex", 40 + i).val(data[i].idx);
$("label", line).html(magnitudeType(magnitude.type) + " #" + parseInt(magnitude.index, 10));
$("div.hint", line).html(magnitude.name);
$("input", line).attr("tabindex", 40 + i).val(magnitude.idx);
line.appendTo("#" + container); line.appendTo("#" + container);
} }
@ -678,14 +675,15 @@ function initRelayConfig(data) {
var template = $("#relayConfigTemplate").children(); var template = $("#relayConfigTemplate").children();
for (var i=0; i < data.length; i++) { for (var i=0; i < data.length; i++) {
var relay = data[i];
var line = $(template).clone(); var line = $(template).clone();
$("span.gpio", line).html(data[i].gpio);
$("span.gpio", line).html(relay.gpio);
$("span.id", line).html(i); $("span.id", line).html(i);
$("select[name='relayBoot']", line).val(data[i].boot);
$("select[name='relayPulse']", line).val(data[i].pulse);
$("input[name='relayTime']", line).val(data[i].pulse_ms);
$("input[name='mqttGroup']", line).val(data[i].group);
$("select[name='mqttGroupInv']", line).val(data[i].group_inv);
$("select[name='relayBoot']", line).val(relay.boot);
$("select[name='relayPulse']", line).val(relay.pulse);
$("input[name='relayTime']", line).val(relay.pulse_ms);
$("input[name='mqttGroup']", line).val(relay.group);
$("select[name='mqttGroupInv']", line).val(relay.group_inv);
line.appendTo("#relayConfig"); line.appendTo("#relayConfig");
} }
@ -706,9 +704,10 @@ function initMagnitudes(data) {
// add templates // add templates
var template = $("#magnitudeTemplate").children(); var template = $("#magnitudeTemplate").children();
for (var i=0; i<data.length; i++) { for (var i=0; i<data.length; i++) {
var magnitude = data[i];
var line = $(template).clone(); var line = $(template).clone();
$("label", line).html(magnitudeType(data[i].type) + " #" + parseInt(data[i].index, 10));
$("div.hint", line).html(data[i].description);
$("label", line).html(magnitudeType(magnitude.type) + " #" + parseInt(magnitude.index, 10));
$("div.hint", line).html(magnitude.description);
$("input", line).attr("data", i); $("input", line).attr("data", i);
line.appendTo("#magnitudes"); line.appendTo("#magnitudes");
} }
@ -800,7 +799,7 @@ function initChannels(num) {
max = num % 3; max = num % 3;
if ((max > 0) & useWhite) { if ((max > 0) & useWhite) {
max--; max--;
};
}
} }
var start = num - max; var start = num - max;
@ -810,7 +809,7 @@ function initChannels(num) {
var parent = $(this).parents(".pure-g"); var parent = $(this).parents(".pure-g");
$("span", parent).html(value); $("span", parent).html(value);
websock.send(JSON.stringify({"action": "channel", "data" : { "id": id, "value": value }})); websock.send(JSON.stringify({"action": "channel", "data" : { "id": id, "value": value }}));
}
};
// add templates // add templates
var template = $("#channelTemplate").children(); var template = $("#channelTemplate").children();
@ -898,10 +897,10 @@ function processData(data) {
// Web mode // Web mode
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
if (key ==="webMode") {
password = data.webMode == 1;
$("#layout").toggle(data.webMode === 0);
$("#password").toggle(datan><span class="p">.span>webMode === 1);
if (key === "webMode") {
password = (1 === data.webMode);
$("#layout").toggle(!password);
$("#password").toggle(password);
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -909,7 +908,7 @@ function processData(data) {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
if (key === "action") { if (key === "action") {
if (data.action === "reload") doReload(1000);
if (data.action === "reload") { doReload(1000); }
return; return;
} }
@ -918,7 +917,7 @@ function processData(data) {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
if (key === "rfbCount") { if (key === "rfbCount") {
for (i=0; i<data.rfbCount; i++) addRfbNode();
for (i=0; i<data.rfbCount; i++) { addRfbNode(); }
return; return;
} }


Loading…
Cancel
Save