").appendTo(this.container);
- this.onSpan = this.onLabel.children('span');
+ this.onSpan = this.onLabel.children("span");
this.handle = $("
").appendTo(this.container);
this.handleCenter = $("
").appendTo(this.handle);
this.handleRight = $("
").appendTo(this.handle);
@@ -89,12 +94,12 @@
iOSCheckbox.prototype.optionallyResize = function(mode) {
var newWidth, offLabelWidth, offSpan, onLabelWidth, onSpan;
- onSpan = this.onLabel.find('span');
+ onSpan = this.onLabel.find("span");
onLabelWidth = this._getDimension(onSpan, "width");
- onLabelWidth += parseInt(onSpan.css('padding-left'), 10);
- offSpan = this.offLabel.find('span');
+ onLabelWidth += parseInt(onSpan.css("padding-left"), 10);
+ offSpan = this.offLabel.find("span");
offLabelWidth = this._getDimension(offSpan, "width");
- offLabelWidth += parseInt(offSpan.css('padding-right'), 10);
+ offLabelWidth += parseInt(offSpan.css("padding-right"), 10);
if (mode === "container") {
newWidth = onLabelWidth > offLabelWidth ? onLabelWidth : offLabelWidth;
newWidth += this._getDimension(this.handle, "width") + this.handleMargin;
@@ -122,7 +127,7 @@
x = event.pageX || event.originalEvent.changedTouches[0].pageX;
iOSCheckbox.currentlyClicking = this.handle;
iOSCheckbox.dragStartPosition = x;
- return iOSCheckbox.handleLeftOffset = parseInt(this.handle.css('left'), 10) || 0;
+ return iOSCheckbox.handleLeftOffset = parseInt(this.handle.css("left"), 10) || 0;
};
iOSCheckbox.prototype.onDragMove = function(event, x) {
@@ -164,14 +169,14 @@
}
if (iOSCheckbox.dragging) {
p = (x - iOSCheckbox.dragStartPosition) / this.rightSide;
- this.elem.prop('checked', p >= 0.5).change();
+ this.elem.prop("checked", p >= 0.5).change();
} else {
- this.elem.prop('checked', !this.elem.prop('checked')).change();
+ this.elem.prop("checked", !this.elem.prop("checked")).change();
}
iOSCheckbox.currentlyClicking = null;
iOSCheckbox.dragging = null;
if (typeof this.onChange === "function") {
- this.onChange(this.elem, this.elem.prop('checked'));
+ this.onChange(this.elem, this.elem.prop("checked"));
}
return this.didChange();
};
@@ -181,7 +186,7 @@
};
iOSCheckbox.prototype.didChange = function() {
- var new_left;
+ var newLeft;
if (this.isDisabled()) {
this.container.addClass(this.disabledClass);
@@ -189,18 +194,18 @@
} else {
this.container.removeClass(this.disabledClass);
}
- new_left = this.elem.prop('checked') ? this.rightSide + 2 : 0;
+ newLeft = this.elem.prop("checked") ? this.rightSide + 2 : 0;
this.handle.animate({
- left: new_left
+ left: newLeft
}, this.duration);
this.onLabel.animate({
- width: new_left + this.handleRadius
+ width: newLeft + this.handleRadius
}, this.duration);
this.offSpan.animate({
- marginRight: -new_left
+ marginRight: - newLeft
}, this.duration);
return this.onSpan.animate({
- marginLeft: new_left - this.rightSide
+ marginLeft: newLeft - this.rightSide
}, this.duration);
};
@@ -213,16 +218,16 @@
};
localMouseUp = function(event) {
self.onGlobalUp.apply(self, arguments);
- $(document).unbind('mousemove touchmove', localMouseMove);
- return $(document).unbind('mouseup touchend', localMouseUp);
+ $(document).unbind("mousemove touchmove", localMouseMove);
+ return $(document).unbind("mouseup touchend", localMouseUp);
};
this.elem.change(function() {
return self.refresh();
});
- return this.container.bind('mousedown touchstart', function(event) {
+ return this.container.bind("mousedown touchstart", function(event) {
self.onMouseDown.apply(self, arguments);
- $(document).bind('mousemove touchmove', localMouseMove);
- return $(document).bind('mouseup touchend', localMouseUp);
+ $(document).bind("mousemove touchmove", localMouseMove);
+ return $(document).bind("mouseup touchend", localMouseUp);
});
};
@@ -241,7 +246,7 @@
offset -= 3;
}
this.rightSide = containerWidth - this._getDimension(this.handle, "width") - offset;
- if (this.elem.is(':checked')) {
+ if (this.elem.is(":checked")) {
this.handle.css({
left: this.rightSide
});
@@ -292,17 +297,17 @@
iOSCheckbox.defaults = {
duration: 200,
- checkedLabel: 'ON',
- uncheckedLabel: 'OFF',
+ checkedLabel: "ON",
+ uncheckedLabel: "OFF",
resizeHandle: true,
resizeContainer: true,
- disabledClass: 'iPhoneCheckDisabled',
- containerClass: 'iPhoneCheckContainer',
- labelOnClass: 'iPhoneCheckLabelOn',
- labelOffClass: 'iPhoneCheckLabelOff',
- handleClass: 'iPhoneCheckHandle',
- handleCenterClass: 'iPhoneCheckHandleCenter',
- handleRightClass: 'iPhoneCheckHandleRight',
+ disabledClass: "iPhoneCheckDisabled",
+ containerClass: "iPhoneCheckContainer",
+ labelOnClass: "iPhoneCheckLabelOn",
+ labelOffClass: "iPhoneCheckLabelOff",
+ handleClass: "iPhoneCheckHandle",
+ handleCenterClass: "iPhoneCheckHandleCenter",
+ handleRightClass: "iPhoneCheckHandleRight",
dragThreshold: 5,
handleMargin: 15,
handleRadius: 4,
@@ -322,7 +327,7 @@
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
dataName = (_ref = (_ref1 = args[0]) != null ? _ref1.dataName : void 0) != null ? _ref : iOSCheckbox.defaults.dataName;
- _ref2 = this.filter(':checkbox');
+ _ref2 = this.filter(":checkbox");
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
checkbox = _ref2[_i];
existingControl = $(checkbox).data(dataName);
@@ -346,14 +351,14 @@
}
opts = $.extend({}, options, {
resizeHandle: false,
- disabledClass: 'iOSCheckDisabled',
- containerClass: 'iOSCheckContainer',
- labelOnClass: 'iOSCheckLabelOn',
- labelOffClass: 'iOSCheckLabelOff',
- handleClass: 'iOSCheckHandle',
- handleCenterClass: 'iOSCheckHandleCenter',
- handleRightClass: 'iOSCheckHandleRight',
- dataName: 'iOSCheckbox'
+ disabledClass: "iOSCheckDisabled",
+ containerClass: "iOSCheckContainer",
+ labelOnClass: "iOSCheckLabelOn",
+ labelOffClass: "iOSCheckLabelOff",
+ handleClass: "iOSCheckHandle",
+ handleCenterClass: "iOSCheckHandleCenter",
+ handleRightClass: "iOSCheckHandleRight",
+ dataName: "iOSCheckbox"
});
return this.iphoneStyle(opts);
};
diff --git a/code/html/custom.js b/code/html/custom.js
index 80e866bc..13d88862 100644
--- a/code/html/custom.js
+++ b/code/html/custom.js
@@ -36,7 +36,9 @@ function sensorName(id) {
"Events", "PMSX003", "BMX280", "MHZ19", "SI7021",
"SHT3X I2C", "BH1750"
];
- if (1 <= id && id <= names.length) return names[id-1];
+ if (1 <= id && id <= names.length) {
+ return names[id-1];
+ }
return null;
}
@@ -48,7 +50,9 @@ function magnitudeType(type) {
"Analog", "Digital", "Events",
"PM1.0", "PM2.5", "PM10", "CO2", "Lux"
];
- if (1 <= type && type <= types.length) return types[type-1];
+ if (1 <= type && type <= types.length) {
+ return types[type-1];
+ }
return null;
}
@@ -57,7 +61,9 @@ function magnitudeError(error) {
"OK", "Out of Range", "Warming Up", "Timeout", "Wrong ID",
"CRC Error", "I2C Error", "GPIO Error"
];
- if (0 <= error && error < errors.length) return errors[error];
+ if (0 <= error && error < errors.length) {
+ return errors[error];
+ }
return "Error " + error;
}
@@ -74,7 +80,7 @@ function checkPassword(str) {
}
function zeroPad(number, positions) {
- var zeros = '';
+ var zeros = "";
for (var i = 0; i < positions; i++) zeros += "0";
return (zeros + number).slice(-positions);
}
@@ -89,7 +95,7 @@ function validateForm(form) {
}
var adminPass2 = $("input[name='adminPass']", form).last().val();
- if (adminPass1 != adminPass2) {
+ if (adminPass1 !== adminPass2) {
alert("Passwords are different!");
return false;
}
@@ -118,16 +124,18 @@ function getData(form) {
$("input,select", form).each(function() {
var name = $(this).attr("name");
if (name) {
+ var value = "";
// Do not report these fields
- if (name == "filename") return;
- if (name == "rfbcode") return;
+ if (name === "filename" || name === "rfbcode" ) {
+ return;
+ }
// Grab the value
- if ($(this).attr('type') == 'checkbox') {
- value = $(this).is(':checked') ? 1 : 0;
- } else if ($(this).attr('type') == 'radio') {
- if (!$(this).is(':checked')) return;
+ if ($(this).attr("type") === "checkbox") {
+ value = $(this).is(":checked") ? 1 : 0;
+ } else if ($(this).attr("type") === "radio") {
+ if (!$(this).is(":checked")) {return;}
value = $(this).val();
} else {
value = $(this).val();
@@ -158,20 +166,22 @@ function getData(form) {
}
function randomString(length, chars) {
- var mask = '';
- if (chars.indexOf('a') > -1) mask += 'abcdefghijklmnopqrstuvwxyz';
- if (chars.indexOf('A') > -1) mask += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- if (chars.indexOf('#') > -1) mask += '0123456789';
- if (chars.indexOf('@') > -1) mask += 'ABCDEF';
- if (chars.indexOf('!') > -1) mask += '~`!@#$%^&*()_+-={}[]:";\'<>?,./|\\';
- var result = '';
- for (var i = length; i > 0; --i) result += mask[Math.round(Math.random() * (mask.length - 1))];
+ var mask = "";
+ if (chars.indexOf("a") > -1) mask += "abcdefghijklmnopqrstuvwxyz";
+ if (chars.indexOf("A") > -1) mask += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ if (chars.indexOf("#") > -1) mask += "0123456789";
+ if (chars.indexOf("@") > -1) mask += "ABCDEF";
+ if (chars.indexOf("!") > -1) mask += "~`!@#$%^&*()_+-={}[]:\";'<>?,./|\\";
+ var result = "";
+ for (var i = length; i > 0; --i) {
+ result += mask[Math.round(Math.random() * (mask.length - 1))];
+ }
return result;
}
function generateAPIKey() {
- var apikey = randomString(16, '@#');
- $("input[name=\"apiKey\"]").val(apikey);
+ var apikey = randomString(16, "@#");
+ $("input[name='apiKey']").val(apikey);
return false;
}
@@ -187,8 +197,17 @@ function getJson(str) {
// Actions
// -----------------------------------------------------------------------------
+function resetOriginals() {
+ $("input,select").each(function() {
+ $(this).attr("original", $(this).val());
+ });
+ numReboot = numReconnect = numReload = 0;
+}
+
function doReload(milliseconds) {
- milliseconds = (typeof milliseconds == 'undefined') ? 0 : parseInt(milliseconds);
+ milliseconds = (typeof milliseconds == "undefined") ?
+ 0 :
+ parseInt(milliseconds, 10);
setTimeout(function() {
window.location.reload();
}, milliseconds);
@@ -201,27 +220,29 @@ function doUpdate() {
// Get data
var data = getData(form);
- websock.send(JSON.stringify({'config': data}));
+ websock.send(JSON.stringify({"config": data}));
// Empty special fields
$(".pwrExpected").val(0);
- $("input[name='pwrResetCalibration']")
- .prop("checked", false)
- .iphoneStyle("refresh");
+ $("input[name='pwrResetCalibration']").
+ prop("checked", false).
+ iphoneStyle("refresh");
// Change handling
numChanged = 0;
setTimeout(function() {
+ var response;
+
if (numReboot > 0) {
- var response = window.confirm("You have to reboot the board for the changes to take effect, do you want to do it now?");
- if (response == true) doReboot(false);
+ response = window.confirm("You have to reboot the board for the changes to take effect, do you want to do it now?");
+ if (response === true) doReboot(false);
} else if (numReconnect > 0) {
- var response = window.confirm("You have to reconnect to the WiFi for the changes to take effect, do you want to do it now?");
- if (response == true) doReconnect(false);
+ response = window.confirm("You have to reconnect to the WiFi for the changes to take effect, do you want to do it now?");
+ if (response === true) doReconnect(false);
} else if (numReload > 0) {
- var response = window.confirm("You have to reload the page to see the latest changes, do you want to do it now?");
- if (response == true) doReload();
+ response = window.confirm("You have to reload the page to see the latest changes, do you want to do it now?");
+ if (response === true) doReload();
}
resetOriginals();
@@ -237,20 +258,20 @@ function doUpdate() {
function doUpgrade() {
var contents = $("input[name='upgrade']")[0].files[0];
- if (typeof contents == 'undefined') {
+ if (typeof contents === "undefined") {
alert("First you have to select a file from your computer.");
return false;
}
- var filename = $("input[name='upgrade']").val().split('\\').pop();
+ var filename = $("input[name='upgrade']").val().split("\\").pop();
var data = new FormData();
- data.append('upgrade', contents, filename);
+ data.append("upgrade", contents, filename);
$.ajax({
// Your server script to process the upload
- url: webhost + 'upgrade',
- type: 'POST',
+ url: webhost + "upgrade",
+ type: "POST",
// Form data
data: data,
@@ -263,7 +284,7 @@ function doUpgrade() {
success: function(data, text) {
$("#upgrade-progress").hide();
- if (data == 'OK') {
+ if (data === "OK") {
alert("Firmware image uploaded, board rebooting. This page will be refreshed in 5 seconds.");
doReload(5000);
} else {
@@ -277,14 +298,14 @@ function doUpgrade() {
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) {
// For handling the progress of the upload
- myXhr.upload.addEventListener('progress', function(e) {
+ myXhr.upload.addEventListener("progress", function(e) {
if (e.lengthComputable) {
- $('progress').attr({ value: e.loaded, max: e.total });
+ $("progress").attr({ value: e.loaded, max: e.total });
}
} , false);
}
return myXhr;
- },
+ }
});
@@ -296,71 +317,86 @@ function doUpdatePassword() {
var form = $("#formPassword");
if (validateForm(form)) {
var data = getData(form);
- websock.send(JSON.stringify({'config': data}));
+ websock.send(JSON.stringify({"config": data}));
}
return false;
}
function doReboot(ask) {
- ask = (typeof ask == 'undefined') ? true : ask;
+ var response;
+
+ ask = (typeof ask == "undefined") ? true : ask;
if (numChanged > 0) {
- var response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
- if (response == true) return doUpdate();
+ response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
+ if (response === true) {
+ return doUpdate();
+ }
}
if (ask) {
- var response = window.confirm("Are you sure you want to reboot the device?");
- if (response == false) return false;
+ response = window.confirm("Are you sure you want to reboot the device?");
+ if (response === false) {
+ return false;
+ }
}
- websock.send(JSON.stringify({'action': 'reboot'}));
+ websock.send(JSON.stringify({"action": "reboot"}));
doReload(5000);
return false;
}
function doReconnect(ask) {
+ var response;
- ask = (typeof ask == 'undefined') ? true : ask;
+ ask = (typeof ask == "undefined") ? true : ask;
if (numChanged > 0) {
- var response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
- if (response == true) return doUpdate();
+ response = window.confirm("Some changes have not been saved yet, do you want to save them first?");
+ if (response === true) {
+ return doUpdate();
+ }
}
if (ask) {
- var response = window.confirm("Are you sure you want to disconnect from the current WIFI network?");
- if (response == false) return false;
+ response = window.confirm("Are you sure you want to disconnect from the current WIFI network?");
+ if (response === false) {
+ return false;
+ }
}
- websock.send(JSON.stringify({'action': 'reconnect'}));
+ websock.send(JSON.stringify({"action": "reconnect"}));
doReload(5000);
return false;
}
function doBackup() {
- document.getElementById('downloader').src = webhost + 'config';
+ document.getElementById("downloader").src = webhost + "config";
return false;
}
function onFileUpload(event) {
var inputFiles = this.files;
- if (inputFiles == undefined || inputFiles.length == 0) return false;
+ if (inputFiles === undefined || inputFiles.length === 0) {
+ return false;
+ }
var inputFile = inputFiles[0];
this.value = "";
var response = window.confirm("Previous settings will be overwritten. Are you sure you want to restore this settings?");
- if (response == false) return false;
+ if (response === false) {
+ return false;
+ }
var reader = new FileReader();
reader.onload = function(e) {
var data = getJson(e.target.result);
if (data) {
- websock.send(JSON.stringify({'action': 'restore', 'data': data}));
+ websock.send(JSON.stringify({"action": "restore", "data": data}));
} else {
alert(messages[4]);
}
@@ -372,7 +408,7 @@ function onFileUpload(event) {
}
function doRestore() {
- if (typeof window.FileReader !== 'function') {
+ if (typeof window.FileReader !== "function") {
alert("The file API isn't supported on this browser yet.");
} else {
$("#uploader").click();
@@ -381,8 +417,8 @@ function doRestore() {
}
function doToggle(element, value) {
- var relayID = parseInt(element.attr("data"));
- websock.send(JSON.stringify({'action': 'relay', 'data': { 'id': relayID, 'status': value ? 1 : 0 }}));
+ var relayID = parseInt(element.attr("data"), 10);
+ websock.send(JSON.stringify({"action": "relay", "data": { "id": relayID, "status": value ? 1 : 0 }}));
return false;
}
@@ -400,26 +436,30 @@ function doScan() {
function showPanel() {
$(".panel").hide();
$("#" + $(this).attr("data")).show();
- if ($("#layout").hasClass('active')) toggleMenu();
- $("input[type='checkbox']").iphoneStyle("calculateDimensions").iphoneStyle("refresh");
-};
+ if ($("#layout").hasClass("active")) toggleMenu();
+ $("input[type='checkbox']").
+ iphoneStyle("calculateDimensions").
+ iphoneStyle("refresh");
+}
function toggleMenu() {
- $("#layout").toggleClass('active');
- $("#menu").toggleClass('active');
- $("#menuLink").toggleClass('active');
+ $("#layout").toggleClass("active");
+ $("#menu").toggleClass("active");
+ $("#menuLink").toggleClass("active");
}
// -----------------------------------------------------------------------------
// Relays & magnitudes mapping
// -----------------------------------------------------------------------------
-function createRelayList(data, container, template) {
+function createRelayList(data, container, template_name) {
var current = $("#" + container + " > div").length;
- if (current > 0) return;
+ if (current > 0) {
+ return;
+ }
- var template = $("#" + template + " .pure-g")[0];
+ var template = $("#" + template_name + " .pure-g")[0];
for (var i=0; i
div").length;
- if (current > 0) return;
+ if (current > 0) {
+ return;
+ }
- var template = $("#" + template + " .pure-g")[0];
+ var template = $("#" + template_name + " .pure-g")[0];
for (var i=0; i div").length;
if (numNetworks >= maxNetworks) {
alert("Max number of networks reached");
- return;
+ return null;
}
var tabindex = 200 + numNetworks * 10;
var template = $("#networkTemplate").children();
var line = $(template).clone();
$(line).find("input").each(function() {
- $(this).attr("tabindex", tabindex++);
+ $(this).attr("tabindex", tabindex);
+ tabindex++;
});
- $(line).find(".button-del-network").on('click', delNetwork);
- $(line).find(".button-more-network").on('click', moreNetwork);
+ $(line).find(".button-del-network").on("click", delNetwork);
+ $(line).find(".button-more-network").on("click", moreNetwork);
line.appendTo("#networks");
return line;
@@ -498,22 +541,21 @@ function addSchedule() {
var numSchedules = $("#schedules > div").length;
if (numSchedules >= maxSchedules) {
alert("Max number of schedules reached");
- return;
+ return null;
}
var tabindex = 200 + numSchedules * 10;
var template = $("#scheduleTemplate").children();
var line = $(template).clone();
$(line).find("input").each(function() {
- $(this).attr("tabindex", tabindex++);
+ $(this).attr("tabindex", tabindex);
+ tabindex++;
});
- $(line).find(".button-del-schedule").on('click', delSchedule);
- $(line).find(".button-more-schedule").on('click', moreSchedule);
+ $(line).find(".button-del-schedule").on("click", delSchedule);
+ $(line).find(".button-more-schedule").on("click", moreSchedule);
line.appendTo("#schedules");
return line;
}
-
-
// -----------------------------------------------------------------------------
// Relays
// -----------------------------------------------------------------------------
@@ -521,10 +563,14 @@ function addSchedule() {
function initRelays(data) {
var current = $("#relays > div").length;
- if (current > 0) return;
+ if (current > 0) {
+ return;
+ }
var template = $("#relayTemplate .pure-g")[0];
for (var i=0; i").attr("value",i).text("Switch #" + i));
+
}
+
}
function initRelayConfig(data) {
var current = $("#relayConfig > div").length;
- if (current > 0) return;
+ if (current > 0) {
+ return;
+ }
var template = $("#relayConfigTemplate").children();
for (var i=0; i < data.length; i++) {
@@ -569,13 +622,15 @@ function initMagnitudes(data) {
// check if already initialized
var done = $("#magnitudes > div").length;
- if (done > 0) return;
+ if (done > 0) {
+ return;
+ }
// add templates
var template = $("#magnitudeTemplate").children();
for (var i=0; i div").length;
- if (done > 0) return;
+ if (done > 0) {
+ return;
+ }
// add template
var template = $("#colorRGBTemplate").children();
@@ -606,19 +665,19 @@ function initColorRGB() {
line.appendTo("#colors");
// init color wheel
- $('input[name="color"]').wheelColorPicker({
- sliders: 'wrgbp'
- }).on('sliderup', function() {
- var value = $(this).wheelColorPicker('getValue', 'css');
- websock.send(JSON.stringify({'action': 'color', 'data' : {'rgb': value}}));
+ $("input[name='color']").wheelColorPicker({
+ sliders: "wrgbp"
+ }).on("sliderup", function() {
+ var value = $(this).wheelColorPicker("getValue", "css");
+ websock.send(JSON.stringify({"action": "color", "data" : {"rgb": value}}));
});
// init bright slider
- $('#brightness').on("change", function() {
+ $("#brightness").on("change", function() {
var value = $(this).val();
var parent = $(this).parents(".pure-g");
$("span", parent).html(value);
- websock.send(JSON.stringify({'action': 'color', 'data' : {'brightness': value}}));
+ websock.send(JSON.stringify({"action": "color", "data" : {"brightness": value}}));
});
}
@@ -627,7 +686,9 @@ function initColorHSV() {
// check if already initialized
var done = $("#colors > div").length;
- if (done > 0) return;
+ if (done > 0) {
+ return;
+ }
// add template
var template = $("#colorHSVTemplate").children();
@@ -635,12 +696,12 @@ function initColorHSV() {
line.appendTo("#colors");
// init color wheel
- $('input[name="color"]').wheelColorPicker({
- sliders: 'whsvp'
- }).on('sliderup', function() {
- var color = $(this).wheelColorPicker('getColor');
- var value = parseInt(color.h * 360) + "," + parseInt(color.s * 100) + "," + parseInt(color.v * 100);
- websock.send(JSON.stringify({'action': 'color', 'data' : {'hsv': value}}));
+ $("input[name='color']").wheelColorPicker({
+ sliders: "whsvp"
+ }).on("sliderup", function() {
+ var color = $(this).wheelColorPicker("getColor");
+ var value = parseInt(color.h * 360, 10) + "," + parseInt(color.s * 100, 10) + "," + parseInt(color.v * 100, 10);
+ websock.send(JSON.stringify({"action": "color", "data" : {"hsv": value}}));
});
}
@@ -649,7 +710,9 @@ function initChannels(num) {
// check if already initialized
var done = $("#channels > div").length > 0;
- if (done) return;
+ if (done) {
+ return;
+ }
// does it have color channels?
var colors = $("#colors > div").length > 0;
@@ -674,7 +737,7 @@ function initChannels(num) {
var value = $(this).val();
var parent = $(this).parents(".pure-g");
$("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 }}));
});
$("label", line).html("Channel " + (channel_id + 1));
@@ -701,9 +764,9 @@ function addRfbNode() {
$(this).attr("data-status", status ? 1 : 0);
status = !status;
});
- $(line).find(".button-rfb-learn").on('click', rfbLearn);
- $(line).find(".button-rfb-forget").on('click', rfbForget);
- $(line).find(".button-rfb-send").on('click', rfbSend);
+ $(line).find(".button-rfb-learn").on("click", rfbLearn);
+ $(line).find(".button-rfb-forget").on("click", rfbForget);
+ $(line).find(".button-rfb-send").on("click", rfbSend);
line.appendTo("#rfbNodes");
return line;
@@ -712,19 +775,19 @@ function addRfbNode() {
function rfbLearn() {
var parent = $(this).parents(".pure-g");
var input = $("input", parent);
- websock.send(JSON.stringify({'action': 'rfblearn', 'data' : {'id' : input.attr("data-id"), 'status': input.attr("data-status")}}));
+ websock.send(JSON.stringify({"action": "rfblearn", "data" : {"id" : input.attr("data-id"), "status": input.attr("data-status")}}));
}
function rfbForget() {
var parent = $(this).parents(".pure-g");
var input = $("input", parent);
- websock.send(JSON.stringify({'action': 'rfbforget', 'data' : {'id' : input.attr("data-id"), 'status': input.attr("data-status")}}));
+ websock.send(JSON.stringify({"action": "rfbforget", "data" : {"id" : input.attr("data-id"), "status": input.attr("data-status")}}));
}
function rfbSend() {
var parent = $(this).parents(".pure-g");
var input = $("input", parent);
- websock.send(JSON.stringify({'action': 'rfbsend', 'data' : {'id' : input.attr("data-id"), 'status': input.attr("data-status"), 'data': input.val()}}));
+ websock.send(JSON.stringify({"action": "rfbsend", "data" : {"id" : input.attr("data-id"), "status": input.attr("data-status"), "data": input.val()}}));
}
// -----------------------------------------------------------------------------
@@ -748,22 +811,24 @@ function processData(data) {
Object.keys(data).forEach(function(key) {
+ var i;
+
// ---------------------------------------------------------------------
// Web mode
// ---------------------------------------------------------------------
- if (key == "webMode") {
+ if (key ==="webMode") {
password = data.webMode == 1;
- $("#layout").toggle(data.webMode == 0);
- $("#password").toggle(data.webMode == 1);
+ $("#layout").toggle(data.webMode === 0);
+ $("#password").toggle(data.webMode === 1);
}
// ---------------------------------------------------------------------
// Actions
// ---------------------------------------------------------------------
- if (key == "action") {
- if (data.action == "reload") doReload(1000);
+ if (key === "action") {
+ if (data.action === "reload") doReload(1000);
return;
}
@@ -771,16 +836,16 @@ function processData(data) {
// RFBridge
// ---------------------------------------------------------------------
- if (key == "rfbCount") {
- for (var i=0; i").attr("value",i).text("Switch #" + i)
- );
+ $("input.relayStatus[data='" + i + "']").
+ prop("checked", data[key][i]).
+ iphoneStyle("refresh");
}
return;
}
// Relay configuration
- if (key == "relayConfig") {
+ if (key === "relayConfig") {
initRelayConfig(data[key]);
return;
}
@@ -926,13 +986,13 @@ function processData(data) {
// ---------------------------------------------------------------------
// Domoticz - Relays
- if (key == "dczRelays") {
+ if (key === "dczRelays") {
createRelayList(data[key], "dczRelays", "dczRelayTemplate");
return;
}
// Domoticz - Magnitudes
- if (key == "dczMagnitudes") {
+ if (key === "dczMagnitudes") {
createMagnitudeList(data[key], "dczMagnitudes", "dczMagnitudeTemplate");
return;
}
@@ -942,13 +1002,13 @@ function processData(data) {
// ---------------------------------------------------------------------
// Thingspeak - Relays
- if (key == "tspkRelays") {
+ if (key === "tspkRelays") {
createRelayList(data[key], "tspkRelays", "tspkRelayTemplate");
return;
}
// Thingspeak - Magnitudes
- if (key == "tspkMagnitudes") {
+ if (key === "tspkMagnitudes") {
createMagnitudeList(data[key], "tspkMagnitudes", "tspkMagnitudeTemplate");
return;
}
@@ -958,68 +1018,71 @@ function processData(data) {
// ---------------------------------------------------------------------
// Messages
- if (key == "message") {
+ if (key === "message") {
window.alert(messages[data.message]);
return;
}
// Enable options
var position = key.indexOf("Visible");
- if (position > 0 && position == key.length - 7) {
+ if (position > 0 && position === key.length - 7) {
var module = key.slice(0,-7);
$(".module-" + module).show();
return;
}
// Pre-process
- if (key == "network") {
+ if (key === "network") {
data.network = data.network.toUpperCase();
}
- if (key == "mqttStatus") {
+ if (key === "mqttStatus") {
data.mqttStatus = data.mqttStatus ? "CONNECTED" : "NOT CONNECTED";
}
- if (key == "ntpStatus") {
+ if (key === "ntpStatus") {
data.ntpStatus = data.ntpStatus ? "SYNC'D" : "NOT SYNC'D";
}
- if (key == "uptime") {
- var uptime = parseInt(data[key]);
- var seconds = uptime % 60; uptime = parseInt(uptime / 60);
- var minutes = uptime % 60; uptime = parseInt(uptime / 60);
- var hours = uptime % 24; uptime = parseInt(uptime / 24);
+ if (key === "uptime") {
+ var uptime = parseInt(data[key], 10);
+ var seconds = uptime % 60; uptime = parseInt(uptime / 60, 10);
+ var minutes = uptime % 60; uptime = parseInt(uptime / 60, 10);
+ var hours = uptime % 24; uptime = parseInt(uptime / 24, 10);
var days = uptime;
- data[key] = days + 'd ' + zeroPad(hours, 2) + 'h ' + zeroPad(minutes, 2) + 'm ' + zeroPad(seconds, 2) + 's';
+ data[key] = days + "d " + zeroPad(hours, 2) + "h " + zeroPad(minutes, 2) + "m " + zeroPad(seconds, 2) + "s";
}
// ---------------------------------------------------------------------
// Matching
// ---------------------------------------------------------------------
+ var pre;
+ var post;
+
// Look for INPUTs
- var element = $("input[name=" + key + "]");
+ var element = $("input[name='" + key + "']");
if (element.length > 0) {
- if (element.attr('type') == 'checkbox') {
- element
- .prop("checked", data[key])
- .iphoneStyle("refresh");
- } else if (element.attr('type') == 'radio') {
+ if (element.attr("type") === "checkbox") {
+ element.
+ prop("checked", data[key]).
+ iphoneStyle("refresh");
+ } else if (element.attr("type") === "radio") {
element.val([data[key]]);
} else {
- var pre = element.attr("pre") || "";
- var post = element.attr("post") || "";
+ pre = element.attr("pre") || "";
+ post = element.attr("post") || "";
element.val(pre + data[key] + post);
}
}
// Look for SPANs
- var element = $("span[name=" + key + "]");
+ var element = $("span[name='" + key + "']");
if (element.length > 0) {
- var pre = element.attr("pre") || "";
- var post = element.attr("post") || "";
+ pre = element.attr("pre") || "";
+ post = element.attr("post") || "";
element.html(pre + data[key] + post);
}
// Look for SELECTs
- var element = $("select[name=" + key + "]");
+ var element = $("select[name='" + key + "']");
if (element.length > 0) {
element.val(data[key]);
}
@@ -1027,7 +1090,7 @@ function processData(data) {
});
// Auto generate an APIKey if none defined yet
- if ($("input[name='apiKey']").val() == "") {
+ if ($("input[name='apiKey']").val() === "") {
generateAPIKey();
}
@@ -1038,8 +1101,8 @@ function processData(data) {
function hasChanged() {
var newValue, originalValue;
- if ($(this).attr('type') == 'checkbox') {
- newValue = $(this).prop("checked")
+ if ($(this).attr("type") === "checkbox") {
+ newValue = $(this).prop("checked");
originalValue = $(this).attr("original") == "true";
} else {
newValue = $(this).val();
@@ -1048,53 +1111,46 @@ function hasChanged() {
var hasChanged = $(this).attr("hasChanged") || 0;
var action = $(this).attr("action");
- if (typeof originalValue == 'undefined') return;
- if (action == 'none') return;
+ if (typeof originalValue === "undefined") {return;}
+ if (action === "none") {return;}
- if (newValue != originalValue) {
- if (hasChanged == 0) {
+ if (newValue !== originalValue) {
+ if (hasChanged === 0) {
++numChanged;
- if (action == "reconnect") ++numReconnect;
- if (action == "reboot") ++numReboot;
- if (action == "reload") ++numReload;
+ if (action === "reconnect") ++numReconnect;
+ if (action === "reboot") ++numReboot;
+ if (action === "reload") ++numReload;
$(this).attr("hasChanged", 1);
}
} else {
- if (hasChanged == 1) {
+ if (hasChanged === 1) {
--numChanged;
- if (action == "reconnect") --numReconnect;
- if (action == "reboot") --numReboot;
- if (action == "reload") --numReload;
+ if (action === "reconnect") --numReconnect;
+ if (action === "reboot") --numReboot;
+ if (action === "reload") --numReload;
$(this).attr("hasChanged", 0);
}
}
}
-function resetOriginals() {
- $("input,select").each(function() {
- $(this).attr("original", $(this).val());
- })
- numReboot = numReconnect = numReload = 0;
-}
-
// -----------------------------------------------------------------------------
// Init & connect
// -----------------------------------------------------------------------------
function connect(host) {
- if (typeof host === 'undefined') {
- host = window.location.href.replace('#', '');
+ if (typeof host === "undefined") {
+ host = window.location.href.replace("#", "");
} else {
- if (host.indexOf("http") != 0) {
- host = 'http://' + host + '/';
+ if (host.indexOf("http") !== 0) {
+ host = "http://" + host + "/";
}
}
- if (host.indexOf("http") != 0) return;
+ if (host.indexOf("http") !== 0) {return;}
webhost = host;
- wshost = host.replace('http', 'ws') + 'ws';
+ wshost = host.replace("http", "ws") + "ws";
if (websock) websock.close();
websock = new WebSocket(wshost);
@@ -1108,38 +1164,38 @@ $(function() {
initMessages();
- $("#menuLink").on('click', toggleMenu);
- $(".pure-menu-link").on('click', showPanel);
- $('progress').attr({ value: 0, max: 100 });
-
- $(".button-update").on('click', doUpdate);
- $(".button-update-password").on('click', doUpdatePassword);
- $(".button-reboot").on('click', doReboot);
- $(".button-reconnect").on('click', doReconnect);
- $(".button-wifi-scan").on('click', doScan);
- $(".button-settings-backup").on('click', doBackup);
- $(".button-settings-restore").on('click', doRestore);
- $('#uploader').on('change', onFileUpload);
- $(".button-upgrade").on('click', doUpgrade);
-
- $(".button-apikey").on('click', generateAPIKey);
- $(".button-upgrade-browse").on('click', function() {
+ $("#menuLink").on("click", toggleMenu);
+ $(".pure-menu-link").on("click", showPanel);
+ $("progress").attr({ value: 0, max: 100 });
+
+ $(".button-update").on("click", doUpdate);
+ $(".button-update-password").on("click", doUpdatePassword);
+ $(".button-reboot").on("click", doReboot);
+ $(".button-reconnect").on("click", doReconnect);
+ $(".button-wifi-scan").on("click", doScan);
+ $(".button-settings-backup").on("click", doBackup);
+ $(".button-settings-restore").on("click", doRestore);
+ $("#uploader").on("change", onFileUpload);
+ $(".button-upgrade").on("click", doUpgrade);
+
+ $(".button-apikey").on("click", generateAPIKey);
+ $(".button-upgrade-browse").on("click", function() {
$("input[name='upgrade']")[0].click();
return false;
});
$("input[name='upgrade']").change(function (){
var fileName = $(this).val();
- $("input[name='filename']").val(fileName.replace(/^.*[\\\/]/, ''));
+ $("input[name='filename']").val(fileName.replace(/^.*[\\\/]/, ""));
});
- $(".button-add-network").on('click', function() {
+ $(".button-add-network").on("click", function() {
$(".more", addNetwork()).toggle();
});
- $(".button-add-schedule").on('click', function() {
+ $(".button-add-schedule").on("click", function() {
$("div.more", addSchedule()).toggle();
});
- $(document).on('change', 'input', hasChanged);
- $(document).on('change', 'select', hasChanged);
+ $(document).on("change", "input", hasChanged);
+ $(document).on("change", "select", hasChanged);
connect();
diff --git a/code/ota.py b/code/ota.py
index e3a79d76..afc65e0b 100644
--- a/code/ota.py
+++ b/code/ota.py
@@ -19,7 +19,7 @@ from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf
try:
# noinspection PyUnresolvedReferences
- input = raw_input # Python2
+ input = raw_input # Python2 *!! redefining build-in input.
except NameError:
pass # Python3
@@ -56,7 +56,7 @@ def on_service_state_change(zeroconf, service_type, name, state_change):
devices.append(device)
-def list():
+def list_devices():
"""
Shows the list of discovered devices
"""
@@ -241,7 +241,7 @@ if __name__ == '__main__':
devices = sorted(devices, key=lambda device: device.get(field, ''))
# List devices
- list()
+ list_devices()
# Flash device
if args.flash > 0: