minor partial state fixes

This commit is contained in:
Maxim Devaev
2024-11-04 18:06:16 +02:00
parent d93639ba8d
commit 7ef2e16b51
7 changed files with 85 additions and 75 deletions

View File

@@ -53,30 +53,33 @@ export function Atx(__recorder) {
__state = {"leds": {}};
}
if (state.enabled !== undefined) {
tools.feature.setEnabled($("atx-dropdown"), state.enabled);
__state.enabled = state.enabled;
tools.feature.setEnabled($("atx-dropdown"), __state.enabled);
}
if (__state.enabled !== undefined) {
if (state.busy !== undefined) {
__updateButtons(!state.busy);
__state.busy = state.busy;
__updateButtons(!__state.busy);
}
if (state.leds !== undefined) {
__state.leds = state.leds;
}
if (state.busy !== undefined || state.leds !== undefined) {
let busy = __state.busy;
let leds = __state.leds;
$("atx-power-led").className = (busy ? "led-yellow" : (leds.power ? "led-green" : "led-gray"));
$("atx-hdd-led").className = (leds.hdd ? "led-red" : "led-gray");
__updateLeds(__state.leds.power, __state.leds.hdd, __state.busy);
}
}
} else {
__state = null;
__updateLeds(false, false, false);
__updateButtons(false);
}
};
var __updateLeds = function(power, hdd, busy) {
$("atx-power-led").className = (busy ? "led-yellow" : (power ? "led-green" : "led-gray"));
$("atx-hdd-led").className = (hdd ? "led-red" : "led-gray");
};
var __updateButtons = function(enabled) {
for (let id of ["atx-power-button", "atx-power-button-long", "atx-reset-button"]) {
tools.el.setEnabled($(id), enabled);