From 5e902f688dbb9ed9a0825ea920dc08e7e40f87f0 Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Thu, 15 Jun 2017 11:01:57 +0000
Subject: [PATCH] 01_FHEMWEB.pm: selectnumbers widget modifier (Forum #73188)
git-svn-id: https://svn.fhem.de/fhem/trunk@14516 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/01_FHEMWEB.pm | 20 ++++++++++++
fhem/www/pgm2/fhemweb.js | 68 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 89 insertions(+)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index efc1ba751..c3909d61c 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
+ - feature: 01_FHEMWEB.pm: selectnumbers widget modifier (Forum #73188)
- feature: 98_structure.pm: add evaluateSetResult attribute (Forum #73113)
- feature: ESPEasy: improved defineFn if bridge port is missing, docu update
- feature: 37_Spotify: resume on target
diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm
index 73a19cfa6..ee0ecdb8d 100755
--- a/fhem/FHEM/01_FHEMWEB.pm
+++ b/fhem/FHEM/01_FHEMWEB.pm
@@ -3965,6 +3965,15 @@ FW_widgetOverride($$)
given to select the switching value. see examples below.
the result is a space separeted list of uzsuTimerEntry results.
+
if the modifier is of the form
+ ":selectnumbers,<min>,<step>,<max>,<number of
+ digits after decimal point>,lin|log10",a select widget is
+ generated with values from min to max with step.
+ lin generates a constantly increasing series. log10 generates an
+ exponentially increasing series to base 10, step is related to the
+ exponent, e.g. 0.0625.
+
+
else a dropdown with all the modifier values is displayed
If this attribute is specified for a FHEMWEB instance, then it is
@@ -4756,6 +4765,17 @@ FW_widgetOverride($$)
Das Ergebiss ist eine durch leerzeichen getrennte Liste von
uzsuTimerEntry Ergebnissen.
+ Ist der Modifier in der Form
+ ":selectnumbers,<min>,<step>,<max>,<number of
+ digits after decimal point>,lin|log10", so wird ein in
+ Select-Widget mit einer Zahlenreihe vom Wert min bis Wert max mit
+ Schritten von step angezeigt.
+
+ Die Angabe lin erzeugt eine konstant ansteigende Reihe. Die Angabe
+ log10 erzeugt eine exponentiell ansteigende Reihe zur Basis 10,
+ step bezieht sich auf den Exponenten, z.B. 0.0625.
+
+
In allen anderen Fällen (oder falls der Modifier explizit
mit :select anfaegt) erscheint ein HTML select mit allen Modifier
Werten.
diff --git a/fhem/www/pgm2/fhemweb.js b/fhem/www/pgm2/fhemweb.js
index a5fe3361d..ec7c9d8dc 100644
--- a/fhem/www/pgm2/fhemweb.js
+++ b/fhem/www/pgm2/fhemweb.js
@@ -17,6 +17,7 @@ var embedLoadRetry = 100;
// - activateFn, which is called after the HTML element is part of the DOM.
var FW_widgets = {
select: { createFn:FW_createSelect },
+ selectnumbers: { createFn:FW_createSelectNumbers, },
slider: { createFn:FW_createSlider },
time: { createFn:FW_createTime },
noArg: { createFn:FW_createNoArg },
@@ -1188,6 +1189,73 @@ FW_createSelect(elName, devName, vArr, currVal, set, params, cmd)
return newEl;
}
+/*************** selectNumbers **************/
+// Syntax: selectnumbers,,,,,lin|log10
+
+function
+FW_createSelectNumbers(elName, devName, vArr, currVal, set, params, cmd)
+{
+ if(vArr.length < 6 || vArr[0] != "selectnumbers" || (params && params.length))
+ return undefined;
+
+ var min = parseFloat(vArr[1]);
+ var stp = parseFloat(vArr[2]);
+ var max = parseFloat(vArr[3]);
+ var dp = parseFloat(vArr[4]); // decimal points
+ var fun = vArr[5]; // function
+
+ if(currVal != undefined)
+ currVal = currVal.replace(/[^\d.\-]/g, "");
+ currVal = (currVal==undefined || currVal=="") ? min : parseFloat(currVal);
+ if(max==min)
+ return undefined;
+ if(!(fun == "lin" || fun == "log10"))
+ return undefined;
+
+ if(currVal < min)
+ currVal = min;
+ if(currVal > max)
+ currVal = max;
+
+ var newEl = document.createElement('select');
+ var vHash = {};
+ var k = 0;
+ var v = 0;
+ if (fun == "lin") {
+ for(var j=min; j <= max; j+=stp) {
+ var o = document.createElement('option');
+ o.text = o.value = j.toFixed(dp);
+ vHash[j.toString()] = 1;
+ newEl.options[k] = o;
+ k++;
+ }
+ } else if (fun == "log10") {
+ if(min <= 0 || max <= 0)
+ return undefined;
+ for(var j=Math.log10(min); j <= Math.log10(max)+stp; j+=stp) {
+ var o = document.createElement('option');
+ var w = Math.pow(10, j)
+ if (w > max)
+ w = max;
+ if (v == w.toFixed(dp))
+ continue;
+ v = w.toFixed(dp);
+ o.text = o.value = v;
+ vHash[v] = 1;
+ newEl.options[k] = o;
+ k++;
+ }
+ }
+ if(currVal)
+ $(newEl).val(currVal.toFixed(dp));
+ if(elName)
+ $(newEl).attr('name', elName);
+ if(cmd)
+ $(newEl).change(function(arg) { cmd($(newEl).val()) });
+ newEl.setValueFn = function(arg) { if(vHash[arg]) $(newEl).val(arg); };
+ return newEl;
+}
+
/*************** noArg **************/
function
FW_createNoArg(elName, devName, vArr, currVal, set, params, cmd)