diff options
Diffstat (limited to 'kvmd/web/js/atx.js')
-rw-r--r-- | kvmd/web/js/atx.js | 77 |
1 files changed, 33 insertions, 44 deletions
diff --git a/kvmd/web/js/atx.js b/kvmd/web/js/atx.js index 56b49e54..cb0163ed 100644 --- a/kvmd/web/js/atx.js +++ b/kvmd/web/js/atx.js @@ -1,53 +1,44 @@ -var atx = new function() { - this.loadInitialState = function() { +function Atx() { + var self = this; + + /********************************************************************************/ + + var __init__ = function() { + $("atx-power-led").title = "Power Led"; + $("atx-hdd-led").title = "Disk Activity Led"; + + $("atx-power-button").onclick = () => __clickButton("power", null, "Are you sure to click the power button?"); + $("atx-power-button-long").onclick = () => __clickButton("power_long", 15000, "Are you sure to perform the long press of the power button?"); + $("atx-reset-button").onclick = () => __clickButton("reset", null, "Are you sure to reboot the server?"); + }; + + /********************************************************************************/ + + self.loadInitialState = function() { var http = tools.makeRequest("GET", "/kvmd/atx", function() { if (http.readyState === 4) { if (http.status === 200) { - atx.setButtonsBusy(JSON.parse(http.responseText).result.busy); + __setButtonsBusy(JSON.parse(http.responseText).result.busy); } else { - setTimeout(atx.loadInitialState, 1000); + setTimeout(self.loadInitialState, 1000); } } }); }; - this.setState = function(state) { - atx.setButtonsBusy(state.busy); + self.setState = function(state) { + __setButtonsBusy(state.busy); $("atx-power-led").className = (state.leds.power ? "led-on" : "led-off"); $("atx-hdd-led").className = (state.leds.hdd ? "led-hdd-busy" : "led-off"); }; - this.clearState = function() { - [ - "atx-power-led", - "atx-hdd-led", - ].forEach(function(name) { - $(name).className = "led-off"; - }); + self.clearState = function() { + $("atx-power-led").className = "led-off"; + $("atx-hdd-led").className = "led-off"; }; - this.clickButton = function(el_button) { - var button = null; - var confirm_msg = null; - var timeout = null; - - switch (el_button.id) { - case "atx-power-button": - button = "power"; - confirm_msg = "Are you sure to click the power button?"; - break; - case "atx-power-button-long": - button = "power_long"; - confirm_msg = "Are you sure to perform the long press of the power button?"; - timeout = 15000; - break; - case "atx-reset-button": - button = "reset"; - confirm_msg = "Are you sure to reboot the server?"; - break; - } - - if (button && confirm(confirm_msg)) { + var __clickButton = function(button, timeout, confirm_msg) { + if (confirm(confirm_msg)) { var http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() { if (http.readyState === 4) { if (http.status === 409) { @@ -60,13 +51,11 @@ var atx = new function() { } }; - this.setButtonsBusy = function(busy) { - [ - "atx-power-button", - "atx-power-button-long", - "atx-reset-button", - ].forEach(function(name) { - document.getElementById(name).disabled = busy; - }); + var __setButtonsBusy = function(busy) { + $("atx-power-button").disabled = busy; + $("atx-power-button-long").disabled = busy; + $("atx-reset-button").disabled = busy; }; -}; + + __init__(); +} |