summaryrefslogtreecommitdiff
path: root/web/share/js
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-10 18:37:25 +0300
committerDevaev Maxim <[email protected]>2020-09-10 18:37:25 +0300
commit6aa5893d57b4af1434b5a40894674c4158868c5a (patch)
tree2d4f20135001e32c319720859dd1b0cb16d55554 /web/share/js
parentbae65c35ee9db3dfd478fb60ce20cdf6d3a2e57b (diff)
refactoring
Diffstat (limited to 'web/share/js')
-rw-r--r--web/share/js/kvm/gpio.js22
1 files changed, 11 insertions, 11 deletions
diff --git a/web/share/js/kvm/gpio.js b/web/share/js/kvm/gpio.js
index a412d579..e7b3c9e1 100644
--- a/web/share/js/kvm/gpio.js
+++ b/web/share/js/kvm/gpio.js
@@ -75,8 +75,6 @@ export function Gpio() {
$("gpio-menu-button").innerHTML = `${model.view.header.title} &#8628;`;
}
- let switches = [];
- let buttons = [];
let content = "<table class=\"kv\">";
for (let row of model.view.table) {
if (row === null) {
@@ -87,7 +85,7 @@ export function Gpio() {
if (item.type === "output") {
item.scheme = model.scheme.outputs[item.channel];
}
- content += `<td align="center">${__createItem(item, switches, buttons)}</td>`;
+ content += `<td align="center">${__createItem(item)}</td>`;
}
content += "</tr>";
}
@@ -95,17 +93,21 @@ export function Gpio() {
content += "</table>";
$("gpio-menu").innerHTML = content;
- for (let channel of switches) {
- tools.setOnClick($(`gpio-switch-${channel}`), () => __switchChannel(channel));
- }
- for (let channel of buttons) {
- tools.setOnClick($(`gpio-button-${channel}`), () => __pulseChannel(channel));
+ for (let channel in model.scheme.outputs) {
+ let el = $(`gpio-switch-${channel}`);
+ if (el) {
+ tools.setOnClick(el, () => __switchChannel(channel));
+ }
+ el = $(`gpio-button-${channel}`);
+ if (el) {
+ tools.setOnClick(el, () => __pulseChannel(channel));
+ }
}
self.setState(__state);
};
- var __createItem = function(item, switches, buttons) {
+ var __createItem = function(item) {
if (item.type === "label") {
return item.text;
} else if (item.type === "input") {
@@ -116,7 +118,6 @@ export function Gpio() {
} else if (item.type === "output") {
let controls = [];
if (item.scheme["switch"]) {
- switches.push(item.channel);
controls.push(`
<td><div class="switch-box">
<input disabled type="checkbox" id="gpio-switch-${item.channel}" class="gpio-switch" />
@@ -128,7 +129,6 @@ export function Gpio() {
`);
}
if (item.scheme.pulse.delay) {
- buttons.push(item.channel);
controls.push(`<td><button disabled id="gpio-button-${item.channel}" class="gpio-button">${item.text}</button></td>`);
}
return `<table><tr>${controls.join("<td>&nbsp;&nbsp;&nbsp;</td>")}</tr></table>`;