mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
refactoring
This commit is contained in:
parent
3c1681fd2b
commit
7f1461371d
@ -51,9 +51,9 @@ export function Atx() {
|
||||
$("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.switchDisabled($("atx-power-button"), (!state || state.busy));
|
||||
wm.switchDisabled($("atx-power-button-long"), (!state || state.busy));
|
||||
wm.switchDisabled($("atx-reset-button"), (!state || state.busy));
|
||||
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) {
|
||||
|
||||
@ -86,9 +86,9 @@ export function Hid() {
|
||||
/************************************************************************/
|
||||
|
||||
self.setSocket = function(ws) {
|
||||
wm.switchDisabled($("hid-pak-text"), !ws);
|
||||
wm.switchDisabled($("hid-pak-button"), !ws);
|
||||
wm.switchDisabled($("hid-reset-button"), !ws);
|
||||
wm.switchEnabled($("hid-pak-text"), ws);
|
||||
wm.switchEnabled($("hid-pak-button"), ws);
|
||||
wm.switchEnabled($("hid-reset-button"), ws);
|
||||
__ws = ws;
|
||||
__keyboard.setSocket(ws);
|
||||
__mouse.setSocket(ws);
|
||||
@ -192,8 +192,8 @@ export function Hid() {
|
||||
|
||||
wm.confirm(confirm_msg).then(function(ok) {
|
||||
if (ok) {
|
||||
wm.switchDisabled($("hid-pak-text"), true);
|
||||
wm.switchDisabled($("hid-pak-button"), true);
|
||||
wm.switchEnabled($("hid-pak-text"), false);
|
||||
wm.switchEnabled($("hid-pak-button"), false);
|
||||
$("hid-pak-led").className = "led-yellow-rotating-fast";
|
||||
$("hid-pak-led").title = "Autotyping...";
|
||||
|
||||
@ -207,8 +207,8 @@ export function Hid() {
|
||||
iterate();
|
||||
} else {
|
||||
$("hid-pak-text").value = "";
|
||||
wm.switchDisabled($("hid-pak-text"), false);
|
||||
wm.switchDisabled($("hid-pak-button"), false);
|
||||
wm.switchEnabled($("hid-pak-text"), true);
|
||||
wm.switchEnabled($("hid-pak-button"), true);
|
||||
$("hid-pak-led").className = "led-gray";
|
||||
$("hid-pak-led").title = "";
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ export function Msd() {
|
||||
__applyState();
|
||||
});
|
||||
__applyState();
|
||||
wm.switchDisabled($(`msd-${action}-button`), true);
|
||||
wm.switchEnabled($(`msd-${action}-button`), false);
|
||||
};
|
||||
|
||||
var __selectNewImageFile = function() {
|
||||
@ -181,17 +181,17 @@ export function Msd() {
|
||||
$("msd-storage-progress-value").style.width = "0%";
|
||||
}
|
||||
|
||||
wm.switchDisabled($("msd-emulate-cdrom-checkbox"), (!__state.online || !__state.features.cdrom, __state.drive.connected || __state.busy));
|
||||
wm.switchEnabled($("msd-emulate-cdrom-checkbox"), (__state.online && __state.features.cdrom && !__state.drive.connected && !__state.busy));
|
||||
if (__state.features.multi) {
|
||||
wm.switchDisabled($("msd-connect-button"), (!__state.online || !__state.drive.image || __state.drive.connected || __state.busy));
|
||||
wm.switchEnabled($("msd-connect-button"), (__state.online && __state.drive.image && !__state.drive.connected && !__state.busy));
|
||||
} else {
|
||||
wm.switchDisabled($("msd-connect-button"), (!__state.online || __state.drive.connected || __state.busy));
|
||||
wm.switchEnabled($("msd-connect-button"), (__state.online && !__state.drive.connected && !__state.busy));
|
||||
}
|
||||
wm.switchDisabled($("msd-disconnect-button"), (!__state.online || !__state.drive.connected || __state.busy));
|
||||
wm.switchDisabled($("msd-select-new-image-button"), (!__state.online || __state.drive.connected || __state.busy || __upload_http));
|
||||
wm.switchDisabled($("msd-upload-new-image-button"), (!__state.online || __state.drive.connected || __state.busy || !__image_file));
|
||||
wm.switchDisabled($("msd-abort-uploading-button"), (!__state.online || !__upload_http));
|
||||
wm.switchDisabled($("msd-reset-button"), (!__state.enabled || __state.busy));
|
||||
wm.switchEnabled($("msd-disconnect-button"), (__state.online && __state.drive.connected && !__state.busy));
|
||||
wm.switchEnabled($("msd-select-new-image-button"), (__state.online && !__state.drive.connected && !__upload_http && !__state.busy));
|
||||
wm.switchEnabled($("msd-upload-new-image-button"), (__state.online && !__state.drive.connected && __image_file && !__state.busy));
|
||||
wm.switchEnabled($("msd-abort-uploading-button"), (__state.online && __upload_http));
|
||||
wm.switchEnabled($("msd-reset-button"), (__state.enabled && !__state.busy));
|
||||
|
||||
$("msd-emulate-cdrom-checkbox").checked = (__state.online && __state.features.cdrom && __state.drive.cdrom);
|
||||
$("msd-new-image").style.display = (__image_file ? "block" : "none");
|
||||
@ -211,13 +211,13 @@ export function Msd() {
|
||||
$("msd-drive-image-size").innerHTML = "";
|
||||
$("msd-storage-size").innerHTML = "";
|
||||
|
||||
wm.switchDisabled($("msd-emulate-cdrom-checkbox"), true);
|
||||
wm.switchDisabled($("msd-connect-button"), true);
|
||||
wm.switchDisabled($("msd-disconnect-button"), true);
|
||||
wm.switchDisabled($("msd-select-new-image-button"), true);
|
||||
wm.switchDisabled($("msd-upload-new-image-button"), true);
|
||||
wm.switchDisabled($("msd-abort-uploading-button"), true);
|
||||
wm.switchDisabled($("msd-reset-button"), true);
|
||||
wm.switchEnabled($("msd-emulate-cdrom-checkbox"), false);
|
||||
wm.switchEnabled($("msd-connect-button"), false);
|
||||
wm.switchEnabled($("msd-disconnect-button"), false);
|
||||
wm.switchEnabled($("msd-select-new-image-button"), false);
|
||||
wm.switchEnabled($("msd-upload-new-image-button"), false);
|
||||
wm.switchEnabled($("msd-abort-uploading-button"), false);
|
||||
wm.switchEnabled($("msd-reset-button"), false);
|
||||
|
||||
$("msd-emulate-cdrom-checkbox").checked = false;
|
||||
$("msd-select-new-image-file").value = "";
|
||||
|
||||
@ -72,7 +72,7 @@ export function Streamer() {
|
||||
state = state.state;
|
||||
|
||||
if (!$("stream-quality-slider").activated) {
|
||||
wm.switchDisabled($("stream-quality-slider"), false);
|
||||
wm.switchEnabled($("stream-quality-slider"), true);
|
||||
if ($("stream-quality-slider").value !== state.encoder.quality) {
|
||||
$("stream-quality-slider").value = state.encoder.quality;
|
||||
__updateQualityValue(state.encoder.quality);
|
||||
@ -81,7 +81,7 @@ export function Streamer() {
|
||||
|
||||
if (!$("stream-desired-fps-slider").activated) {
|
||||
$("stream-desired-fps-slider").max = max_fps;
|
||||
wm.switchDisabled($("stream-desired-fps-slider"), false);
|
||||
wm.switchEnabled($("stream-desired-fps-slider"), true);
|
||||
if ($("stream-desired-fps-slider").value !== state.source.desired_fps) {
|
||||
$("stream-desired-fps-slider").value = state.source.desired_fps;
|
||||
__updateDesiredFpsValue(state.source.desired_fps);
|
||||
@ -103,8 +103,8 @@ export function Streamer() {
|
||||
if (__ensureStream(state.stream.clients_stat)) {
|
||||
$("stream-led").className = "led-green";
|
||||
$("stream-led").title = "Stream is active";
|
||||
wm.switchDisabled($("stream-screenshot-button"), false);
|
||||
wm.switchDisabled($("stream-reset-button"), false);
|
||||
wm.switchEnabled($("stream-screenshot-button"), true);
|
||||
wm.switchEnabled($("stream-reset-button"), true);
|
||||
$("stream-quality-slider").activated = false;
|
||||
$("stream-desired-fps-slider").activated = false;
|
||||
tools.info("Stream: active");
|
||||
@ -115,10 +115,10 @@ export function Streamer() {
|
||||
} else {
|
||||
$("stream-led").className = "led-gray";
|
||||
$("stream-led").title = "Stream inactive";
|
||||
wm.switchDisabled($("stream-screenshot-button"), true);
|
||||
wm.switchDisabled($("stream-reset-button"), true);
|
||||
wm.switchDisabled($("stream-quality-slider"), true);
|
||||
wm.switchDisabled($("stream-desired-fps-slider"), true);
|
||||
wm.switchEnabled($("stream-screenshot-button"), false);
|
||||
wm.switchEnabled($("stream-reset-button"), false);
|
||||
wm.switchEnabled($("stream-quality-slider"), false);
|
||||
wm.switchEnabled($("stream-desired-fps-slider"), false);
|
||||
tools.info("Stream: inactive");
|
||||
|
||||
__updateStreamWindow(false, false);
|
||||
|
||||
@ -62,18 +62,18 @@ function __login() {
|
||||
}
|
||||
}
|
||||
}, body, "application/x-www-form-urlencoded");
|
||||
__setDisabled(true);
|
||||
__setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
function __setDisabled(disabled) {
|
||||
wm.switchDisabled($("user-input"), disabled);
|
||||
wm.switchDisabled($("passwd-input"), disabled);
|
||||
wm.switchDisabled($("login-button"), disabled);
|
||||
function __setEnabled(enabled) {
|
||||
wm.switchEnabled($("user-input"), enabled);
|
||||
wm.switchEnabled($("passwd-input"), enabled);
|
||||
wm.switchEnabled($("login-button"), enabled);
|
||||
}
|
||||
|
||||
function __tryAgain() {
|
||||
__setDisabled(false);
|
||||
__setEnabled(true);
|
||||
$("passwd-input").focus();
|
||||
$("passwd-input").select();
|
||||
}
|
||||
|
||||
@ -156,8 +156,8 @@ function __WindowManager() {
|
||||
return promise;
|
||||
};
|
||||
|
||||
self.switchDisabled = function(el, disabled) {
|
||||
if (disabled && document.activeElement === el) {
|
||||
self.switchEnabled = function(el, enabled) {
|
||||
if (!enabled && document.activeElement === el) {
|
||||
let el_to_focus = (
|
||||
el.closest(".modal-window")
|
||||
|| el.closest(".window")
|
||||
@ -167,7 +167,7 @@ function __WindowManager() {
|
||||
el_to_focus.focus();
|
||||
}
|
||||
}
|
||||
el.disabled = disabled;
|
||||
el.disabled = !enabled;
|
||||
};
|
||||
|
||||
self.showWindow = function(el_window, activate=true, center=false) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user