2023-02-06 02:00:20 +04:00
|
|
|
function get_entry_id(button) {
|
|
|
|
return button.form.children[0].value
|
|
|
|
}
|
|
|
|
|
|
|
|
// EDIT ENTRY
|
|
|
|
|
|
|
|
function edit_entry(e) {
|
2023-05-06 23:14:36 +04:00
|
|
|
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");
|
2023-02-06 02:00:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const edit_entry_button of document.getElementsByName("edit-entry"))
|
|
|
|
edit_entry_button.addEventListener("click", edit_entry);
|
|
|
|
|
|
|
|
// DELETE ENTRY
|
|
|
|
|
|
|
|
function delete_entry(e) {
|
2023-05-06 23:14:36 +04:00
|
|
|
fetch(`/api/guestbook/${e.target.form[0].value}`, {method:"DELETE"})
|
2023-02-06 02:00:20 +04:00
|
|
|
.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) {
|
2023-02-06 02:42:42 +04:00
|
|
|
let data = new URLSearchParams();
|
|
|
|
data.append("message", e.target.form[1].value);
|
2023-05-06 23:14:36 +04:00
|
|
|
fetch(`/api/guestbook/${e.target.form[0].value}/reply`, {method: "PATCH", body: data})
|
2023-02-06 02:42:42 +04:00
|
|
|
.catch(e => console.log(e))
|
|
|
|
.then(() => window.location = "/guestbook/admin");
|
2023-02-06 02:00:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const edit_reply_button of document.getElementsByName("edit-reply"))
|
|
|
|
edit_reply_button.addEventListener("click", edit_reply);
|
|
|
|
|
|
|
|
// DELETE REPLY
|
|
|
|
|
|
|
|
function delete_reply(e) {
|
2023-05-06 23:14:36 +04:00
|
|
|
fetch(`/api/guestbook/${e.target.form[0].value}/reply`, {method:"DELETE"})
|
2023-02-06 02:00:20 +04:00
|
|
|
.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) {
|
2023-02-06 02:42:42 +04:00
|
|
|
let data = new URLSearchParams();
|
|
|
|
data.append("message", e.target.form[1].value);
|
2023-05-06 23:14:36 +04:00
|
|
|
fetch(`/api/guestbook/${e.target.form[0].value}/reply`, {method: "PATCH", body: data})
|
2023-02-06 02:42:42 +04:00
|
|
|
.catch(e => console.log(e))
|
|
|
|
.then(() => window.location = "/guestbook/admin");
|
2023-02-06 02:00:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const reply_button of document.getElementsByName("reply"))
|
|
|
|
reply_button.addEventListener("click", send_reply);
|