From 41306ad06681b27061f41d97dd7c8484ef015827 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 19 Oct 2020 21:06:10 +0200 Subject: Some frontend things --- profile/public/user.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'profile/public/user.js') diff --git a/profile/public/user.js b/profile/public/user.js index 96215e7..1f93891 100644 --- a/profile/public/user.js +++ b/profile/public/user.js @@ -12,7 +12,7 @@ function addUser(userData) { if (!questions.hasOwnProperty(questionID)) continue; const question = questions[questionID]; const div = document.createElement("div"); - div.innerHTML = `${question.question}: ${question.answer || ""}`; + div.innerHTML = `${question.question} ${question.answer || ""}`; divs.push(div); } const h1 = document.createElement("h1"); @@ -27,9 +27,9 @@ function addUser(userData) { } async function addComments(comments) { - const h1 = document.createElement("h1"); - h1.textContent = "Kommentare"; - h1.addEventListener("click", (evt) => { + const h2 = document.createElement("h2"); + h2.textContent = "Kommentare"; + h2.addEventListener("click", (evt) => { const qDivs = evt.target.parentElement.querySelectorAll("div"); qDivs.forEach( (div) => (div.style.display = !div.style.display || div.style.display === "flex" ? "none" : "flex"), @@ -49,8 +49,8 @@ async function addComments(comments) { const del = document.createElement("span"); del.classList.add("delete-btn"); - del.textContent = "[Löschen]"; del.addEventListener("click", async (evt) => { + if (!confirm("Bist du sicher, dass du den Kommentar löschen willst?")) return; const body = JSON.stringify({ pid: uid, cid: evt.target.parentElement.parentElement.dataset.id, @@ -66,11 +66,13 @@ async function addComments(comments) { const edit = document.createElement("span"); edit.classList.add("edit-btn"); - edit.textContent = "[Bearbeiten]"; edit.addEventListener("click", (evt) => { const updateDiv = document.createElement("div"); + updateDiv.id = "edit-div"; - const input = document.createElement("input"); + const inputDiv = document.createElement("div"); + const input = document.createElement("textarea"); + input.placeholder = "Dein Kommentar..."; input.value = comment.comment; const submit = document.createElement("input"); submit.type = "submit"; @@ -92,7 +94,8 @@ async function addComments(comments) { if (res.success) window.location.reload(); }); - updateDiv.append(input, submit); + inputDiv.append(input, submit); + updateDiv.append(inputDiv); div.insertAdjacentElement("beforebegin", updateDiv); commentsDiv.removeChild(div); }); @@ -103,16 +106,16 @@ async function addComments(comments) { divs.push(div); } - commentsDiv.append(h1, ...divs); + commentsDiv.append(h2, ...divs); const addDiv = document.createElement("div"); addDiv.id = "add-div"; const add = document.createElement("span"); add.classList.add("add-btn"); - add.textContent = "[Neuen Kommentar hinzufügen]"; add.addEventListener("click", (evt) => { const div = document.createElement("div"); const input = document.createElement("textarea"); + input.placeholder = "Dein Kommentar..."; const submit = document.createElement("input"); submit.type = "submit"; submit.value = "Hinzufügen"; -- cgit v1.2.3