diff --git a/web/config.json b/web/config.json index 294e8f8..3098dba 100644 --- a/web/config.json +++ b/web/config.json @@ -106,7 +106,7 @@ "name": "stopApTime", "type": "number", "default": "0", - "check": "checkStopApTime", + "check": "checkMinMax", "description": "stop the access point after that many minutes if not used", "category": "system" }, @@ -128,7 +128,8 @@ "label":"min XDR interval", "type": "number", "default": "100", - "check": "checkMinXdrInterval", + "check": "checkMinMax", + "min": 10, "description": "min interval in ms between 2 XDR records with the same transducer (> 10)", "category": "converter" }, @@ -137,7 +138,8 @@ "label":"min N2K interval", "type": "number", "default": "50", - "check": "checkMin2KInterval", + "check": "checkMinMax", + "min": 5, "description": "min interval in ms between 2 NMEA 2000 records with the same PGN (> 5)", "category": "converter" }, @@ -363,7 +365,9 @@ "label": "max. TCP clients", "type": "number", "default": "10", - "check": "checkMaxClients", + "check": "checkMinMax", + "min": 0, + "max": 10, "description": "the number of clients we allow to connect to us", "category": "TCP port" }, diff --git a/web/index.js b/web/index.js index cd9e3e7..2f283eb 100644 --- a/web/index.js +++ b/web/index.js @@ -106,12 +106,17 @@ function resetForm(ev) { } }); } -function checkMaxClients(v) { - let parsed = parseInt(v); - if (isNaN(parsed)) return "not a valid number"; - if (parsed < 0) return "must be >= 0"; - if (parsed > 10) return "max is 10"; +function checkMinMax(v,allValues,def){ + let parsed=parseFloat(v); + if (isNaN(parsed)) return "must be a number"; + if (def.min !== undefined){ + if (parsed < parseFloat(def.min)) return "must be >= "+def.min; + } + if (def.max !== undefined){ + if (parsed > parseFloat(def.max)) return "must be <= "+def.max; + } } + function checkSystemName(v) { //2...32 characters for ssid let allowed = v.replace(/[^a-zA-Z0-9]*/g, ''); @@ -124,16 +129,7 @@ function checkApPass(v) { return "password must be at least 8 characters"; } } -function checkMinXdrInterval(v){ - let vv=parseInt(v); - if (isNaN(vv)) return "is not a number"; - if (vv < 10) return "must be >= 10"; -} -function checkMin2KInterval(v){ - let vv=parseInt(v); - if (isNaN(vv)) return "is not a number"; - if (vv < 5) return "must be >= 5"; -} + function checkXDR(v,allValues){ if (! v) return; let parts=v.split(','); @@ -175,7 +171,7 @@ function changeConfig() { let check = v.getAttribute('data-check'); if (check) { if (typeof (self[check]) === 'function') { - let res = self[check](v.value,allValues); + let res = self[check](v.value,allValues,getConfigDefition(name)); if (res) { let value = v.value; if (v.type === 'password') value = "******"; @@ -301,8 +297,8 @@ let configDefinitions={}; let xdrConfig={}; //a map between the name of a config item and a list of dependend items let conditionRelations={}; -function getConditions(name){ - if (! name) return; +function getConfigDefition(name){ + if (! name) return {}; let def; for (let k in configDefinitions){ if (configDefinitions[k].name === name){ @@ -310,6 +306,11 @@ function getConditions(name){ break; } } + if (! def) return {}; + return def; +} +function getConditions(name){ + let def=getConfigDefition(name); if (! def) return; let condition=def.condition; if (! condition) return;