Adlerka SMP FTW

This commit is contained in:
Bruno Rybársky 2024-04-25 22:08:02 +02:00
parent e74a9c8578
commit b38b4726d9
2 changed files with 28 additions and 8 deletions

@ -553,11 +553,9 @@ function uploadFile() {
xhr.open('POST', '/upload', true); xhr.open('POST', '/upload', true);
xhr.onload = function () { xhr.onload = function () {
if (xhr.status === 200) { const respData = JSON.parse(xhr.responseText);
document.getElementById('uploadStatus').innerHTML = 'File uploaded successfully.'; handleResponse(resp, "Súbor bol úspešne nahraný", "Nastala chyba pri nahrávaní súboru");
} else { fileInput.reset();
document.getElementById('uploadStatus').innerHTML = 'Error uploading file.';
}
}; };
xhr.send(formData); xhr.send(formData);
@ -584,10 +582,32 @@ async function listFiles() {
if (xhr.status === 200) { if (xhr.status === 200) {
const resp = JSON.parse(xhr.responseText); const resp = JSON.parse(xhr.responseText);
if (resp.Status == "Success") { if (resp.Status == "Success") {
displayList(resp['Files'], "filelist", deleteFile); displayList(resp.Files, "filelist", deleteFile);
}
} }
} }
};
xhr.send(formData); xhr.send(formData);
} }
function addMeme() {
let formData = new FormData();
let memeTitleElement = document.getElementById("meme_title_input");
let memeTextElement = document.getElementById("meme_text_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();
xhr.open('POST', '/meme', true);
xhr.onload = function () {
const resp = JSON.parse(xhr.responseText);
handleResponse(resp, "Meme bol pridaný", "Nastala chyba pri pridávaní meme-u");
memeTitleElement.reset();
memeTextElement.reset();
memeImageElement.reset();
};
xhr.send(formData);
}

@ -6,7 +6,7 @@ function endpoint($endpoint_data): array
{ {
return match ($endpoint_data["action"]) { return match ($endpoint_data["action"]) {
"addMeme" => addMeme($endpoint_data['memetitle'], $endpoint_data['memetext'], $endpoint_data['imageid']), "addMeme" => addMeme($endpoint_data['meme_title'], $endpoint_data['meme_text'], $endpoint_data['meme_image_id']),
"renderGallery" => renderMemeGallery(), "renderGallery" => renderMemeGallery(),
default => ["Status" => "Fail", "message" => "Invalid action"], default => ["Status" => "Fail", "message" => "Invalid action"],
}; };