fhemweb.js: fix bitfield issues (Forum #102825)
git-svn-id: https://svn.fhem.de/fhem/trunk@19957 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
@@ -1833,12 +1833,14 @@ FW_createBitfield(elName, devName, vArr, currVal, set, params, cmd)
|
|||||||
{
|
{
|
||||||
if(vArr[0] != "bitfield")
|
if(vArr[0] != "bitfield")
|
||||||
return undefined;
|
return undefined;
|
||||||
|
if(elName)
|
||||||
elName = elName.replace(/[^A-Z0-9_]/ig, '_');
|
elName = elName.replace(/[^A-Z0-9_]/ig, '_');
|
||||||
|
var lName = Math.random().toString(36).substr(2);
|
||||||
var fieldSize = (vArr.length > 1 ? parseInt(vArr[1]) : 8);
|
var fieldSize = (vArr.length > 1 ? parseInt(vArr[1]) : 8);
|
||||||
var bitMask = (vArr.length > 2 ? parseInt(vArr[2]) : 4294967295);
|
var bitMask = (vArr.length > 2 ? parseInt(vArr[2]) : 4294967295);
|
||||||
var html = '<div style="display:inline-block" tabindex="0">'+
|
var html = '<div style="display:inline-block" tabindex="0">'+
|
||||||
'<input type="hidden" name="'+elName+'">'+
|
(elName ? '<input type="hidden" name="'+elName+'">' : '')+
|
||||||
'<table id="'+elName+'_bitfield">';
|
'<table id="'+lName+'_bitfield">';
|
||||||
for(var fs=fieldSize; fs>0; ) {
|
for(var fs=fieldSize; fs>0; ) {
|
||||||
html += '<tr><td>Bit '+fs+'</td><td>';
|
html += '<tr><td>Bit '+fs+'</td><td>';
|
||||||
for(var i1=0; i1<8 && fs>0; i1++, fs--)
|
for(var i1=0; i1<8 && fs>0; i1++, fs--)
|
||||||
@@ -1851,20 +1853,23 @@ FW_createBitfield(elName, devName, vArr, currVal, set, params, cmd)
|
|||||||
newEl.activateFn = function() {
|
newEl.activateFn = function() {
|
||||||
var bm = bitMask;
|
var bm = bitMask;
|
||||||
for(var i1=1; i1<=fieldSize; i1++) {
|
for(var i1=1; i1<=fieldSize; i1++) {
|
||||||
$('#'+elName+'_bitfield input[value='+i1+']')
|
$('#'+lName+'_bitfield input[value='+i1+']')
|
||||||
.prop("disabled", (bm%2 == 0));
|
.prop("disabled", (bm%2 == 0));
|
||||||
bm = parseInt(bm/2);
|
bm = parseInt(bm/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#"+elName+"_bitfield input").change(function(){
|
$("#"+lName+"_bitfield input").change(function(){
|
||||||
var total = 0;
|
var total = 0;
|
||||||
$("#"+elName+"_bitfield input").each(function(){
|
$("#"+lName+"_bitfield input").each(function(){
|
||||||
if($(this).is(":checked")) {
|
if($(this).is(":checked")) {
|
||||||
var sv = parseInt($(this).attr("value"))-1, thisVal=1;
|
var sv = parseInt($(this).attr("value"))-1, thisVal=1;
|
||||||
while(sv) { thisVal *= 2; sv--; } // << works on signed 32bit values
|
while(sv) { thisVal *= 2; sv--; } // << works on signed 32bit values
|
||||||
total += thisVal;
|
total += thisVal;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if(cmd)
|
||||||
|
cmd(total);
|
||||||
|
if(elName)
|
||||||
$("[name="+elName+"]").val(total);
|
$("[name="+elName+"]").val(total);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1872,7 +1877,7 @@ FW_createBitfield(elName, devName, vArr, currVal, set, params, cmd)
|
|||||||
newEl.setValueFn = function(arg) {
|
newEl.setValueFn = function(arg) {
|
||||||
var total = parseInt(arg);
|
var total = parseInt(arg);
|
||||||
for(var i1=1; i1<=fieldSize; i1++) {
|
for(var i1=1; i1<=fieldSize; i1++) {
|
||||||
$('#'+elName+'_bitfield input[value='+i1+']')
|
$('#'+lName+'_bitfield input[value='+i1+']')
|
||||||
.prop("checked", (total%2 == 1));
|
.prop("checked", (total%2 == 1));
|
||||||
total = parseInt(total/2);
|
total = parseInt(total/2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user