104 lines
3.5 KiB
JavaScript
104 lines
3.5 KiB
JavaScript
function httpGetAsync(url, data, callback) {
|
|
const xmlHttp = new XMLHttpRequest();
|
|
xmlHttp.onreadystatechange = function () {
|
|
if (this.readyState === 4) {
|
|
if (this.status !== 401) {
|
|
clearTimeout(timeout);
|
|
timeout = startTimeout();
|
|
}
|
|
callback(xmlHttp.responseText, xmlHttp.status);
|
|
}
|
|
}
|
|
|
|
xmlHttp.open("GET", url, true);
|
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
|
xmlHttp.send(null);
|
|
}
|
|
|
|
function httpPostAsync(url, data, callback) {
|
|
const xmlHttp = new XMLHttpRequest();
|
|
xmlHttp.onreadystatechange = function () {
|
|
if (this.readyState === 4) {
|
|
callback(xmlHttp.responseText, xmlHttp.status);
|
|
}
|
|
}
|
|
|
|
xmlHttp.open("POST", url, true);
|
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
|
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
xmlHttp.send(data);
|
|
}
|
|
|
|
function httpUploadAsync(url, data, callback) {
|
|
const xmlHttp = new XMLHttpRequest();
|
|
xmlHttp.onreadystatechange = function () {
|
|
if (this.readyState === 4) {
|
|
callback(xmlHttp.responseText, xmlHttp.status);
|
|
}
|
|
}
|
|
|
|
xmlHttp.upload.addEventListener("progress",function(event){
|
|
let progressBar = document.getElementById("upload_progress");
|
|
let progress = (event.loaded/event.total)*100;
|
|
progressBar.value = progress;
|
|
console.log(progress)
|
|
});
|
|
|
|
xmlHttp.open("POST", url, true);
|
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
|
xmlHttp.send(data);
|
|
}
|
|
|
|
function httpDeleteAsync(url, data, callback) {
|
|
const xmlHttp = new XMLHttpRequest();
|
|
xmlHttp.onreadystatechange = function () {
|
|
if (this.readyState === 4) {
|
|
callback(xmlHttp.responseText, xmlHttp.status);
|
|
}
|
|
}
|
|
|
|
xmlHttp.open("DELETE", url, true);
|
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
|
xmlHttp.send();
|
|
}
|
|
|
|
function startTimeout() {
|
|
return setTimeout(function () {
|
|
sessionStorage.removeItem('authorization');
|
|
document.getElementById('logout').remove();
|
|
document.getElementById('context_menu').parentElement.remove();
|
|
create_login_view();
|
|
}, 600000);
|
|
}
|
|
|
|
function findGetParameter(parameterName) {
|
|
let result = null,
|
|
tmp = [];
|
|
location.search
|
|
.substr(1)
|
|
.split("&")
|
|
.forEach(function (item) {
|
|
tmp = item.split("=");
|
|
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
|
|
});
|
|
return result;
|
|
}
|
|
|
|
function get_random_id() {
|
|
let s4 = function () {
|
|
return Math.floor((1 + Math.random()) * 0x10000)
|
|
.toString(16)
|
|
.substring(1);
|
|
}
|
|
|
|
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
|
|
}
|
|
|
|
function try_to_parse_error(message) {
|
|
try {
|
|
message = JSON.parse(message);
|
|
create_error_view(message['error'] + ` <span onclick="this.parentElement.children[1].click(); window.history.pushState('index', 'Filemanager', 'index.html?path='); path_changed();">Return to root directory</span>`);
|
|
} catch (e) {
|
|
create_error_view(`Unrecoverable error! <span onclick="this.parentElement.children[1].click(); window.history.pushState('index', 'Filemanager', 'index.html?path='); path_changed();">Return to root directory</span>`);
|
|
}
|
|
} |