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) {
|
||||
var post *mindflow.Post
|
||||
var category *mindflow.Category
|
||||
var category mindflow.Category
|
||||
var err error
|
||||
|
||||
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"))
|
||||
|
||||
if r.FormValue("category") != "" {
|
||||
category, err = mindflow.NewCategory(r.FormValue("new-category"))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
category.ID, _ = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
||||
|
||||
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)
|
||||
category.ID, err = strconv.ParseInt(r.FormValue("category"), 10, 64)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
post, err = mindflow.NewPost(*category, r.FormValue("title"), body)
|
||||
post, err = mindflow.NewPost(category, r.FormValue("title"), body)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -17,7 +17,7 @@ form#add {
|
||||
display: grid;
|
||||
gap: .5rem;
|
||||
grid-template-areas:
|
||||
"c n"
|
||||
"c c"
|
||||
"t t"
|
||||
"b b"
|
||||
"a a";
|
||||
@ -27,7 +27,6 @@ form#add {
|
||||
width: 100%; }
|
||||
|
||||
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 textarea[name="body"] { grid-area: b; }
|
||||
form#add button[type="submit"] { grid-area: a; }
|
||||
|
@ -6,7 +6,6 @@ function edit_post(e) {
|
||||
e.preventDefault();
|
||||
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"))
|
||||
|
@ -25,7 +25,7 @@ block content
|
||||
each category in categories
|
||||
option(value=category.ID) #{category.Name}
|
||||
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="edit") Edit
|
||||
button(type="submit" name="delete") Delete
|
||||
@ -35,12 +35,7 @@ block content
|
||||
form(id='add' action='/api/mindflow', method='POST')
|
||||
select(name='category' required='')
|
||||
each category in categories
|
||||
if (category.ID == 1)
|
||||
option(value=category.ID selected='') #{category.Name}
|
||||
else
|
||||
option(value=category.ID) #{category.Name}
|
||||
option(value='0') -- New category --
|
||||
input(type='text', placeholder='New category name' name='new-category')
|
||||
option(value=category.ID) #{category.Name}
|
||||
input(type='text', placeholder='Title' name='title' required='')
|
||||
textarea(placeholder='Body post' name='body' required='')
|
||||
button(type="submit") Add
|
||||
@ -58,8 +53,6 @@ block content
|
||||
option(value=category.ID selected='') #{category.Name}
|
||||
else
|
||||
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='old-category' value=post.Category.ID)
|
||||
input(type='text', placeholder='Title' name='title' value=post.Title required='')
|
||||
|
Loading…
Reference in New Issue
Block a user