This commit is contained in:
Devaev Maxim 2018-12-01 13:08:35 +03:00
parent a6d4545baf
commit ad6a66ac8f
8 changed files with 48 additions and 48 deletions

View File

@ -6,8 +6,8 @@ globals:
Msd: true Msd: true
Session: true Session: true
Streamer: true Streamer: true
Ui: true WindowManager: true
ui: true wm: true
tools: true tools: true
checkBrowser: true checkBrowser: true
"$": true "$": true

View File

@ -18,9 +18,9 @@ function Atx() {
$("atx-power-led").className = (state.leds.power ? "led-green" : "led-gray"); $("atx-power-led").className = (state.leds.power ? "led-green" : "led-gray");
$("atx-hdd-led").className = (state.leds.hdd ? "led-red" : "led-gray"); $("atx-hdd-led").className = (state.leds.hdd ? "led-red" : "led-gray");
ui.switchDisabled($("atx-power-button"), state.busy); wm.switchDisabled($("atx-power-button"), state.busy);
ui.switchDisabled($("atx-power-button-long"), state.busy); wm.switchDisabled($("atx-power-button-long"), state.busy);
ui.switchDisabled($("atx-reset-button"), state.busy); wm.switchDisabled($("atx-reset-button"), state.busy);
}; };
self.clearState = function() { self.clearState = function() {
@ -29,14 +29,14 @@ function Atx() {
}; };
var __clickButton = function(button, confirm_msg) { var __clickButton = function(button, confirm_msg) {
ui.confirm(confirm_msg).then(function(ok) { wm.confirm(confirm_msg).then(function(ok) {
if (ok) { if (ok) {
var http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() { var http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() {
if (http.readyState === 4) { if (http.readyState === 4) {
if (http.status === 409) { if (http.status === 409) {
ui.error("Performing another ATX operation for other client.<br>Please try again later"); wm.error("Performing another ATX operation for other client.<br>Please try again later");
} else if (http.status !== 200) { } else if (http.status !== 200) {
ui.error("Click error:<br>", http.responseText); wm.error("Click error:<br>", http.responseText);
} }
} }
}); });

View File

@ -54,9 +54,9 @@ function Hid() {
/********************************************************************************/ /********************************************************************************/
self.setSocket = function(ws) { self.setSocket = function(ws) {
ui.switchDisabled($("hid-pak-text"), !ws); wm.switchDisabled($("hid-pak-text"), !ws);
ui.switchDisabled($("hid-pak-button"), !ws); wm.switchDisabled($("hid-pak-button"), !ws);
ui.switchDisabled($("hid-reset-button"), !ws); wm.switchDisabled($("hid-reset-button"), !ws);
__ws = ws; __ws = ws;
__keyboard.setSocket(ws); __keyboard.setSocket(ws);
__mouse.setSocket(ws); __mouse.setSocket(ws);
@ -152,10 +152,10 @@ function Hid() {
Are you sure you want to continue? Are you sure you want to continue?
`; `;
ui.confirm(confirm_msg).then(function(ok) { wm.confirm(confirm_msg).then(function(ok) {
if (ok) { if (ok) {
ui.switchDisabled($("hid-pak-text"), true); wm.switchDisabled($("hid-pak-text"), true);
ui.switchDisabled($("hid-pak-button"), true); wm.switchDisabled($("hid-pak-button"), true);
$("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...";
@ -169,8 +169,8 @@ function Hid() {
iterate(); iterate();
} else { } else {
$("hid-pak-text").value = ""; $("hid-pak-text").value = "";
ui.switchDisabled($("hid-pak-text"), false); wm.switchDisabled($("hid-pak-text"), false);
ui.switchDisabled($("hid-pak-button"), false); wm.switchDisabled($("hid-pak-button"), false);
$("hid-pak-led").className = "led-gray"; $("hid-pak-led").className = "led-gray";
$("hid-pak-led").title = ""; $("hid-pak-led").title = "";
} }
@ -188,7 +188,7 @@ function Hid() {
var http = tools.makeRequest("POST", "/kvmd/hid/reset", function() { var http = tools.makeRequest("POST", "/kvmd/hid/reset", function() {
if (http.readyState === 4) { if (http.readyState === 4) {
if (http.status !== 200) { if (http.status !== 200) {
ui.error("HID reset error:<br>", http.responseText); wm.error("HID reset error:<br>", http.responseText);
} }
} }
}); });

View File

@ -1,15 +1,15 @@
var ui; var wm;
function main() { function main() {
if (checkBrowser()) { if (checkBrowser()) {
ui = new Ui(); wm = new WindowManager();
tools.setOnClick($("show-about-button"), () => ui.showWindow($("about-window"))); tools.setOnClick($("show-about-button"), () => wm.showWindow($("about-window")));
tools.setOnClick($("show-keyboard-button"), () => ui.showWindow($("keyboard-window"))); tools.setOnClick($("show-keyboard-button"), () => wm.showWindow($("keyboard-window")));
tools.setOnClick($("show-stream-button"), () => ui.showWindow($("stream-window"))); tools.setOnClick($("show-stream-button"), () => wm.showWindow($("stream-window")));
tools.setOnClick($("open-log-button"), () => window.open("/kvmd/log?seek=3600&follow=1", "_blank")); tools.setOnClick($("open-log-button"), () => window.open("/kvmd/log?seek=3600&follow=1", "_blank"));
ui.showWindow($("stream-window")); wm.showWindow($("stream-window"));
new Session(); new Session();
} }

View File

@ -55,20 +55,20 @@ function Msd() {
var http = tools.makeRequest("POST", "/kvmd/msd/connect?to=" + to, function() { var http = tools.makeRequest("POST", "/kvmd/msd/connect?to=" + to, function() {
if (http.readyState === 4) { if (http.readyState === 4) {
if (http.status !== 200) { if (http.status !== 200) {
ui.error("Switch error:<br>", http.responseText); wm.error("Switch error:<br>", http.responseText);
} }
} }
__applyState(); __applyState();
}); });
__applyState(); __applyState();
ui.switchDisabled($(`msd-switch-to-${to}-button`), true); wm.switchDisabled($(`msd-switch-to-${to}-button`), true);
}; };
var __selectNewImageFile = function() { var __selectNewImageFile = function() {
var el_input = $("msd-select-new-image-file"); var el_input = $("msd-select-new-image-file");
var image_file = (el_input.files.length ? el_input.files[0] : null); var image_file = (el_input.files.length ? el_input.files[0] : null);
if (image_file && image_file.size > __state.info.size) { if (image_file && image_file.size > __state.info.size) {
ui.error("New image is too big for your Mass Storage Device.<br>Maximum:", __formatSize(__state.info.size)); wm.error("New image is too big for your Mass Storage Device.<br>Maximum:", __formatSize(__state.info.size));
el_input.value = ""; el_input.value = "";
image_file = null; image_file = null;
} }
@ -80,7 +80,7 @@ function Msd() {
var http = tools.makeRequest("POST", "/kvmd/msd/reset", function() { var http = tools.makeRequest("POST", "/kvmd/msd/reset", function() {
if (http.readyState === 4) { if (http.readyState === 4) {
if (http.status !== 200) { if (http.status !== 200) {
ui.error("MSD reset error:<br>", http.responseText); wm.error("MSD reset error:<br>", http.responseText);
} }
} }
__applyState(); __applyState();
@ -120,12 +120,12 @@ function Msd() {
$("msd-current-image-size").innerHTML = (__state.in_operate && __state.info.image ? __formatSize(__state.info.image.size) : "None"); $("msd-current-image-size").innerHTML = (__state.in_operate && __state.info.image ? __formatSize(__state.info.image.size) : "None");
$("msd-storage-size").innerHTML = (__state.in_operate ? __formatSize(__state.info.size) : "Unavailable"); $("msd-storage-size").innerHTML = (__state.in_operate ? __formatSize(__state.info.size) : "Unavailable");
ui.switchDisabled($("msd-switch-to-kvm-button"), (!__state.in_operate || __state.connected_to === "kvm" || __state.busy)); wm.switchDisabled($("msd-switch-to-kvm-button"), (!__state.in_operate || __state.connected_to === "kvm" || __state.busy));
ui.switchDisabled($("msd-switch-to-server-button"), (!__state.in_operate || __state.connected_to === "server" || __state.busy)); wm.switchDisabled($("msd-switch-to-server-button"), (!__state.in_operate || __state.connected_to === "server" || __state.busy));
ui.switchDisabled($("msd-select-new-image-button"), (!__state.in_operate || __state.connected_to !== "kvm" || __state.busy || __upload_http)); wm.switchDisabled($("msd-select-new-image-button"), (!__state.in_operate || __state.connected_to !== "kvm" || __state.busy || __upload_http));
ui.switchDisabled($("msd-upload-new-image-button"), (!__state.in_operate || __state.connected_to !== "kvm" || __state.busy || !__image_file)); wm.switchDisabled($("msd-upload-new-image-button"), (!__state.in_operate || __state.connected_to !== "kvm" || __state.busy || !__image_file));
ui.switchDisabled($("msd-abort-uploading-button"), (!__state.in_operate || !__upload_http)); wm.switchDisabled($("msd-abort-uploading-button"), (!__state.in_operate || !__upload_http));
ui.switchDisabled($("msd-reset-button"), (!__state.in_operate || __upload_http)); wm.switchDisabled($("msd-reset-button"), (!__state.in_operate || __upload_http));
$("msd-new-image").style.display = (__image_file ? "block" : "none"); $("msd-new-image").style.display = (__image_file ? "block" : "none");
$("msd-progress").setAttribute("data-label", "Waiting for upload ..."); $("msd-progress").setAttribute("data-label", "Waiting for upload ...");
@ -146,7 +146,7 @@ function Msd() {
var __uploadStateChange = function() { var __uploadStateChange = function() {
if (__upload_http.readyState === 4) { if (__upload_http.readyState === 4) {
if (__upload_http.status !== 200) { if (__upload_http.status !== 200) {
ui.error("Can't upload image to the Mass Storage Device:<br>", __upload_http.responseText); wm.error("Can't upload image to the Mass Storage Device:<br>", __upload_http.responseText);
} }
$("msd-select-new-image-file").value = ""; $("msd-select-new-image-file").value = "";
__image_file = null; __image_file = null;

View File

@ -49,7 +49,7 @@ function Streamer() {
} }
if (!$("stream-quality-slider").activated) { if (!$("stream-quality-slider").activated) {
ui.switchDisabled($("stream-quality-slider"), false); wm.switchDisabled($("stream-quality-slider"), false);
if ($("stream-quality-slider").value !== source.quality) { if ($("stream-quality-slider").value !== source.quality) {
$("stream-quality-slider").value = source.quality; $("stream-quality-slider").value = source.quality;
__updateQualityValue(source.quality); __updateQualityValue(source.quality);
@ -57,7 +57,7 @@ function Streamer() {
} }
if (!$("stream-desired-fps-slider").activated) { if (!$("stream-desired-fps-slider").activated) {
ui.switchDisabled($("stream-desired-fps-slider"), false); wm.switchDisabled($("stream-desired-fps-slider"), false);
if ($("stream-desired-fps-slider").value !== source.desired_fps) { if ($("stream-desired-fps-slider").value !== source.desired_fps) {
$("stream-desired-fps-slider").value = source.desired_fps; $("stream-desired-fps-slider").value = source.desired_fps;
__updateDesiredFpsValue(source.desired_fps); __updateDesiredFpsValue(source.desired_fps);
@ -101,8 +101,8 @@ function Streamer() {
$("stream-box").classList.remove("stream-box-inactive"); $("stream-box").classList.remove("stream-box-inactive");
$("stream-led").className = "led-green"; $("stream-led").className = "led-green";
$("stream-led").title = "Stream is active"; $("stream-led").title = "Stream is active";
ui.switchDisabled($("stream-screenshot-button"), false); wm.switchDisabled($("stream-screenshot-button"), false);
ui.switchDisabled($("stream-reset-button"), false); wm.switchDisabled($("stream-reset-button"), false);
tools.info("Stream: acquired"); tools.info("Stream: acquired");
__prev = true; __prev = true;
} }
@ -121,10 +121,10 @@ function Streamer() {
$("stream-box").classList.add("stream-box-inactive"); $("stream-box").classList.add("stream-box-inactive");
$("stream-led").className = "led-gray"; $("stream-led").className = "led-gray";
$("stream-led").title = "Stream inactive"; $("stream-led").title = "Stream inactive";
ui.switchDisabled($("stream-screenshot-button"), true); wm.switchDisabled($("stream-screenshot-button"), true);
ui.switchDisabled($("stream-reset-button"), true); wm.switchDisabled($("stream-reset-button"), true);
ui.switchDisabled($("stream-quality-slider"), true); wm.switchDisabled($("stream-quality-slider"), true);
ui.switchDisabled($("stream-desired-fps-slider"), true); wm.switchDisabled($("stream-desired-fps-slider"), true);
__client_key = tools.makeId(); __client_key = tools.makeId();
__client_id = ""; __client_id = "";
@ -165,7 +165,7 @@ function Streamer() {
var http = tools.makeRequest("POST", "/kvmd/streamer/reset", function() { var http = tools.makeRequest("POST", "/kvmd/streamer/reset", function() {
if (http.readyState === 4) { if (http.readyState === 4) {
if (http.status !== 200) { if (http.status !== 200) {
ui.error("Can't reset stream:<br>", http.responseText); wm.error("Can't reset stream:<br>", http.responseText);
} }
} }
}); });
@ -175,7 +175,7 @@ function Streamer() {
var http = tools.makeRequest("POST", `/kvmd/streamer/set_params?${name}=${value}`, function() { var http = tools.makeRequest("POST", `/kvmd/streamer/set_params?${name}=${value}`, function() {
if (http.readyState === 4) { if (http.readyState === 4) {
if (http.status !== 200) { if (http.status !== 200) {
ui.error("Can't configure stream:<br>", http.responseText); wm.error("Can't configure stream:<br>", http.responseText);
} }
} }
}); });
@ -191,7 +191,7 @@ function Streamer() {
var __adjustSizeFactor = function() { var __adjustSizeFactor = function() {
var el_window = $("stream-window"); var el_window = $("stream-window");
var el_slider = $("stream-size-slider"); var el_slider = $("stream-size-slider");
var view = ui.getViewGeometry(); var view = wm.getViewGeometry();
for (var size = 100; size >= el_slider.min; size -= el_slider.step) { for (var size = 100; size >= el_slider.min; size -= el_slider.step) {
tools.info("Stream: adjusting size:", size); tools.info("Stream: adjusting size:", size);
@ -214,7 +214,7 @@ function Streamer() {
var el_stream_image = $("stream-image"); var el_stream_image = $("stream-image");
el_stream_image.style.width = __resolution.width * __size_factor + "px"; el_stream_image.style.width = __resolution.width * __size_factor + "px";
el_stream_image.style.height = __resolution.height * __size_factor + "px"; el_stream_image.style.height = __resolution.height * __size_factor + "px";
ui.showWindow($("stream-window"), false, center); wm.showWindow($("stream-window"), false, center);
}; };
__init__(); __init__();

View File

@ -1,4 +1,4 @@
function Ui() { function WindowManager() {
var self = this; var self = this;
/********************************************************************************/ /********************************************************************************/

View File

@ -29,7 +29,7 @@
<script src="../js/bb.js"></script> <script src="../js/bb.js"></script>
<script src="../js/tools.js"></script> <script src="../js/tools.js"></script>
<script src="../js/ui.js"></script> <script src="../js/wm.js"></script>
<script src="../js/kvm/stream.js"></script> <script src="../js/kvm/stream.js"></script>
<script src="../js/kvm/atx.js"></script> <script src="../js/kvm/atx.js"></script>
<script src="../js/kvm/keyboard.js"></script> <script src="../js/kvm/keyboard.js"></script>