New and updated version of old code.
This commit is contained in:
79
js/appControl.js
Normal file
79
js/appControl.js
Normal file
@@ -0,0 +1,79 @@
|
||||
function discoverScanners(attemptID)
|
||||
{
|
||||
var xhttp = new XMLHttpRequest();
|
||||
|
||||
xhttp.onreadystatechange = function()
|
||||
{
|
||||
if (this.readyState == 4 && this.status == 200)
|
||||
{
|
||||
if(this.responseText == "OK")
|
||||
{
|
||||
location.href = "interface.php";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("[Scanner discovery(attempt " + attemptID + ")] Failed with message: " + this.responseText);
|
||||
setTimeout(discoverScanners, 2000, ++attemptID);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
xhttp.open("GET", "api/discoverScanners.php", true);
|
||||
xhttp.send();
|
||||
|
||||
if(attemptID > 3)
|
||||
{
|
||||
var progressBarElement = document.getElementById("scannerSearchProgress");
|
||||
progressBarElement.innerHTML = '<div class="progress-bar progress-bar-striped progress-bar-animated bg-warning" style="width: 100%; color: black;">Attempt ' + attemptID + '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function scannersDiscoveryController()
|
||||
{
|
||||
var progressBarElement = document.getElementById("scannerSearchProgress");
|
||||
if(progressBarElement != null) progressBarElement.innerHTML = '<div class="progress-bar progress-bar-striped progress-bar-animated" style="width: 100%"></div>';
|
||||
else return;
|
||||
|
||||
discoverScanners(1);
|
||||
}
|
||||
|
||||
function scanImage()
|
||||
{
|
||||
const scanningAnimationModal = new bootstrap.Modal(document.getElementById('scanningAnimationModal'));
|
||||
|
||||
var deviceID = document.getElementById("deviceIDFormSelect").value;
|
||||
var outputImageResolution = document.getElementById("outputImageResolutionFormSelect").value;
|
||||
var outputImageColorDepth = document.getElementById("outputImageColorDepthFormSelect").value;
|
||||
var outputFileFormat = document.getElementById("outputFileFormatFormSelect").value;
|
||||
var inputPageSize = document.getElementById("inputPageSizeFormSelect").value;
|
||||
|
||||
var xhttp = new XMLHttpRequest();
|
||||
|
||||
xhttp.onreadystatechange = function()
|
||||
{
|
||||
// TODO / DEBUG - Enable this
|
||||
if (this.readyState == 4 && this.status == 200)
|
||||
{
|
||||
var scannedFileName = this.responseText;
|
||||
|
||||
var scannedImagePreview = document.getElementById("scanPreview");
|
||||
scannedImagePreview.src = "api/imageDownload.php?filename=" + scannedFileName;
|
||||
scannedImagePreview.alt = scannedFileName;
|
||||
|
||||
var scannedImageDownloadButton = document.getElementById("scannedImageDownloadButton");
|
||||
scannedImageDownloadButton.href = "api/imageDownload.php?filename=" + scannedFileName;
|
||||
scannedImageDownloadButton.style = "display: block;";
|
||||
|
||||
scanningAnimationModal.hide();
|
||||
}
|
||||
};
|
||||
|
||||
xhttp.open("GET", "api/scan.php?outputImageResolution=" + outputImageResolution + "&outputImageColorDepth=" + outputImageColorDepth + "&outputFileFormat=" + outputFileFormat + "&inputPageSize=" + inputPageSize + "&deviceID=" + deviceID, true);
|
||||
xhttp.send();
|
||||
|
||||
scanningAnimationModal.show();
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener("DOMContentLoaded", (event) => { scannersDiscoveryController(); });
|
||||
Reference in New Issue
Block a user