27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
function get_field(e, el) {
|
|
return e.form.elements[el].value
|
|
}
|
|
|
|
function edit_post(e) {
|
|
let data = new URLSearchParams();
|
|
data.append("category", get_field(e.target, "category"))
|
|
data.append("new-category", get_field(e.target, "new-category"))
|
|
data.append("old-category", get_field(e.target, "old-category"))
|
|
data.append("title", get_field(e.target, "title"))
|
|
data.append("body", get_field(e.target, "body"))
|
|
fetch(`/api/mindflow/${get_field(e.target, "post-id")}`, {method: "PATCH", body: data})
|
|
.catch(e => console.log(e))
|
|
.then(() => window.location = "/mindflow/admin");
|
|
}
|
|
|
|
for (const edit_post_button of document.getElementsByName("edit-post"))
|
|
edit_post_button.addEventListener("click", edit_post);
|
|
|
|
function delete_post(e) {
|
|
fetch(`/api/mindflow/${get_field(e.target, "post-id")}`, {method:"DELETE"})
|
|
.catch(e => console.log(e))
|
|
.then(() => window.location = "/mindflow/admin");
|
|
}
|
|
|
|
for (const delete_post_button of document.getElementsByName("delete-post"))
|
|
delete_post_button.addEventListener("click", delete_post); |