2023-05-09 23:38:49 +04:00
|
|
|
function get_field(e, el) {
|
|
|
|
return e.form.elements[el].value
|
2023-02-06 02:00:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// EDIT ENTRY
|
|
|
|
|
|
|
|
function edit_entry(e) {
|
2023-05-06 23:14:36 +04:00
|
|
|
let data = new URLSearchParams();
|
2023-05-09 23:38:49 +04:00
|
|
|
data.append("message", get_field(e.target, "message"));
|
|
|
|
data.append("name", get_field(e.target, "name"));
|
|
|
|
data.append("website", get_field(e.target, "website"));
|
|
|
|
data.append("hide_website", get_field(e.target, "hide_website"));
|
|
|
|
fetch(`/api/guestbook/${get_field(e.target, "entry_id")}`, {method: "PATCH", body: data})
|
2023-05-06 23:14:36 +04:00
|
|
|
.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-09 23:38:49 +04:00
|
|
|
fetch(`/api/guestbook/${get_field(e.target, "entry_id")}`, {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();
|
2023-05-09 23:38:49 +04:00
|
|
|
data.append("message", get_field(e.target, "message"));
|
|
|
|
fetch(`/api/guestbook/${get_field(e.target, "entry_id")}/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-09 23:38:49 +04:00
|
|
|
fetch(`/api/guestbook/${get_field(e.target, "entry_id")}/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();
|
2023-05-09 23:38:49 +04:00
|
|
|
data.append("message", get_field(e.target, "message"));
|
2023-05-09 23:58:05 +04:00
|
|
|
fetch(`/api/guestbook/${get_field(e.target, "entry_id")}/reply`, {method: "POST", 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);
|