summaryrefslogtreecommitdiff
path: root/web/share/js/kvm/atx.js
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-07-21 15:02:57 +0300
committerDevaev Maxim <[email protected]>2020-07-21 15:27:14 +0300
commit360ff0090346fe2ead3e42d7bc39391325f8a2d3 (patch)
tree27de4c274acfe1abcc3df6b94d123a2cbb0fd03f /web/share/js/kvm/atx.js
parentb5ba546481dffa687395df725fb4dd57c7dc8338 (diff)
refactoring
Diffstat (limited to 'web/share/js/kvm/atx.js')
-rw-r--r--web/share/js/kvm/atx.js31
1 files changed, 19 insertions, 12 deletions
diff --git a/web/share/js/kvm/atx.js b/web/share/js/kvm/atx.js
index 7c10a496..0614cb95 100644
--- a/web/share/js/kvm/atx.js
+++ b/web/share/js/kvm/atx.js
@@ -36,30 +36,37 @@ export function Atx() {
$("atx-power-led").title = "Power Led";
$("atx-hdd-led").title = "Disk Activity Led";
- tools.setOnClick($("atx-power-button"), () => __clickButton("power", "Are you sure to click the power button?"));
- tools.setOnClick($("atx-power-button-long"), () => __clickButton("power_long", "Are you sure to perform the long press of the power button?"));
- tools.setOnClick($("atx-reset-button"), () => __clickButton("reset", "Are you sure to reboot the server?"));
+ for (let args of [
+ ["atx-power-button", "power", "Are you sure to click the power button?"],
+ ["atx-power-button-long", "power_long", "Are you sure to perform the long press of the power button?"],
+ ["atx-reset-button", "reset", "Are you sure to reboot the server?"],
+ ]) {
+ tools.setOnClick($(args[0]), () => __clickButton(args[1], args[2]));
+ }
};
/************************************************************************/
self.setState = function(state) {
+ let buttons_enabled = false;
if (state) {
- tools.setFeatureEnabled($("atx-dropdown"), state.enabled);
+ tools.featureSetEnabled($("atx-dropdown"), state.enabled);
+ $("atx-power-led").className = (state.busy ? "led-yellow" : (state.leds.power ? "led-green" : "led-gray"));
+ $("atx-hdd-led").className = (state.leds.hdd ? "led-red" : "led-gray");
+ buttons_enabled = !state.busy;
+ } else {
+ $("atx-power-led").className = "led-gray";
+ $("atx-hdd-led").className = "led-gray";
+ }
+ for (let id of ["atx-power-button", "atx-power-button-long", "atx-reset-button"]) {
+ wm.switchEnabled($(id), buttons_enabled);
}
-
- $("atx-power-led").className = ((state && state.leds.power) ? "led-green" : "led-gray");
- $("atx-hdd-led").className = ((state && state.leds.hdd) ? "led-red" : "led-gray");
-
- wm.switchEnabled($("atx-power-button"), (state && !state.busy));
- wm.switchEnabled($("atx-power-button-long"), (state && !state.busy));
- wm.switchEnabled($("atx-reset-button"), (state && !state.busy));
};
var __clickButton = function(button, confirm_msg) {
wm.confirm(confirm_msg).then(function(ok) {
if (ok) {
- let http = tools.makeRequest("POST", "/api/atx/click?button=" + button, function() {
+ let http = tools.makeRequest("POST", `/api/atx/click?button=${button}`, function() {
if (http.readyState === 4) {
if (http.status === 409) {
wm.error("Performing another ATX operation for other client.<br>Please try again later");