2023-05-22 05:22:47 +04:00
|
|
|
function get_field(e, el) {
|
|
|
|
return e.form.elements[el].value
|
|
|
|
}
|
|
|
|
|
|
|
|
function edit_post(e) {
|
2023-05-23 03:41:02 +04:00
|
|
|
e.preventDefault();
|
2023-05-22 05:22:47 +04:00
|
|
|
let data = new URLSearchParams();
|
|
|
|
data.append("category", get_field(e.target, "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) {
|
2023-05-23 03:41:02 +04:00
|
|
|
e.preventDefault();
|
2023-05-22 05:22:47 +04:00
|
|
|
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"))
|
2023-05-23 00:22:29 +04:00
|
|
|
delete_post_button.addEventListener("click", delete_post);
|
|
|
|
|
|
|
|
document.getElementById("manage-categories").elements["add"].addEventListener("click", ev => {
|
2023-05-23 03:41:02 +04:00
|
|
|
ev.preventDefault();
|
2023-05-23 00:22:29 +04:00
|
|
|
let data = new URLSearchParams();
|
|
|
|
data.append("name", get_field(ev.target, "name"));
|
2023-05-27 21:04:45 +04:00
|
|
|
fetch(`/api/mindflow/category`, {method: "POST", body: data})
|
2023-05-23 00:22:29 +04:00
|
|
|
.catch(e => console.log(e))
|
|
|
|
.then(() => window.location = "/mindflow/admin");
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("manage-categories").elements["edit"].addEventListener("click", ev => {
|
2023-05-23 03:41:02 +04:00
|
|
|
ev.preventDefault();
|
2023-05-23 00:22:29 +04:00
|
|
|
let data = new URLSearchParams();
|
|
|
|
data.append("name", get_field(ev.target, "name"));
|
2023-05-27 21:04:45 +04:00
|
|
|
fetch(`/api/mindflow/category/${get_field(ev.target, "category")}`, {method: "PATCH", body: data})
|
2023-05-23 00:22:29 +04:00
|
|
|
.catch(e => console.log(e))
|
|
|
|
.then(() => window.location = "/mindflow/admin");
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById("manage-categories").elements["delete"].addEventListener("click", ev => {
|
2023-05-23 03:41:02 +04:00
|
|
|
ev.preventDefault();
|
2023-05-27 21:04:45 +04:00
|
|
|
fetch(`/api/mindflow/category/${get_field(ev.target, "category")}`, {method: "DELETE"})
|
2023-05-23 00:22:29 +04:00
|
|
|
.catch(e => console.log(e))
|
|
|
|
.then(() => window.location = "/mindflow/admin");
|
|
|
|
});
|