mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
01_FHEMWEB.pm: selectnumbers widget modifier (Forum #73188)
git-svn-id: https://svn.fhem.de/fhem/trunk@14516 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
ba90774060
commit
5e902f688d
@ -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
|
||||
|
@ -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.</li>
|
||||
|
||||
<li>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.<br>
|
||||
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.
|
||||
</li>
|
||||
|
||||
<li>else a dropdown with all the modifier values is displayed</li>
|
||||
</ul>
|
||||
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.</li>
|
||||
|
||||
<li>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.<br>
|
||||
|
||||
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.
|
||||
</li>
|
||||
|
||||
<li>In allen anderen Fällen (oder falls der Modifier explizit
|
||||
mit :select anfaegt) erscheint ein HTML select mit allen Modifier
|
||||
Werten.</li>
|
||||
|
@ -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,<min value>,<step|step of exponent>,<max value>,<number of digits after decimal point>,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)
|
||||
|
Loading…
Reference in New Issue
Block a user