refactoring

This commit is contained in:
Devaev Maxim 2020-12-25 05:09:52 +03:00
parent dd4c797d26
commit 3ae6f3f881
13 changed files with 78 additions and 78 deletions

View File

@ -143,8 +143,8 @@
<td>Auto-resize stream window:</td>
<td align="right">
<div class="switch-box">
<input checked type="checkbox" id="stream-auto-resize-checkbox">
<label for="stream-auto-resize-checkbox"><span class="switch-inner"></span><span class="switch"></span></label>
<input checked type="checkbox" id="stream-auto-resize-switch">
<label for="stream-auto-resize-switch"><span class="switch-inner"></span><span class="switch"></span></label>
</div>
</td>
</table>
@ -177,8 +177,8 @@
<td>Squash relative mouse moves:</td>
<td align="right">
<div class="switch-box">
<input checked type="checkbox" id="hid-mouse-squash-checkbox">
<label for="hid-mouse-squash-checkbox"><span class="switch-inner"></span><span class="switch"></span></label>
<input checked type="checkbox" id="hid-mouse-squash-switch">
<label for="hid-mouse-squash-switch"><span class="switch-inner"></span><span class="switch"></span></label>
</div>
</td>
</table>
@ -189,8 +189,8 @@
<td>Connect HID to Server:</td>
<td align="right">
<div class="switch-box">
<input checked type="checkbox" id="hid-connect-checkbox">
<label for="hid-connect-checkbox"><span class="switch-inner"></span><span class="switch"></span></label>
<input checked type="checkbox" id="hid-connect-switch">
<label for="hid-connect-switch"><span class="switch-inner"></span><span class="switch"></span></label>
</div>
</td>
</table>
@ -404,8 +404,8 @@
<td>Infinite loop playback:</td>
<td align="right">
<div class="switch-box">
<input disabled type="checkbox" id="hid-recorder-loop-checkbox">
<label for="hid-recorder-loop-checkbox"><span class="switch-inner"></span><span class="switch"></span></label>
<input disabled type="checkbox" id="hid-recorder-loop-switch">
<label for="hid-recorder-loop-switch"><span class="switch-inner"></span><span class="switch"></span></label>
</div>
</td>
</table>

View File

@ -22,7 +22,7 @@ li(class="right")
td(id="hid-recorder-events-count" class="value") 0
td #[sup #[i include delays]]
hr
+menu_switch("hid-recorder-loop-checkbox", "Infinite loop playback", false, false)
+menu_switch("hid-recorder-loop-switch", "Infinite loop playback", false, false)
hr
input(type="file" id="hid-recorder-new-script-file")
div(class="buttons buttons-row")

View File

@ -27,7 +27,7 @@ li(class="right")
td #[input(type="range" id="stream-size-slider" class="slider")]
td(id="stream-size-value" class="value" style="width: 4em") 100%
hr
+menu_switch("stream-auto-resize-checkbox", "Auto-resize stream window", true, true)
+menu_switch("stream-auto-resize-switch", "Auto-resize stream window", true, true)
hr
div(class="buttons buttons-row")
button(data-force-hide-menu id="show-stream-button" class="row33") &bull; Show stream
@ -44,10 +44,10 @@ li(class="right")
td #[div(id="hid-outputs-mouse" class="radio-box")]
div(id="hid-mouse-squash" class="feature-disabled")
hr
+menu_switch("hid-mouse-squash-checkbox", "Squash relative mouse moves", true, true)
+menu_switch("hid-mouse-squash-switch", "Squash relative mouse moves", true, true)
div(id="hid-connect" class="feature-disabled")
hr
+menu_switch("hid-connect-checkbox", "Connect HID to Server", true, true)
+menu_switch("hid-connect-switch", "Connect HID to Server", true, true)
hr
div(class="buttons buttons-row")
button(data-force-hide-menu id="show-keyboard-button" class="row50") &bull; Show keyboard

View File

@ -59,7 +59,7 @@ export function Atx() {
$("atx-hdd-led").className = "led-gray";
}
for (let id of ["atx-power-button", "atx-power-button-long", "atx-reset-button"]) {
wm.switchEnabled($(id), buttons_enabled);
wm.setElementEnabled($(id), buttons_enabled);
}
};

View File

@ -48,7 +48,7 @@ export function Gpio() {
for (let type of ["switch", "button"]) {
let el = $(`gpio-${type}-${channel}`);
if (el) {
wm.switchEnabled(el, state.outputs[channel].online && !state.outputs[channel].busy);
wm.setElementEnabled(el, state.outputs[channel].online && !state.outputs[channel].busy);
}
}
let el = $(`gpio-switch-${channel}`);
@ -62,7 +62,7 @@ export function Gpio() {
}
for (let selector of [".gpio-switch", ".gpio-button"]) {
for (let el of $$$(selector)) {
wm.switchEnabled(el, false);
wm.setElementEnabled(el, false);
}
}
}

View File

@ -75,7 +75,7 @@ export function Hid() {
window.addEventListener("blur", __releaseAll);
tools.setOnClick($("hid-pak-button"), __clickPasteAsKeysButton);
tools.setOnClick($("hid-connect-checkbox"), __clickConnectCheckbox);
tools.setOnClick($("hid-connect-switch"), __clickConnectSwitch);
tools.setOnClick($("hid-reset-button"), __clickResetButton);
for (let el_shortcut of $$$("[data-shortcut]")) {
@ -86,9 +86,9 @@ export function Hid() {
/************************************************************************/
self.setSocket = function(ws) {
wm.switchEnabled($("hid-pak-text"), ws);
wm.switchEnabled($("hid-pak-button"), ws);
wm.switchEnabled($("hid-reset-button"), ws);
wm.setElementEnabled($("hid-pak-text"), ws);
wm.setElementEnabled($("hid-pak-button"), ws);
wm.setElementEnabled($("hid-reset-button"), ws);
if (!ws) {
self.setState(null);
}
@ -148,13 +148,13 @@ export function Hid() {
tools.featureSetEnabled($("hid-outputs"), has_outputs);
tools.featureSetEnabled($("hid-mouse-squash"), has_relative);
tools.featureSetEnabled($("hid-connect"), (state.connected !== null));
$("hid-connect-checkbox").checked = !!state.connected;
$("hid-connect-switch").checked = !!state.connected;
}
wm.switchRadioEnabled("hid-outputs-keyboard-radio", (state && state.online && !state.busy));
wm.switchRadioEnabled("hid-outputs-mouse-radio", (state && state.online && !state.busy));
wm.switchEnabled($("hid-mouse-squash-checkbox"), (has_relative_squash && !state.busy));
wm.switchEnabled($("hid-connect-checkbox"), (state && state.online && !state.busy));
wm.setRadioEnabled("hid-outputs-keyboard-radio", (state && state.online && !state.busy));
wm.setRadioEnabled("hid-outputs-mouse-radio", (state && state.online && !state.busy));
wm.setElementEnabled($("hid-mouse-squash-switch"), (has_relative_squash && !state.busy));
wm.setElementEnabled($("hid-connect-switch"), (state && state.online && !state.busy));
if (state) {
__keyboard.setState(state.keyboard, state.online, state.busy);
@ -203,15 +203,15 @@ export function Hid() {
wm.confirm(confirm_msg).then(function(ok) {
if (ok) {
wm.switchEnabled($("hid-pak-text"), false);
wm.switchEnabled($("hid-pak-button"), false);
wm.setElementEnabled($("hid-pak-text"), false);
wm.setElementEnabled($("hid-pak-button"), false);
tools.debug("HID: paste-as-keys:", text);
let http = tools.makeRequest("POST", "/api/hid/print?limit=0", function() {
if (http.readyState === 4) {
wm.switchEnabled($("hid-pak-text"), true);
wm.switchEnabled($("hid-pak-button"), true);
wm.setElementEnabled($("hid-pak-text"), true);
wm.setElementEnabled($("hid-pak-button"), true);
$("hid-pak-text").value = "";
if (http.status === 413) {
wm.error("Too many text for paste!");
@ -240,8 +240,8 @@ export function Hid() {
});
};
var __clickConnectCheckbox = function() {
let connected = $("hid-connect-checkbox").checked;
var __clickConnectSwitch = function() {
let connected = $("hid-connect-switch").checked;
let http = tools.makeRequest("POST", `/api/hid/set_connected?connected=${connected}`, function() {
if (http.readyState === 4) {
if (http.status !== 200) {

View File

@ -141,7 +141,7 @@ export function Mouse(record_callback) {
};
var __isRelativeSquashed = function() {
return $("hid-mouse-squash-checkbox").checked;
return $("hid-mouse-squash-switch").checked;
};
var __relativeCapturedHandler = function() {

View File

@ -64,8 +64,8 @@ export function Msd() {
};
var __selectImage = function() {
wm.switchEnabled($("msd-image-selector"), false);
wm.switchEnabled($("msd-remove-image"), false);
wm.setElementEnabled($("msd-image-selector"), false);
wm.setElementEnabled($("msd-remove-image"), false);
__sendParam("image", $("msd-image-selector").value);
};
@ -148,7 +148,7 @@ export function Msd() {
__applyState();
});
__applyState();
wm.switchEnabled($(`msd-${connected ? "connect" : "disconnect"}-button`), false);
wm.setElementEnabled($(`msd-${connected ? "connect" : "disconnect"}-button`), false);
};
var __selectNewImageFile = function() {
@ -217,23 +217,23 @@ export function Msd() {
tools.progressSetValue($("msd-storage-progress"), "Storage: unavailable", 0);
}
wm.switchEnabled($("msd-image-selector"), (__state.online && __state.features.multi && !__state.drive.connected && !__state.busy));
wm.setElementEnabled($("msd-image-selector"), (__state.online && __state.features.multi && !__state.drive.connected && !__state.busy));
if (__state.features.multi && !__state.storage.uploading) {
__refreshImageSelector();
}
wm.switchEnabled($("msd-remove-image"), (__state.online && __state.features.multi && __state.drive.image && !__state.drive.connected && !__state.busy));
wm.setElementEnabled($("msd-remove-image"), (__state.online && __state.features.multi && __state.drive.image && !__state.drive.connected && !__state.busy));
wm.switchRadioEnabled("msd-mode-radio", (__state.online && __state.features.cdrom && !__state.drive.connected && !__state.busy));
wm.setRadioEnabled("msd-mode-radio", (__state.online && __state.features.cdrom && !__state.drive.connected && !__state.busy));
tools.radioSetValue("msd-mode-radio", `${Number(__state.online && __state.features.cdrom && __state.drive.cdrom)}`);
wm.switchEnabled($("msd-connect-button"), (__state.online && (!__state.features.multi || __state.drive.image) && !__state.drive.connected && !__state.busy));
wm.switchEnabled($("msd-disconnect-button"), (__state.online && __state.drive.connected && !__state.busy));
wm.setElementEnabled($("msd-connect-button"), (__state.online && (!__state.features.multi || __state.drive.image) && !__state.drive.connected && !__state.busy));
wm.setElementEnabled($("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.setElementEnabled($("msd-select-new-image-button"), (__state.online && !__state.drive.connected && !__upload_http && !__state.busy));
wm.setElementEnabled($("msd-upload-new-image-button"), (__state.online && !__state.drive.connected && __image_file && !__state.busy));
wm.setElementEnabled($("msd-abort-uploading-button"), (__state.online && __upload_http));
wm.switchEnabled($("msd-reset-button"), (__state.enabled && !__state.busy));
wm.setElementEnabled($("msd-reset-button"), (__state.enabled && !__state.busy));
tools.hiddenSetVisible($("msd-submenu-new-image"), __image_file);
$("msd-new-image-name").innerHTML = (__image_file ? __image_file.name : "");
@ -256,21 +256,21 @@ export function Msd() {
$("msd-storage-size").innerHTML = "";
tools.progressSetValue($("msd-storage-progress"), "", 0);
wm.switchEnabled($("msd-image-selector"), false);
wm.setElementEnabled($("msd-image-selector"), false);
$("msd-image-selector").options.length = 1;
wm.switchEnabled($("msd-remove-image"), false);
wm.setElementEnabled($("msd-remove-image"), false);
wm.switchRadioEnabled("msd-mode-radio", false);
wm.setRadioEnabled("msd-mode-radio", false);
tools.radioSetValue("msd-mode-radio", "0");
wm.switchEnabled($("msd-connect-button"), false);
wm.switchEnabled($("msd-disconnect-button"), false);
wm.setElementEnabled($("msd-connect-button"), false);
wm.setElementEnabled($("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.setElementEnabled($("msd-select-new-image-button"), false);
wm.setElementEnabled($("msd-upload-new-image-button"), false);
wm.setElementEnabled($("msd-abort-uploading-button"), false);
wm.switchEnabled($("msd-reset-button"), false);
wm.setElementEnabled($("msd-reset-button"), false);
$("msd-select-new-image-file").value = "";
tools.hiddenSetVisible($("msd-submenu-new-image"), false);

View File

@ -222,7 +222,7 @@ export function Recorder() {
}
index += 1;
}
if ($("hid-recorder-loop-checkbox").checked) {
if ($("hid-recorder-loop-switch").checked) {
setTimeout(() => __runEvents(0));
} else {
__stopProcess();
@ -241,14 +241,14 @@ export function Recorder() {
$("hid-recorder-led").title = "";
}
wm.switchEnabled($("hid-recorder-record"), (__ws && !__play_timer && !__recording));
wm.switchEnabled($("hid-recorder-stop"), (__ws && (__play_timer || __recording)));
wm.switchEnabled($("hid-recorder-play"), (__ws && !__recording && __events.length));
wm.switchEnabled($("hid-recorder-clear"), (!__play_timer && !__recording && __events.length));
wm.switchEnabled($("hid-recorder-loop-checkbox"), (__ws && !__recording));
wm.setElementEnabled($("hid-recorder-record"), (__ws && !__play_timer && !__recording));
wm.setElementEnabled($("hid-recorder-stop"), (__ws && (__play_timer || __recording)));
wm.setElementEnabled($("hid-recorder-play"), (__ws && !__recording && __events.length));
wm.setElementEnabled($("hid-recorder-clear"), (!__play_timer && !__recording && __events.length));
wm.setElementEnabled($("hid-recorder-loop-switch"), (__ws && !__recording));
wm.switchEnabled($("hid-recorder-upload"), (!__play_timer && !__recording));
wm.switchEnabled($("hid-recorder-download"), (!__play_timer && !__recording && __events.length));
wm.setElementEnabled($("hid-recorder-upload"), (!__play_timer && !__recording));
wm.setElementEnabled($("hid-recorder-download"), (!__play_timer && !__recording && __events.length));
__setCounters(__events.length, __events_time);
};

View File

@ -90,7 +90,7 @@ export function Streamer() {
if (state && state.streamer) {
if (!$("stream-quality-slider").activated) {
wm.switchEnabled($("stream-quality-slider"), true);
wm.setElementEnabled($("stream-quality-slider"), true);
if ($("stream-quality-slider").value !== state.streamer.encoder.quality) {
$("stream-quality-slider").value = state.streamer.encoder.quality;
__updateQualityValue(state.streamer.encoder.quality);
@ -99,7 +99,7 @@ export function Streamer() {
if (!$("stream-desired-fps-slider").activated) {
$("stream-desired-fps-slider").max = state.limits.max_fps;
wm.switchEnabled($("stream-desired-fps-slider"), true);
wm.setElementEnabled($("stream-desired-fps-slider"), true);
if ($("stream-desired-fps-slider").value !== state.streamer.source.desired_fps) {
$("stream-desired-fps-slider").value = state.streamer.source.desired_fps;
__updateDesiredFpsValue(state.streamer.source.desired_fps);
@ -112,7 +112,7 @@ export function Streamer() {
) {
__resolution = state.streamer.source.resolution;
__resolution_str = `${__resolution.width}x${__resolution.height}`;
if ($("stream-auto-resize-checkbox").checked) {
if ($("stream-auto-resize-switch").checked) {
__adjustSizeFactor();
} else {
__applySizeFactor();
@ -132,14 +132,14 @@ export function Streamer() {
$("stream-resolution-selector").resolutions = state.limits.available_resolutions;
}
document.querySelector(`#stream-resolution-selector [value="${__resolution_str}"]`).selected = true;
wm.switchEnabled($("stream-resolution-selector"), true);
wm.setElementEnabled($("stream-resolution-selector"), true);
}
if (__ensureStream(state.streamer.stream.clients_stat)) {
$("stream-led").className = "led-green";
$("stream-led").title = "Stream is active";
wm.switchEnabled($("stream-screenshot-button"), true);
wm.switchEnabled($("stream-reset-button"), true);
wm.setElementEnabled($("stream-screenshot-button"), true);
wm.setElementEnabled($("stream-reset-button"), true);
$("stream-quality-slider").activated = false;
$("stream-desired-fps-slider").activated = false;
@ -155,11 +155,11 @@ export function Streamer() {
$("stream-led").className = "led-gray";
$("stream-led").title = "Stream inactive";
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);
wm.switchEnabled($("stream-resolution-selector"), false);
wm.setElementEnabled($("stream-screenshot-button"), false);
wm.setElementEnabled($("stream-reset-button"), false);
wm.setElementEnabled($("stream-quality-slider"), false);
wm.setElementEnabled($("stream-desired-fps-slider"), false);
wm.setElementEnabled($("stream-resolution-selector"), false);
__updateStreamWindow(false, false);
}

View File

@ -45,7 +45,7 @@ export function WakeOnLan() {
tools.featureSetEnabled($("wol"), state.enabled);
__target = state.target;
}
wm.switchEnabled($("wol-wakeup-button"), (state && state.enabled));
wm.setElementEnabled($("wol-wakeup-button"), (state && state.enabled));
};
var __clickWakeupButton = function() {

View File

@ -75,9 +75,9 @@ function __login() {
}
function __setEnabled(enabled) {
wm.switchEnabled($("user-input"), enabled);
wm.switchEnabled($("passwd-input"), enabled);
wm.switchEnabled($("login-button"), enabled);
wm.setElementEnabled($("user-input"), enabled);
wm.setElementEnabled($("passwd-input"), enabled);
wm.setElementEnabled($("login-button"), enabled);
}
function __tryAgain() {

View File

@ -162,7 +162,7 @@ function __WindowManager() {
return promise;
};
self.switchEnabled = function(el, enabled) {
self.setElementEnabled = function(el, enabled) {
if (!enabled && document.activeElement === el) {
let el_to_focus = (
el.closest(".modal-window")
@ -176,9 +176,9 @@ function __WindowManager() {
el.disabled = !enabled;
};
self.switchRadioEnabled = function(name, enabled) {
self.setRadioEnabled = function(name, enabled) {
for (let el of $$$(`input[type="radio"][name="${name}"]`)) {
self.switchEnabled(el, enabled);
self.setElementEnabled(el, enabled);
}
};