From 4996e52d4da02a3ca1673d0d4519712bb6954540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Thu, 25 Apr 2024 22:38:04 +0200 Subject: [PATCH] MEME --- assets/script.js | 29 +++++++++++++++++++++++++-- pages/files/{list.html => index.html} | 0 pages/files/upload.html | 1 - pages/memes/create.html | 9 +++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) rename pages/files/{list.html => index.html} (100%) create mode 100644 pages/memes/create.html diff --git a/assets/script.js b/assets/script.js index 8e353a2..5498897 100644 --- a/assets/script.js +++ b/assets/script.js @@ -274,6 +274,9 @@ async function onPageLoad() { if ("files" === currentSite && "list" === currentPage) { await listFiles(); } + if ("memes" === currentSite && "create" === currentPage) { + await getMemeImages(); + } } async function navigateTo(site, page) { @@ -571,7 +574,7 @@ function deleteFile(fileID) { xhr.send(formData); } -async function listFiles() { +async function getFileList() { let formData = new FormData(); formData.append('action', 'getAllFiles'); @@ -582,7 +585,10 @@ async function listFiles() { if (xhr.status === 200) { const resp = JSON.parse(xhr.responseText); if (resp.Status == "Success") { - displayList(resp.Files, "filelist", deleteFile); + return resp.Files; + } + else { + return false; } } }; @@ -590,6 +596,13 @@ async function listFiles() { xhr.send(formData); } +async function listFiles() { + const fileList = getFileList(); + if(fileList){ + displayList(fileList, "filelist", deleteFile); + } +} + function addMeme() { let formData = new FormData(); let memeTitleElement = document.getElementById("meme_title_input"); @@ -610,4 +623,16 @@ function addMeme() { memeImageElement.reset(); }; xhr.send(formData); +} + +async function getMemeImages() { + let memeImageSelector = document.getElementById("meme_image_input"); + const fileList = await getFileList(); + fileList.forEach((item) => { + let option = document.createElement("option"); + option.value = item.ID; + option.text = `${item.Path.split("/")[-1]} - (${item.ID}) [${item.UploadedBy}]`; + memeImageSelector.appendChild(option); + }); + } \ No newline at end of file diff --git a/pages/files/list.html b/pages/files/index.html similarity index 100% rename from pages/files/list.html rename to pages/files/index.html diff --git a/pages/files/upload.html b/pages/files/upload.html index eb718f1..dc401ed 100644 --- a/pages/files/upload.html +++ b/pages/files/upload.html @@ -5,4 +5,3 @@ -
diff --git a/pages/memes/create.html b/pages/memes/create.html new file mode 100644 index 0000000..7846d7b --- /dev/null +++ b/pages/memes/create.html @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file