diff options
author | Marvin Borner | 2020-10-03 12:31:15 +0200 |
---|---|---|
committer | Marvin Borner | 2020-10-03 12:31:27 +0200 |
commit | 7285ce6a534baed7c94c28d6ccaadc959156e94d (patch) | |
tree | fcc3d94a7f270db040a69a0d3627260b87098bde /quotes/public/script.js | |
parent | 9e18568e9d51a6e07d71dd0ec987e8acf737fac2 (diff) |
Added quote deletion
Diffstat (limited to 'quotes/public/script.js')
-rw-r--r-- | quotes/public/script.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/quotes/public/script.js b/quotes/public/script.js index da1c38f..20587fe 100644 --- a/quotes/public/script.js +++ b/quotes/public/script.js @@ -21,8 +21,16 @@ function appendQuote(response) { "beforeend", `<li>${elem["name"]} ${elem["middlename"] ? elem["middlename"] : " "}${elem["surname"]}: ${ elem["quote"] - }</li>`, + } <span data-id="${elem["id"]}">[Löschen]</span></li>`, ); + + document.querySelector(`li span[data-id="${elem["id"]}"]`).addEventListener("click", (event) => { + fetch("api/delete/" + event.target.getAttribute("data-id"), { method: "DELETE" }) + .then((response) => response.text()) + .then((response) => { + if (response == "ok") event.target.parentNode.remove(); + }); + }); }); } @@ -30,7 +38,7 @@ fetch("/auth/api/list?class=all") .then((response) => response.json()) .then((response) => appendOption(response)); -fetch("/quotes/api/list") +fetch("api/list") .then((response) => response.json()) .then((response) => appendQuote(response)); |