From 0caf7a4aac399d1c208667115a1343cd3562fdf0 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Tue, 4 Sep 2018 16:44:26 +0300 Subject: [PATCH 1/2] attr() returns text, do not compare to 0 / 1 --- code/html/custom.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/html/custom.js b/code/html/custom.js index 4a111572..e513218b 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -182,8 +182,8 @@ function validateForm(form) { var re_hostname = new RegExp('^(?!-)[A-Za-z0-9-]{0,30}[A-Za-z0-9]$'); var hostname = $("input[name='hostname']", form); - var hasChanged = hostname.attr("hasChanged") || 0; - if (0 === hasChanged) { + var hasChanged = ("true" === hostname.attr("hasChanged")); + if (!hasChanged) { return true; } @@ -1472,27 +1472,27 @@ function hasChanged() { newValue = $(this).val(); originalValue = $(this).attr("original"); } - var hasChanged = $(this).attr("hasChanged") || 0; + var hasChanged = ("true" === $(this).attr("hasChanged")); var action = $(this).attr("action"); if (typeof originalValue === "undefined") { return; } if ("none" === action) { return; } if (newValue !== originalValue) { - if (0 === hasChanged) { + if (!hasChanged) { ++numChanged; if ("reconnect" === action) { ++numReconnect; } if ("reboot" === action) { ++numReboot; } if ("reload" === action) { ++numReload; } - $(this).attr("hasChanged", 1); + $(this).attr("hasChanged", true); } } else { - if (1 === hasChanged) { + if (hasChanged) { --numChanged; if ("reconnect" === action) { --numReconnect; } if ("reboot" === action) { --numReboot; } if ("reload" === action) { --numReload; } - $(this).attr("hasChanged", 0); + $(this).attr("hasChanged", false); } } From f59d747af1b43dc3903305ab69f76b6d1c3594d3 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Tue, 4 Sep 2018 17:44:05 +0300 Subject: [PATCH 2/2] do not reset original attr every ws message --- code/html/custom.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/code/html/custom.js b/code/html/custom.js index e513218b..e0646b30 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -300,10 +300,18 @@ function sendConfig(data) { websock.send(JSON.stringify({config: data})); } -function resetOriginals() { +function setOriginalsFromValues(force) { + var force = (true === force); $("input,select").each(function() { - $(this).attr("original", $(this).val()); + var initial = (null === $(this).attr("original")); + if (force || initial) { + $(this).attr("original", $(this).val()); + } }); +} + +function resetOriginals() { + setOriginalsFromValues(true); numReboot = numReconnect = numReload = 0; } @@ -1458,7 +1466,7 @@ function processData(data) { generateAPIKey(); } - resetOriginals(); + setOriginalsFromValues(); }