fix selector problem with click #53

This commit is contained in:
squandor 2017-01-21 22:02:42 +01:00
parent 8a298ec443
commit c48ab36903
2 changed files with 7 additions and 6 deletions

View File

@ -24,6 +24,9 @@ function changeSwitch(checkboxElem, idx) {
// switchSelector
function switchSelector(idx, lvl, bid) {
var old_bid = bid.replace(new RegExp(lvl + '$'), '');
//var old_index = bid.replace(lvl, '');
url = '/api?type=devices&rid=' + idx;
requestAPI(flask_server + url, function(d) {
r = JSON.parse(d);
@ -31,8 +34,8 @@ function switchSelector(idx, lvl, bid) {
if (last_active != 0) {
last_active = last_active + 0;
}
$('#' + bid + last_active).removeClass('btn-primary');
$('#' + bid + lvl).addClass('btn-primary');
$('#' + old_bid + last_active).removeClass('btn-primary');
$('#' + bid).addClass('btn-primary');
requestAPI(flask_server + '/api?type=command&param=switchlight&idx=' + idx + '&switchcmd=Set%20Level&level=' + lvl + '&passcode=');
});
}

View File

@ -152,11 +152,10 @@ $(document).ready(function() {
btnClass = 'btn btn-responsive';
}
bid = 'selector_{{v[1]}}_block_{{count}}_index_';
b = '<button id="' + bid + i + '" class="' + btnClass + '">' + lvlname + '</button>';
b = '<button id="' + bid + i + '" onclick="switchSelector({{v[1]}}, ' + i + ', this.id)" class="' + btnClass + '">' + lvlname + '</button>';
$('#selector_body_{{v[1]}}_block_{{count}}').append(b);
$('#' + bid + i).click(function(e) {
$('#' + 'selector_{{v[1]}}_block_{{count}}_index_' + i).click(function(e) {
e.preventDefault();
switchSelector({{v[1]}}, i, bid);
});
});
});
@ -183,5 +182,4 @@ $(document).ready(function() {
setInterval(refreshSetpoints, 9000, updateSetpoints_block_{{count}}, {{count}});
});
</script>