From bc49a887753d63e5e8d8c9c5a8be01895259b45c Mon Sep 17 00:00:00 2001 From: squandor Date: Sun, 8 Jan 2017 01:40:19 +0100 Subject: [PATCH] Fix for issue #46 created an link behind the dimmer name which switches the dimmer --- static/js/domoboard.js | 12 ++++++++++++ templates/switches.html | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/static/js/domoboard.js b/static/js/domoboard.js index 22a0f6a..6fec00a 100644 --- a/static/js/domoboard.js +++ b/static/js/domoboard.js @@ -22,6 +22,18 @@ function changeSwitch(checkboxElem, idx) { } } +// Dimmer functions +function changeDimmer(checkboxElem, idx) { + var chkurl = "/api?type=devices&rid=" + idx; + requestAPI(flask_server + chkurl, function(d) { + _json = JSON.parse(d); + if (_json['result'][0]['Data'] != 'Off') { + requestAPI(flask_server + "/api?type=command¶m=switchlight&idx=" + idx + "&switchcmd=Off&level=0"); + } else { + requestAPI(flask_server + "/api?type=command¶m=switchlight&idx=" + idx + "&switchcmd=On&level=0"); + } + }); +} // Switch functions function changePush(idx, action) { if (action == 'on') { diff --git a/templates/switches.html b/templates/switches.html index 0491ae6..f3295b3 100644 --- a/templates/switches.html +++ b/templates/switches.html @@ -16,12 +16,16 @@ {% for k, v in blockArray[count]["switches"].iteritems() %} + {% if "dimmer" in v[1] or "rgb" in v[1] %} + + {% else %} + {% endif %}
{% if "switch" in v[1] %} {% elif "dimmer" in v[1] %} - + {% elif "pushon" in v[1] %} {% elif "pushoff" in v[1] %} @@ -127,6 +131,10 @@ $(document).ready(function() { {% elif (v[1] == "setpoint") %} updateSetpoints_block_{{count}}.push("{{v[0]}}"); {% elif (v[1] == "dimmer" or v[1] == "rgb") %} + $('#dim_{{count}}').click(function(e) { + e.preventDefault(); + changeDimmer(this, {{v[0]}}); + }); updateDimmers_block_{{count}}.push("{{v[0]}}"); {% endif %} {% endfor %}