1
0

Updated mindflow_admin template and written JS to make it work.

This commit is contained in:
Alexander Andreev 2023-05-22 05:22:47 +04:00
parent 5095c7649d
commit 2e5bdc2b6f
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 38 additions and 3 deletions

View File

@ -0,0 +1,27 @@
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);

View File

@ -37,10 +37,18 @@ block content
a(href=`#${post.PostID()}`)
h3= post.Category.Name + ": " + post.Title
form.edit
input(type='hidden', name='post_id' value=post.ID)
select(name='category')
option(value='' selected='') -- Change to category --
option(value='1') Update
option(value='2') Diary
option(value='0') New category
input(type='text', placeholder='New category name' name='new-category')
input(type='hidden', name='post-id' value=post.ID)
input(type='hidden', name='old-category' value=post.Category.ID)
input(type='text', placeholder='Title' name='title' value=post.Title required='')
textarea(placeholder='Body post' name='body' required='')= post.Body
button(name='edit') Edit
button(name='delete') Delete
button(name='edit-post') Edit
button(name='delete-post') Delete
footer
time(datetime=util.ToClientTimezone(post.Date, r))= util.ToClientTimezone(post.Date, r).Format(time.RFC1123)
else