Better Editor Forms #56
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"owl-blogs/domain/model"
|
"owl-blogs/domain/model"
|
||||||
"owl-blogs/render"
|
"owl-blogs/render"
|
||||||
"owl-blogs/web/forms"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Article struct {
|
type Article struct {
|
||||||
|
@ -13,11 +12,24 @@ type Article struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArticleMetaData struct {
|
type ArticleMetaData struct {
|
||||||
forms.DefaultForm
|
|
||||||
Title string `owl:"inputType=text"`
|
Title string `owl:"inputType=text"`
|
||||||
Content string `owl:"inputType=text widget=textarea"`
|
Content string `owl:"inputType=text widget=textarea"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Form implements model.EntryMetaData.
|
||||||
|
func (meta *ArticleMetaData) Form(binSvc model.BinaryStorageInterface) string {
|
||||||
|
f, _ := render.RenderTemplateToString("forms/Article", meta)
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseFormData implements model.EntryMetaData.
|
||||||
|
func (*ArticleMetaData) ParseFormData(data model.HttpFormData, binSvc model.BinaryStorageInterface) (model.EntryMetaData, error) {
|
||||||
|
return &ArticleMetaData{
|
||||||
|
Title: data.FormValue("title"),
|
||||||
|
Content: data.FormValue("content"),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Article) Title() string {
|
func (e *Article) Title() string {
|
||||||
return e.meta.Title
|
return e.meta.Title
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<label for="title">Title</label>
|
||||||
|
<input type="text" name="title" value="{{.Title}}" />
|
||||||
|
|
||||||
|
<label for="content">Content</label>
|
||||||
|
<textarea name="content" rows="16">
|
||||||
|
{{.Content}}
|
||||||
|
</textarea>
|
|
@ -1 +1 @@
|
||||||
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"owl-blogs/app/repository"
|
"owl-blogs/app/repository"
|
||||||
"owl-blogs/domain/model"
|
"owl-blogs/domain/model"
|
||||||
"owl-blogs/render"
|
"owl-blogs/render"
|
||||||
"owl-blogs/web/forms"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
@ -48,12 +47,7 @@ func (h *EditorHandler) HandleGetNew(c *fiber.Ctx) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
htmlForm := entryType.MetaData().Form(h.binSvc)
|
||||||
form := forms.NewForm(entryType.MetaData(), h.binSvc)
|
|
||||||
htmlForm, err := form.HtmlForm()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return render.RenderTemplateWithBase(c, getSiteConfig(h.configRepo), "views/editor", htmlForm)
|
return render.RenderTemplateWithBase(c, getSiteConfig(h.configRepo), "views/editor", htmlForm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +59,7 @@ func (h *EditorHandler) HandlePostNew(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
form := forms.NewForm(entry.MetaData(), h.binSvc)
|
entryMeta, err := entry.MetaData().ParseFormData(c, h.binSvc)
|
||||||
// get form data
|
|
||||||
entryMeta, err := form.Parse(c)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -100,11 +92,7 @@ func (h *EditorHandler) HandleGetEdit(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
form := forms.NewForm(entry.MetaData(), h.binSvc)
|
htmlForm := entry.MetaData().Form(h.binSvc)
|
||||||
htmlForm, err := form.HtmlForm()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return render.RenderTemplateWithBase(c, getSiteConfig(h.configRepo), "views/editor", htmlForm)
|
return render.RenderTemplateWithBase(c, getSiteConfig(h.configRepo), "views/editor", htmlForm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,9 +105,8 @@ func (h *EditorHandler) HandlePostEdit(c *fiber.Ctx) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
form := forms.NewForm(entry.MetaData(), h.binSvc)
|
|
||||||
// get form data
|
// get form data
|
||||||
meta, err := form.Parse(c)
|
meta, err := entry.MetaData().ParseFormData(c, h.binSvc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue