Code:
/*** RTR ***/
$('.reve-rtr').each(function(index){
/* data:
object: Setpoint Adr
statusObject: Is-Value Adr
1) create new element for Setpoint
2) add listener for Setpoint
*/
var curEle = $(this);
var knxAdr = curEle.data();
var setPoint = grp.find(knxAdr.object);
/* create new element */
curEle.find('.control-button').append('<button class="btn control-value disabled">( S: ' + setPoint.value.toFixed(2) + setPoint.units + ' )</button>');
/* listener for changed-Value */
grp.listen(knxAdr.object, function(object, state){
curEle.find('.control-button > button:last-child').html('( S: ' + object.value.toFixed(2) + object.units + ' )');
}, true);
});
/*****************/
/*** Jalousien ***/
/* scale */
$('.reve-jal').each(function(index){
/* data:
object: Lamelle Position Status Adr
statusObject: Postion Status Adr
1) create new element for Lamelle
2) add listener for Lamelle
*/
var curEle = $(this);
var knxAdr = curEle.data();
var lamPos = grp.find(knxAdr.object);
/* create new element */
curEle.find('.control-button').append('<button class="btn control-value disabled" style="padding:0px;">/</button>');
curEle.find('.control-button').append('<button class="btn control-value disabled">' + lamPos.value + '%</button>');
/* listener for changed-Value */
grp.listen(knxAdr.object, function(object, state){
curEle.find('.control-button > button:last-child').html(object.value + '%');
}, true);
});
/* step */
$('div').filter(function(){
/* filter the onoff buttons */
return this.className.match(/reve-jal-step/);
}).each(function(index){
/* data
object: Move Adress
statusObject: Stop Adress
*/
var curEle = $(this);
var knxAdr = curEle.data();
var stepAdr = knxAdr.object;
var stopAdr = knxAdr.statusObject;
var controlEle = curEle.find('.control');
var invert = $(this).hasClass('reve-jal-step-invert');
/* add Buttons */
controlEle.empty()
var upEle = $('<button class="btn icon">↑</button>');
var stopEle = $('<button class="btn icon btn-error">×</button>');
var downEle = $('<button class="btn icon">↓</button>');
controlEle.append(upEle);
controlEle.append(stopEle);
controlEle.append(downEle);
/* add click events */
upEle.click(function(){
grp.write(stepAdr, invert);
});
stopEle.click(function(){
grp.write(stopAdr, true);
});
downEle.click(function(){
grp.write(stepAdr, !invert);
});
});
/*** On/Off Buttons ***/
$('div').filter(function(){
/* filter the onoff buttons */
return this.className.match(/reve-onoff/);
}).each(function(index){
var curEle = $(this);
var knxAdr = curEle.data();
var useSecure = $(this).hasClass('reve-onoff-secure');
/* clear normal button */
curEle.find('.control').empty();
/* create Buttons */
var offBtn = $('<button class="btn icon">×</button>');
var onBtn = $('<button class="btn icon btn-success">✓</button>');
curEle.find('.control').append(offBtn);
curEle.find('.control').append(onBtn);
/* add listener */
function cbOn(){
grp.write(knxAdr.object, true);
}
function cbOff(){
grp.write(knxAdr.object, false);
}
offBtn.click(function(){
if(useSecure){
showPincode(grp.getvalue(secureCodeAdr), {callback: cbOff});
}
else{
cbOff();
}
});
onBtn.click(function(){
if(useSecure){
showPincode(grp.getvalue(secureCodeAdr), {callback: cbOn});
}
else{
cbOn();
}
});
});