preparing to otg

This commit is contained in:
Devaev Maxim
2019-09-24 00:03:31 +03:00
parent 661828502e
commit aee005787c
9 changed files with 95 additions and 110 deletions

View File

@@ -221,7 +221,7 @@
<div id="msd-new-image" class="msd-message">
<table class="msd-info">
<tr>
<td>New name:</td>
<td>New image:</td>
<td id="msd-new-image-name" class="msd-info-value"></td>
</tr>
<tr>
@@ -239,8 +239,8 @@
</div>
<div class="menu-item-content-buttons buttons-row">
<button disabled data-force-hide-menu id="msd-switch-to-kvm-button" class="row50">&bull; Switch drive to KVM</button>
<button disabled data-force-hide-menu id="msd-switch-to-server-button" class="row50">&bull; Switch drive to Server</button>
<button disabled data-force-hide-menu id="msd-connect-button" class="row50">&bull; Connect drive to Server</button>
<button disabled data-force-hide-menu id="msd-disconnect-button" class="row50">&bull; Disconnect drive</button>
</div>
</div>
</li>

View File

@@ -45,8 +45,8 @@ export function Msd() {
tools.setOnClick($("msd-upload-new-image-button"), __clickUploadNewImageButton);
tools.setOnClick($("msd-abort-uploading-button"), __clickAbortUploadingButton);
tools.setOnClick($("msd-switch-to-kvm-button"), () => __clickSwitchButton("kvm"));
tools.setOnClick($("msd-switch-to-server-button"), () => __clickSwitchButton("server"));
tools.setOnClick($("msd-connect-button"), () => __clickConnectButton(true));
tools.setOnClick($("msd-disconnect-button"), () => __clickConnectButton(false));
tools.setOnClick($("msd-reset-button"), __clickResetButton);
};
@@ -80,8 +80,9 @@ export function Msd() {
$("msd-progress-value").style.width = "0%";
};
var __clickSwitchButton = function(to) {
let http = tools.makeRequest("POST", "/api/msd/connect?to=" + to, function() {
var __clickConnectButton = function(connect) {
let action = (connect ? "connect" : "disconnect");
let http = tools.makeRequest("POST", `/api/msd/${action}`, function() {
if (http.readyState === 4) {
if (http.status !== 200) {
wm.error("Switch error:<br>", http.responseText);
@@ -90,14 +91,14 @@ export function Msd() {
__applyState();
});
__applyState();
wm.switchDisabled($(`msd-switch-to-${to}-button`), true);
wm.switchDisabled($(`msd-${action}-button`), true);
};
var __selectNewImageFile = function() {
let el_input = $("msd-select-new-image-file");
let image_file = (el_input.files.length ? el_input.files[0] : null);
if (image_file && image_file.size > __state.info.size) {
wm.error("New image is too big for your Mass Storage Device.<br>Maximum:", __formatSize(__state.info.size));
if (image_file && image_file.size > __state.storage.size) {
wm.error("New image is too big for your Mass Storage Device.<br>Maximum:", __formatSize(__state.storage.size));
el_input.value = "";
image_file = null;
}
@@ -131,7 +132,7 @@ export function Msd() {
$("msd-reset-button").classList.add("feature-disabled");
}
if (__state.connected_to === "server") {
if (__state.connected) {
$("msd-another-another-user-uploads").style.display = "none";
$("msd-led").className = "led-green";
$("msd-status").innerHTML = $("msd-led").title = "Connected to Server";
@@ -145,7 +146,7 @@ export function Msd() {
$("msd-another-another-user-uploads").style.display = "none";
$("msd-led").className = "led-gray";
if (__state.online) {
$("msd-status").innerHTML = $("msd-led").title = "Connected to KVM";
$("msd-status").innerHTML = $("msd-led").title = "Disconnected";
} else {
$("msd-status").innerHTML = $("msd-led").title = "Unavailable";
}
@@ -153,18 +154,18 @@ export function Msd() {
$("msd-offline").style.display = (__state.online ? "none" : "block");
$("msd-current-image-broken").style.display = (
__state.online && __state.info.image &&
!__state.info.image.complete && !__state.uploading ? "block" : "none"
__state.online && __state.current &&
!__state.current.complete && !__state.uploading ? "block" : "none"
);
$("msd-current-image-name").innerHTML = (__state.online && __state.info.image ? __state.info.image.name : "None");
$("msd-current-image-size").innerHTML = (__state.online && __state.info.image ? __formatSize(__state.info.image.size) : "None");
$("msd-storage-size").innerHTML = (__state.online ? __formatSize(__state.info.size) : "Unavailable");
$("msd-current-image-name").innerHTML = (__state.online && __state.current ? __state.current.name : "None");
$("msd-current-image-size").innerHTML = (__state.online && __state.current ? __formatSize(__state.current.size) : "None");
$("msd-storage-size").innerHTML = (__state.online ? __formatSize(__state.storage.size) : "Unavailable");
wm.switchDisabled($("msd-switch-to-kvm-button"), (!__state.online || __state.connected_to === "kvm" || __state.busy));
wm.switchDisabled($("msd-switch-to-server-button"), (!__state.online || __state.connected_to === "server" || __state.busy));
wm.switchDisabled($("msd-select-new-image-button"), (!__state.online || __state.connected_to !== "kvm" || __state.busy || __upload_http));
wm.switchDisabled($("msd-upload-new-image-button"), (!__state.online || __state.connected_to !== "kvm" || __state.busy || !__image_file));
wm.switchDisabled($("msd-connect-button"), (!__state.online || __state.connected || __state.busy));
wm.switchDisabled($("msd-disconnect-button"), (!__state.online || !__state.connected || __state.busy));
wm.switchDisabled($("msd-select-new-image-button"), (!__state.online || __state.connected || __state.busy || __upload_http));
wm.switchDisabled($("msd-upload-new-image-button"), (!__state.online || __state.connected || __state.busy || !__image_file));
wm.switchDisabled($("msd-abort-uploading-button"), (!__state.online || !__upload_http));
wm.switchDisabled($("msd-reset-button"), (!__state.enabled || __state.busy));
@@ -185,8 +186,8 @@ export function Msd() {
$("msd-current-image-size").innerHTML = "";
$("msd-storage-size").innerHTML = "";
wm.switchDisabled($("msd-switch-to-kvm-button"), true);
wm.switchDisabled($("msd-switch-to-server-button"), 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);