1
0
dwelling-home/web/assets/js/guestbook_admin.js

61 lines
1.9 KiB
JavaScript

function get_entry_id(button) {
return button.form.children[0].value
}
// EDIT ENTRY
function edit_entry(e) {
}
for (const edit_entry_button of document.getElementsByName("edit-entry"))
edit_entry_button.addEventListener("click", edit_entry);
// DELETE ENTRY
function delete_entry(e) {
fetch("/guestbook/admin/entry/"+get_entry_id(e.target), {method:"DELETE"})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}
for (const delete_entry_button of document.getElementsByName("delete-entry"))
delete_entry_button.addEventListener("click", delete_entry);
// EDIT REPLY
function edit_reply(e) {
let data = new URLSearchParams();
data.append("entry_id", e.target.form[0].value);
data.append("message", e.target.form[1].value);
fetch("/guestbook/admin/reply/?update", {method: "POST", body: data})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}
for (const edit_reply_button of document.getElementsByName("edit-reply"))
edit_reply_button.addEventListener("click", edit_reply);
// DELETE REPLY
function delete_reply(e) {
fetch("/guestbook/admin/reply/"+get_entry_id(e.target), {method:"DELETE"})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}
for (const delete_reply_button of document.getElementsByName("delete-reply"))
delete_reply_button.addEventListener("click", delete_reply);
// NEW REPLY
function send_reply(e) {
let data = new URLSearchParams();
data.append("entry_id", e.target.form[0].value);
data.append("message", e.target.form[1].value);
fetch("/guestbook/admin/reply/", {method: "POST", body: data})
.catch(e => console.log(e))
.then(() => window.location = "/guestbook/admin");
}
for (const reply_button of document.getElementsByName("reply"))
reply_button.addEventListener("click", send_reply);