From c48ab36903900f07aee3cc6c0ed1eb54e1eea201 Mon Sep 17 00:00:00 2001 From: squandor Date: Sat, 21 Jan 2017 22:02:42 +0100 Subject: [PATCH] fix selector problem with click #53 --- static/js/domoboard.js | 7 +++++-- templates/switches.html | 6 ++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/static/js/domoboard.js b/static/js/domoboard.js index 4233c39..7ff12c5 100644 --- a/static/js/domoboard.js +++ b/static/js/domoboard.js @@ -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¶m=switchlight&idx=' + idx + '&switchcmd=Set%20Level&level=' + lvl + '&passcode='); }); } diff --git a/templates/switches.html b/templates/switches.html index efc9c1a..89e47c9 100644 --- a/templates/switches.html +++ b/templates/switches.html @@ -152,11 +152,10 @@ $(document).ready(function() { btnClass = 'btn btn-responsive'; } bid = 'selector_{{v[1]}}_block_{{count}}_index_'; - b = ''; + b = ''; $('#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}}); }); -