|
80 | 80 | inner.appendChild(button); |
81 | 81 | outer.appendChild(inner); |
82 | 82 | schlist.insertBefore(outer, addline); |
83 | | - } |
| 83 | + } |
| 84 | + var label = "Enable Schedule"; |
| 85 | + var action = enableSchedule; |
| 86 | + if (response.lights.mode == "auto") { |
| 87 | + label = "Disable Schedule"; |
| 88 | + action = disableSchedule; |
| 89 | + } |
| 90 | + var buttons = document.getElementsByClassName ("modeButton"); |
| 91 | + for (var i = 0; i < buttons.length; i++) { |
| 92 | + buttons[i].innerHTML = label; |
| 93 | + buttons[i].disabled = false; |
| 94 | + buttons[i].onclick = action; |
| 95 | + } |
84 | 96 | } |
85 | 97 |
|
86 | 98 | function lightsUpdate (response) { |
|
93 | 105 | lightsShow(response); |
94 | 106 | } |
95 | 107 |
|
96 | | -function lightsRefresh () { |
| 108 | +function lightsRefresh (request) { |
97 | 109 | var command = new XMLHttpRequest(); |
98 | | - command.open("GET", "/lights/status"); |
| 110 | + if (request) |
| 111 | + command.open("GET", request); |
| 112 | + else |
| 113 | + command.open("GET", "/lights/status"); |
99 | 114 | command.onreadystatechange = function () { |
100 | 115 | if (command.readyState === 4 && command.status === 200) { |
101 | 116 | var response = JSON.parse(command.responseText); |
|
140 | 155 | command.send(null); |
141 | 156 | } |
142 | 157 |
|
| 158 | +function doNothing() {} |
| 159 | + |
| 160 | +function enableSchedule () { |
| 161 | + lightsRefresh ("/lights/enable"); |
| 162 | +} |
| 163 | + |
| 164 | +function disableSchedule () { |
| 165 | + lightsRefresh ("/lights/disable"); |
| 166 | +} |
| 167 | + |
143 | 168 | window.onload = function() { |
144 | 169 | lightsConfig(); |
145 | 170 | setInterval (lightsRefresh, 5000); |
|
189 | 214 | <td><input type="checkbox" id="lightsat"></td> |
190 | 215 | <td><button onclick="lightsAdd()">Add</button></td> |
191 | 216 | </tr> |
| 217 | + <tr> |
| 218 | + <td></td> |
| 219 | + <td></td> |
| 220 | + <td></td> |
| 221 | + <td></td> |
| 222 | + <td></td> |
| 223 | + <td></td> |
| 224 | + <td></td> |
| 225 | + <td></td> |
| 226 | + <td></td> |
| 227 | + <td></td> |
| 228 | + <td></td> |
| 229 | + <td><button class="modeButton" disabled onclick="doNothing()">Loading..</button></td> |
| 230 | + </tr> |
192 | 231 | </table> |
193 | 232 | </body> |
194 | 233 | </html> |
|
0 commit comments