refactoring

This commit is contained in:
Devaev Maxim 2019-11-08 02:08:56 +03:00
parent 3c1681fd2b
commit 7f1461371d
6 changed files with 43 additions and 43 deletions

View File

@ -51,9 +51,9 @@ export function Atx() {
$("atx-power-led").className = ((state && state.leds.power) ? "led-green" : "led-gray"); $("atx-power-led").className = ((state && state.leds.power) ? "led-green" : "led-gray");
$("atx-hdd-led").className = ((state && state.leds.hdd) ? "led-red" : "led-gray"); $("atx-hdd-led").className = ((state && state.leds.hdd) ? "led-red" : "led-gray");
wm.switchDisabled($("atx-power-button"), (!state || state.busy)); wm.switchEnabled($("atx-power-button"), (state && !state.busy));
wm.switchDisabled($("atx-power-button-long"), (!state || state.busy)); wm.switchEnabled($("atx-power-button-long"), (state && !state.busy));
wm.switchDisabled($("atx-reset-button"), (!state || state.busy)); wm.switchEnabled($("atx-reset-button"), (state && !state.busy));
}; };
var __clickButton = function(button, confirm_msg) { var __clickButton = function(button, confirm_msg) {

View File

@ -86,9 +86,9 @@ export function Hid() {
/************************************************************************/ /************************************************************************/
self.setSocket = function(ws) { self.setSocket = function(ws) {
wm.switchDisabled($("hid-pak-text"), !ws); wm.switchEnabled($("hid-pak-text"), ws);
wm.switchDisabled($("hid-pak-button"), !ws); wm.switchEnabled($("hid-pak-button"), ws);
wm.switchDisabled($("hid-reset-button"), !ws); wm.switchEnabled($("hid-reset-button"), ws);
__ws = ws; __ws = ws;
__keyboard.setSocket(ws); __keyboard.setSocket(ws);
__mouse.setSocket(ws); __mouse.setSocket(ws);
@ -192,8 +192,8 @@ export function Hid() {
wm.confirm(confirm_msg).then(function(ok) { wm.confirm(confirm_msg).then(function(ok) {
if (ok) { if (ok) {
wm.switchDisabled($("hid-pak-text"), true); wm.switchEnabled($("hid-pak-text"), false);
wm.switchDisabled($("hid-pak-button"), true); wm.switchEnabled($("hid-pak-button"), false);
$("hid-pak-led").className = "led-yellow-rotating-fast"; $("hid-pak-led").className = "led-yellow-rotating-fast";
$("hid-pak-led").title = "Autotyping..."; $("hid-pak-led").title = "Autotyping...";
@ -207,8 +207,8 @@ export function Hid() {
iterate(); iterate();
} else { } else {
$("hid-pak-text").value = ""; $("hid-pak-text").value = "";
wm.switchDisabled($("hid-pak-text"), false); wm.switchEnabled($("hid-pak-text"), true);
wm.switchDisabled($("hid-pak-button"), false); wm.switchEnabled($("hid-pak-button"), true);
$("hid-pak-led").className = "led-gray"; $("hid-pak-led").className = "led-gray";
$("hid-pak-led").title = ""; $("hid-pak-led").title = "";
} }

View File

@ -97,7 +97,7 @@ export function Msd() {
__applyState(); __applyState();
}); });
__applyState(); __applyState();
wm.switchDisabled($(`msd-${action}-button`), true); wm.switchEnabled($(`msd-${action}-button`), false);
}; };
var __selectNewImageFile = function() { var __selectNewImageFile = function() {
@ -181,17 +181,17 @@ export function Msd() {
$("msd-storage-progress-value").style.width = "0%"; $("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) { 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 { } 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.switchEnabled($("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.switchEnabled($("msd-select-new-image-button"), (__state.online && !__state.drive.connected && !__upload_http && !__state.busy));
wm.switchDisabled($("msd-upload-new-image-button"), (!__state.online || __state.drive.connected || __state.busy || !__image_file)); wm.switchEnabled($("msd-upload-new-image-button"), (__state.online && !__state.drive.connected && __image_file && !__state.busy));
wm.switchDisabled($("msd-abort-uploading-button"), (!__state.online || !__upload_http)); wm.switchEnabled($("msd-abort-uploading-button"), (__state.online && __upload_http));
wm.switchDisabled($("msd-reset-button"), (!__state.enabled || __state.busy)); wm.switchEnabled($("msd-reset-button"), (__state.enabled && !__state.busy));
$("msd-emulate-cdrom-checkbox").checked = (__state.online && __state.features.cdrom && __state.drive.cdrom); $("msd-emulate-cdrom-checkbox").checked = (__state.online && __state.features.cdrom && __state.drive.cdrom);
$("msd-new-image").style.display = (__image_file ? "block" : "none"); $("msd-new-image").style.display = (__image_file ? "block" : "none");
@ -211,13 +211,13 @@ export function Msd() {
$("msd-drive-image-size").innerHTML = ""; $("msd-drive-image-size").innerHTML = "";
$("msd-storage-size").innerHTML = ""; $("msd-storage-size").innerHTML = "";
wm.switchDisabled($("msd-emulate-cdrom-checkbox"), true); wm.switchEnabled($("msd-emulate-cdrom-checkbox"), false);
wm.switchDisabled($("msd-connect-button"), true); wm.switchEnabled($("msd-connect-button"), false);
wm.switchDisabled($("msd-disconnect-button"), true); wm.switchEnabled($("msd-disconnect-button"), false);
wm.switchDisabled($("msd-select-new-image-button"), true); wm.switchEnabled($("msd-select-new-image-button"), false);
wm.switchDisabled($("msd-upload-new-image-button"), true); wm.switchEnabled($("msd-upload-new-image-button"), false);
wm.switchDisabled($("msd-abort-uploading-button"), true); wm.switchEnabled($("msd-abort-uploading-button"), false);
wm.switchDisabled($("msd-reset-button"), true); wm.switchEnabled($("msd-reset-button"), false);
$("msd-emulate-cdrom-checkbox").checked = false; $("msd-emulate-cdrom-checkbox").checked = false;
$("msd-select-new-image-file").value = ""; $("msd-select-new-image-file").value = "";

View File

@ -72,7 +72,7 @@ export function Streamer() {
state = state.state; state = state.state;
if (!$("stream-quality-slider").activated) { 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) { if ($("stream-quality-slider").value !== state.encoder.quality) {
$("stream-quality-slider").value = state.encoder.quality; $("stream-quality-slider").value = state.encoder.quality;
__updateQualityValue(state.encoder.quality); __updateQualityValue(state.encoder.quality);
@ -81,7 +81,7 @@ export function Streamer() {
if (!$("stream-desired-fps-slider").activated) { if (!$("stream-desired-fps-slider").activated) {
$("stream-desired-fps-slider").max = max_fps; $("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) { if ($("stream-desired-fps-slider").value !== state.source.desired_fps) {
$("stream-desired-fps-slider").value = state.source.desired_fps; $("stream-desired-fps-slider").value = state.source.desired_fps;
__updateDesiredFpsValue(state.source.desired_fps); __updateDesiredFpsValue(state.source.desired_fps);
@ -103,8 +103,8 @@ export function Streamer() {
if (__ensureStream(state.stream.clients_stat)) { if (__ensureStream(state.stream.clients_stat)) {
$("stream-led").className = "led-green"; $("stream-led").className = "led-green";
$("stream-led").title = "Stream is active"; $("stream-led").title = "Stream is active";
wm.switchDisabled($("stream-screenshot-button"), false); wm.switchEnabled($("stream-screenshot-button"), true);
wm.switchDisabled($("stream-reset-button"), false); wm.switchEnabled($("stream-reset-button"), true);
$("stream-quality-slider").activated = false; $("stream-quality-slider").activated = false;
$("stream-desired-fps-slider").activated = false; $("stream-desired-fps-slider").activated = false;
tools.info("Stream: active"); tools.info("Stream: active");
@ -115,10 +115,10 @@ export function Streamer() {
} else { } else {
$("stream-led").className = "led-gray"; $("stream-led").className = "led-gray";
$("stream-led").title = "Stream inactive"; $("stream-led").title = "Stream inactive";
wm.switchDisabled($("stream-screenshot-button"), true); wm.switchEnabled($("stream-screenshot-button"), false);
wm.switchDisabled($("stream-reset-button"), true); wm.switchEnabled($("stream-reset-button"), false);
wm.switchDisabled($("stream-quality-slider"), true); wm.switchEnabled($("stream-quality-slider"), false);
wm.switchDisabled($("stream-desired-fps-slider"), true); wm.switchEnabled($("stream-desired-fps-slider"), false);
tools.info("Stream: inactive"); tools.info("Stream: inactive");
__updateStreamWindow(false, false); __updateStreamWindow(false, false);

View File

@ -62,18 +62,18 @@ function __login() {
} }
} }
}, body, "application/x-www-form-urlencoded"); }, body, "application/x-www-form-urlencoded");
__setDisabled(true); __setEnabled(false);
} }
} }
function __setDisabled(disabled) { function __setEnabled(enabled) {
wm.switchDisabled($("user-input"), disabled); wm.switchEnabled($("user-input"), enabled);
wm.switchDisabled($("passwd-input"), disabled); wm.switchEnabled($("passwd-input"), enabled);
wm.switchDisabled($("login-button"), disabled); wm.switchEnabled($("login-button"), enabled);
} }
function __tryAgain() { function __tryAgain() {
__setDisabled(false); __setEnabled(true);
$("passwd-input").focus(); $("passwd-input").focus();
$("passwd-input").select(); $("passwd-input").select();
} }

View File

@ -156,8 +156,8 @@ function __WindowManager() {
return promise; return promise;
}; };
self.switchDisabled = function(el, disabled) { self.switchEnabled = function(el, enabled) {
if (disabled && document.activeElement === el) { if (!enabled && document.activeElement === el) {
let el_to_focus = ( let el_to_focus = (
el.closest(".modal-window") el.closest(".modal-window")
|| el.closest(".window") || el.closest(".window")
@ -167,7 +167,7 @@ function __WindowManager() {
el_to_focus.focus(); el_to_focus.focus();
} }
} }
el.disabled = disabled; el.disabled = !enabled;
}; };
self.showWindow = function(el_window, activate=true, center=false) { self.showWindow = function(el_window, activate=true, center=false) {