Rewrite some stuff
This commit is contained in:
parent
f1165f2c51
commit
ec4df02b65
104
assets/script.js
104
assets/script.js
@ -547,56 +547,33 @@ if ("loading" === document.readyState) {
|
|||||||
setTimeout(initAjax, 0);
|
setTimeout(initAjax, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadFile() {
|
async function uploadFile() {
|
||||||
const fileInput = document.getElementById('fileInput');
|
const fileInput = document.getElementById('fileInput');
|
||||||
const file = fileInput.files[0];
|
let data = {
|
||||||
let formData = new FormData();
|
action: "uploadFiles"
|
||||||
formData.append('userfile', file);
|
|
||||||
formData.append('action', 'uploadFiles');
|
|
||||||
|
|
||||||
let xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('POST', '/upload', true);
|
|
||||||
|
|
||||||
xhr.onload = function () {
|
|
||||||
const respData = JSON.parse(xhr.responseText);
|
|
||||||
handleResponse(respData, "Súbor bol úspešne nahraný", "Nastala chyba pri nahrávaní súboru").then(() => {
|
|
||||||
fileInput.reset();
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
let i = 1;
|
||||||
xhr.send(formData);
|
fileInput.files.forEach((file) => {
|
||||||
|
data[`userFile${i}`] = file;
|
||||||
|
});
|
||||||
|
await doAction("/upload", data, "Súbor bol úspešne nahraný", "Nastala chyba pri nahrávaní súboru", false);
|
||||||
|
fileInput.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteFile(fileID) {
|
async function deleteFile(fileID) {
|
||||||
let formData = new FormData();
|
await doAction("/upload", {
|
||||||
formData.append('action', 'deleteFile');
|
action: "deleteFile",
|
||||||
formData.append('file_id', fileID);
|
file_id: fileID
|
||||||
|
}, "Súbor bol úspešne zmazaný", "Nastala chyba pri mazaní súboru", true);
|
||||||
let xhr = new XMLHttpRequest();
|
await listFiles();
|
||||||
xhr.open('POST', '/upload', true);
|
|
||||||
xhr.onload = function () {
|
|
||||||
// noinspection JSIgnoredPromiseFromCall
|
|
||||||
listFiles();
|
|
||||||
};
|
|
||||||
xhr.send(formData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFileList() {
|
async function getFileList() {
|
||||||
let formData = new FormData();
|
const resp = await doAction("/upload", {
|
||||||
formData.append('action', 'getAllFiles');
|
action: "getAllFiles"
|
||||||
|
}, "Zoznam súborov bol úspešne stiahnutý", "Nastala chyba pri sťahovaní zoznamu súborov", true);
|
||||||
|
|
||||||
const response = await fetch('/upload', {
|
if ("Success" === resp.Status) {
|
||||||
method: 'POST',
|
|
||||||
body: formData
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const resp = await response.json();
|
|
||||||
|
|
||||||
if (resp.Status === "Success") {
|
|
||||||
return resp.Files;
|
return resp.Files;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@ -610,42 +587,27 @@ async function listFiles() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addMeme() {
|
async function addMeme() {
|
||||||
let formData = new FormData();
|
|
||||||
let memeTitleElement = document.getElementById("meme_title_input");
|
let memeTitleElement = document.getElementById("meme_title_input");
|
||||||
let memeTextElement = document.getElementById("meme_text_input");
|
let memeTextElement = document.getElementById("meme_text_input");
|
||||||
let memeImageElement = document.getElementById("meme_image_input");
|
let memeImageElement = document.getElementById("meme_image_input");
|
||||||
formData.append('action', 'addMeme');
|
|
||||||
formData.append('meme_title', memeTitleElement.value);
|
|
||||||
formData.append('meme_text', memeTextElement.value);
|
|
||||||
formData.append('meme_image_id', memeImageElement.value);
|
|
||||||
|
|
||||||
let xhr = new XMLHttpRequest();
|
await doAction("/meme", {
|
||||||
xhr.open('POST', '/meme', true);
|
action: "addMeme",
|
||||||
xhr.onload = function () {
|
meme_title: memeTitleElement.value,
|
||||||
const resp = JSON.parse(xhr.responseText);
|
meme_text: memeTextElement.value,
|
||||||
handleResponse(resp, "Meme bol pridaný", "Nastala chyba pri pridávaní meme-u").then(() => {
|
meme_image_id: memeImageElement.value
|
||||||
memeTitleElement.reset();
|
}, "Meme bol zmazaný", "Nastala chyba pri mazaní meme-u", false);
|
||||||
memeTextElement.reset();
|
memeTitleElement.reset();
|
||||||
memeImageElement.reset();
|
memeTextElement.reset();
|
||||||
});
|
memeImageElement.reset();
|
||||||
};
|
|
||||||
xhr.send(formData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteMeme(memeId) {
|
async function deleteMeme(memeId) {
|
||||||
let formData = new FormData();
|
await doAction("/meme", {
|
||||||
formData.append('action', 'deleteMeme');
|
action: "deleteMeme",
|
||||||
formData.append('meme_id', memeId);
|
meme_id: memeId
|
||||||
|
}, "Meme bol zmazaný", "Nastala chyba pri mazaní meme-u", false);
|
||||||
let xhr = new XMLHttpRequest();
|
|
||||||
xhr.open('POST', '/meme', true);
|
|
||||||
xhr.onload = function () {
|
|
||||||
const resp = JSON.parse(xhr.responseText);
|
|
||||||
handleResponse(resp, "Meme bol zmazaný", "Nastala chyba pri mazaní meme-u");
|
|
||||||
softReload();
|
|
||||||
};
|
|
||||||
xhr.send(formData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getMemeImages() {
|
async function getMemeImages() {
|
||||||
|
Loading…
Reference in New Issue
Block a user