Removed ability to create new category when editing/creating a post.
This commit is contained in:
parent
c3a6d57708
commit
a81375fc34
@ -60,7 +60,7 @@ func (h *MindflowApiHandlers) NewPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (h *MindflowApiHandlers) EditPost(w http.ResponseWriter, r *http.Request) {
|
func (h *MindflowApiHandlers) EditPost(w http.ResponseWriter, r *http.Request) {
|
||||||
var post *mindflow.Post
|
var post *mindflow.Post
|
||||||
var category *mindflow.Category
|
var category mindflow.Category
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
if strings.Contains(r.Header.Get("Content-Type"), "application/x-www-form-urlencoded") {
|
||||||
@ -68,28 +68,13 @@ func (h *MindflowApiHandlers) EditPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
body := cleanupNewlines(r.FormValue("body"))
|
body := cleanupNewlines(r.FormValue("body"))
|
||||||
|
|
||||||
if r.FormValue("category") != "" {
|
category.ID, err = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
||||||
category, err = mindflow.NewCategory(r.FormValue("new-category"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
category.ID, _ = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
post, err = mindflow.NewPost(category, r.FormValue("title"), body)
|
||||||
|
|
||||||
if category.ID == 0 {
|
|
||||||
category.ID, err = h.db.NewCategory(category)
|
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
category = &mindflow.Category{}
|
|
||||||
category.ID, _ = strconv.ParseInt(r.FormValue("old-category"), 10, 64)
|
|
||||||
}
|
|
||||||
|
|
||||||
post, err = mindflow.NewPost(*category, r.FormValue("title"), body)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -17,7 +17,7 @@ form#add {
|
|||||||
display: grid;
|
display: grid;
|
||||||
gap: .5rem;
|
gap: .5rem;
|
||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
"c n"
|
"c c"
|
||||||
"t t"
|
"t t"
|
||||||
"b b"
|
"b b"
|
||||||
"a a";
|
"a a";
|
||||||
@ -27,7 +27,6 @@ form#add {
|
|||||||
width: 100%; }
|
width: 100%; }
|
||||||
|
|
||||||
form#add select { grid-area: c; }
|
form#add select { grid-area: c; }
|
||||||
form#add input[name="new-category"] { grid-area: n; }
|
|
||||||
form#add input[name="title"] { grid-area: t; }
|
form#add input[name="title"] { grid-area: t; }
|
||||||
form#add textarea[name="body"] { grid-area: b; }
|
form#add textarea[name="body"] { grid-area: b; }
|
||||||
form#add button[type="submit"] { grid-area: a; }
|
form#add button[type="submit"] { grid-area: a; }
|
||||||
|
@ -6,7 +6,6 @@ function edit_post(e) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let data = new URLSearchParams();
|
let data = new URLSearchParams();
|
||||||
data.append("category", get_field(e.target, "category"))
|
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("old-category", get_field(e.target, "old-category"))
|
||||||
data.append("title", get_field(e.target, "title"))
|
data.append("title", get_field(e.target, "title"))
|
||||||
data.append("body", get_field(e.target, "body"))
|
data.append("body", get_field(e.target, "body"))
|
||||||
|
@ -25,7 +25,7 @@ block content
|
|||||||
each category in categories
|
each category in categories
|
||||||
option(value=category.ID) #{category.Name}
|
option(value=category.ID) #{category.Name}
|
||||||
option(value='0') -- New category --
|
option(value='0') -- New category --
|
||||||
input(type='text', placeholder='Category name' name='name')
|
input(type='text', placeholder='New category name' name='name')
|
||||||
button(type="submit" name="add") Add
|
button(type="submit" name="add") Add
|
||||||
button(type="submit" name="edit") Edit
|
button(type="submit" name="edit") Edit
|
||||||
button(type="submit" name="delete") Delete
|
button(type="submit" name="delete") Delete
|
||||||
@ -35,12 +35,7 @@ block content
|
|||||||
form(id='add' action='/api/mindflow', method='POST')
|
form(id='add' action='/api/mindflow', method='POST')
|
||||||
select(name='category' required='')
|
select(name='category' required='')
|
||||||
each category in categories
|
each category in categories
|
||||||
if (category.ID == 1)
|
|
||||||
option(value=category.ID selected='') #{category.Name}
|
|
||||||
else
|
|
||||||
option(value=category.ID) #{category.Name}
|
option(value=category.ID) #{category.Name}
|
||||||
option(value='0') -- New category --
|
|
||||||
input(type='text', placeholder='New category name' name='new-category')
|
|
||||||
input(type='text', placeholder='Title' name='title' required='')
|
input(type='text', placeholder='Title' name='title' required='')
|
||||||
textarea(placeholder='Body post' name='body' required='')
|
textarea(placeholder='Body post' name='body' required='')
|
||||||
button(type="submit") Add
|
button(type="submit") Add
|
||||||
@ -58,8 +53,6 @@ block content
|
|||||||
option(value=category.ID selected='') #{category.Name}
|
option(value=category.ID selected='') #{category.Name}
|
||||||
else
|
else
|
||||||
option(value=category.ID) #{category.Name}
|
option(value=category.ID) #{category.Name}
|
||||||
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='post-id' value=post.ID)
|
||||||
input(type='hidden', name='old-category' value=post.Category.ID)
|
input(type='hidden', name='old-category' value=post.Category.ID)
|
||||||
input(type='text', placeholder='Title' name='title' value=post.Title required='')
|
input(type='text', placeholder='Title' name='title' value=post.Title required='')
|
||||||
|
Loading…
Reference in New Issue
Block a user