summaryrefslogtreecommitdiff
path: root/kvmd/web/js/atx.js
blob: 6e753bdfaedb4b81f83ac54785001a9530bc1856 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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);
		});
	};
};