summaryrefslogtreecommitdiff
path: root/kvmd/web/js/atx.js
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-15 11:21:44 +0300
committerDevaev Maxim <[email protected]>2018-07-15 11:21:44 +0300
commit999d3f245710013425cc2413f81d900ec1fc2f24 (patch)
tree07bf519cab5da1b522e8146a362724762c8a3e7c /kvmd/web/js/atx.js
parent4122ecdb55abae00f2168d27df5f88527fc02341 (diff)
big js refactoring
Diffstat (limited to 'kvmd/web/js/atx.js')
-rw-r--r--kvmd/web/js/atx.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/kvmd/web/js/atx.js b/kvmd/web/js/atx.js
new file mode 100644
index 00000000..6e753bdf
--- /dev/null
+++ b/kvmd/web/js/atx.js
@@ -0,0 +1,55 @@
+var atx = new function() {
+ this.setLedsState = function(leds) {
+ $("atx-power-led").className = (leds.power ? "led-on" : "led-off");
+ $("atx-hdd-led").className = (leds.hdd ? "led-busy" : "led-off");
+ };
+
+ this.clearLeds = function() {
+ atx.setLedsState(false, false);
+ };
+
+ this.clickButton = function(el_button) {
+ switch (el_button.id) {
+ case "atx-power-button":
+ var button = "power";
+ var confirm_msg = "Are you sure to click the power button?";
+ break;
+ case "atx-power-button-long":
+ var button = "power_long";
+ var confirm_msg = "Are you sure to perform the long press of the power button?";
+ break;
+ case "atx-reset-button":
+ var button = "reset";
+ var confirm_msg = "Are you sure to reboot the server?";
+ break;
+ default:
+ var button = null;
+ var confirm_msg = null;
+ break;
+ }
+
+ if (button && confirm(confirm_msg)) {
+ __setButtonsBusy(true);
+ var http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() {
+ if (http.readyState === 4) {
+ if (http.status === 409) {
+ alert("Performing another ATX operation for other client, please try again later");
+ } else if (http.status !== 200) {
+ alert("Click error:", http.responseText);
+ }
+ __setButtonsBusy(false);
+ }
+ });
+ }
+ };
+
+ var __setButtonsBusy = function(busy) {
+ [
+ "atx-power-button",
+ "atx-power-button-long",
+ "atx-reset-button",
+ ].forEach(function(name) {
+ tools.setButtonBusy(document.getElementById(name), busy);
+ });
+ };
+};