64 lines
2.1 KiB
JavaScript
64 lines
2.1 KiB
JavaScript
function get_entry_id(button) {
|
|
return button.form.children[0].value
|
|
}
|
|
|
|
// EDIT ENTRY
|
|
|
|
function edit_entry(e) {
|
|
let data = new URLSearchParams();
|
|
data.append("message", e.target.form[1].value);
|
|
fetch(`/api/guestbook/${e.target.form[0].value}`, {method: "PATCH", body: data})
|
|
.catch(e => console.log(e))
|
|
.then(() => window.location = "/guestbook/admin");
|
|
}
|
|
|
|
for (const edit_entry_button of document.getElementsByName("edit-entry"))
|
|
edit_entry_button.addEventListener("click", edit_entry);
|
|
|
|
// DELETE ENTRY
|
|
|
|
function delete_entry(e) {
|
|
fetch(`/api/guestbook/${e.target.form[0].value}`, {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("message", e.target.form[1].value);
|
|
fetch(`/api/guestbook/${e.target.form[0].value}/reply`, {method: "PATCH", 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(`/api/guestbook/${e.target.form[0].value}/reply`, {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("message", e.target.form[1].value);
|
|
fetch(`/api/guestbook/${e.target.form[0].value}/reply`, {method: "PATCH", 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); |