Better Editor Forms #56
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"owl-blogs/domain/model"
|
||||
"owl-blogs/render"
|
||||
"owl-blogs/web/forms"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
|
@ -13,11 +12,22 @@ type Note struct {
|
|||
}
|
||||
|
||||
type NoteMetaData struct {
|
||||
forms.DefaultForm
|
||||
|
||||
Content string `owl:"inputType=text widget=textarea"`
|
||||
}
|
||||
|
||||
// Form implements model.EntryMetaData.
|
||||
func (meta *NoteMetaData) Form(binSvc model.BinaryStorageInterface) string {
|
||||
f, _ := render.RenderTemplateToString("forms/Note", meta)
|
||||
return f
|
||||
}
|
||||
|
||||
// ParseFormData implements model.EntryMetaData.
|
||||
func (*NoteMetaData) ParseFormData(data model.HttpFormData, binSvc model.BinaryStorageInterface) (model.EntryMetaData, error) {
|
||||
return &NoteMetaData{
|
||||
Content: data.FormValue("content"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *Note) Title() string {
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"owl-blogs/domain/model"
|
||||
"owl-blogs/render"
|
||||
"owl-blogs/web/forms"
|
||||
)
|
||||
|
||||
type Page struct {
|
||||
|
@ -13,12 +12,24 @@ type Page struct {
|
|||
}
|
||||
|
||||
type PageMetaData struct {
|
||||
forms.DefaultForm
|
||||
|
||||
Title string `owl:"inputType=text"`
|
||||
Content string `owl:"inputType=text widget=textarea"`
|
||||
}
|
||||
|
||||
// Form implements model.EntryMetaData.
|
||||
func (meta *PageMetaData) Form(binSvc model.BinaryStorageInterface) string {
|
||||
f, _ := render.RenderTemplateToString("forms/Page", meta)
|
||||
return f
|
||||
}
|
||||
|
||||
// ParseFormData implements model.EntryMetaData.
|
||||
func (*PageMetaData) ParseFormData(data model.HttpFormData, binSvc model.BinaryStorageInterface) (model.EntryMetaData, error) {
|
||||
return &PageMetaData{
|
||||
Title: data.FormValue("title"),
|
||||
Content: data.FormValue("content"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *Page) Title() string {
|
||||
return e.meta.Title
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"owl-blogs/domain/model"
|
||||
"owl-blogs/render"
|
||||
"owl-blogs/web/forms"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Recipe struct {
|
||||
|
@ -13,8 +13,6 @@ type Recipe struct {
|
|||
}
|
||||
|
||||
type RecipeMetaData struct {
|
||||
forms.DefaultForm
|
||||
|
||||
Title string `owl:"inputType=text"`
|
||||
Yield string `owl:"inputType=text"`
|
||||
Duration string `owl:"inputType=text"`
|
||||
|
@ -22,6 +20,30 @@ type RecipeMetaData struct {
|
|||
Content string `owl:"inputType=text widget=textarea"`
|
||||
}
|
||||
|
||||
// Form implements model.EntryMetaData.
|
||||
func (meta *RecipeMetaData) Form(binSvc model.BinaryStorageInterface) string {
|
||||
f, _ := render.RenderTemplateToString("forms/Recipe", meta)
|
||||
return f
|
||||
}
|
||||
|
||||
// ParseFormData implements model.EntryMetaData.
|
||||
func (*RecipeMetaData) ParseFormData(data model.HttpFormData, binSvc model.BinaryStorageInterface) (model.EntryMetaData, error) {
|
||||
ings := strings.Split(data.FormValue("ingredients"), "\n")
|
||||
clean := make([]string, 0)
|
||||
for _, ing := range ings {
|
||||
if strings.TrimSpace(ing) != "" {
|
||||
clean = append(clean, strings.TrimSpace(ing))
|
||||
}
|
||||
}
|
||||
return &RecipeMetaData{
|
||||
Title: data.FormValue("title"),
|
||||
Yield: data.FormValue("yield"),
|
||||
Duration: data.FormValue("duration"),
|
||||
Ingredients: clean,
|
||||
Content: data.FormValue("content"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *Recipe) Title() string {
|
||||
return e.meta.Title
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"owl-blogs/domain/model"
|
||||
"owl-blogs/render"
|
||||
"owl-blogs/web/forms"
|
||||
)
|
||||
|
||||
type Reply struct {
|
||||
|
@ -13,13 +12,26 @@ type Reply struct {
|
|||
}
|
||||
|
||||
type ReplyMetaData struct {
|
||||
forms.DefaultForm
|
||||
|
||||
Title string `owl:"inputType=text"`
|
||||
Url string `owl:"inputType=text"`
|
||||
Content string `owl:"inputType=text widget=textarea"`
|
||||
}
|
||||
|
||||
// Form implements model.EntryMetaData.
|
||||
func (meta *ReplyMetaData) Form(binSvc model.BinaryStorageInterface) string {
|
||||
f, _ := render.RenderTemplateToString("forms/Reply", meta)
|
||||
return f
|
||||
}
|
||||
|
||||
// ParseFormData implements model.EntryMetaData.
|
||||
func (*ReplyMetaData) ParseFormData(data model.HttpFormData, binSvc model.BinaryStorageInterface) (model.EntryMetaData, error) {
|
||||
return &ReplyMetaData{
|
||||
Title: data.FormValue("title"),
|
||||
Url: data.FormValue("url"),
|
||||
Content: data.FormValue("content"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (e *Reply) Title() string {
|
||||
return "Re: " + e.meta.Title
|
||||
}
|
||||
|
|
|
@ -2,6 +2,4 @@
|
|||
<input type="text" name="title" value="{{.Title}}" />
|
||||
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" rows="16">
|
||||
{{.Content}}
|
||||
</textarea>
|
||||
<textarea name="content" rows="16">{{.Content}}</textarea>
|
|
@ -5,6 +5,4 @@
|
|||
<input type="text" name="url" value="{{.Url}}" placeholder="https://..." />
|
||||
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" rows="16">
|
||||
{{.Content}}
|
||||
</textarea>
|
||||
<textarea name="content" rows="16">{{.Content}}</textarea></textarea>
|
|
@ -5,6 +5,4 @@
|
|||
<input type="text" name="title" value="{{.Title}}" />
|
||||
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" rows="16">
|
||||
{{.Content}}
|
||||
</textarea>
|
||||
<textarea name="content" rows="16">{{.Content}}</textarea>
|
|
@ -0,0 +1,2 @@
|
|||
<label for="content">Content</label>
|
||||
<textarea name="content" rows="8">{{.Content}}</textarea>
|
|
@ -0,0 +1,5 @@
|
|||
<label for="title">Title</label>
|
||||
<input type="text" name="title" value="{{.Title}}" />
|
||||
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" rows="16">{{.Content}}</textarea>
|
|
@ -0,0 +1,15 @@
|
|||
<label for="title">Title</label>
|
||||
<input type="text" name="title" value="{{.Title}}" />
|
||||
|
||||
<label for="yield">Yield</label>
|
||||
<input type="text" name="yield" value="{{.Yield}}" />
|
||||
|
||||
<label for="duration">Duration</label>
|
||||
<input type="text" name="duration" value="{{.Duration}}" />
|
||||
|
||||
<label for="ingredients">Ingredients</label>
|
||||
<textarea name="ingredients" rows="8">{{ range $i := .Ingredients }}
|
||||
{{$i}}{{ end }}</textarea>
|
||||
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" rows="16">{{.Content}}</textarea>
|
|
@ -0,0 +1,8 @@
|
|||
<label for="title">Title</label>
|
||||
<input type="text" name="title" value="{{.Title}}" />
|
||||
|
||||
<label for="url">Reply To</label>
|
||||
<input type="text" name="url" value="{{.Url}}" placeholder="https://..." />
|
||||
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" rows="16">{{.Content}}</textarea></textarea>
|
|
@ -2,19 +2,26 @@ package test
|
|||
|
||||
import (
|
||||
"owl-blogs/domain/model"
|
||||
"owl-blogs/web/forms"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MockEntryMetaData struct {
|
||||
forms.DefaultForm
|
||||
|
||||
Str string
|
||||
Number int
|
||||
Date time.Time
|
||||
Title string
|
||||
}
|
||||
|
||||
// Form implements model.EntryMetaData.
|
||||
func (*MockEntryMetaData) Form(binSvc model.BinaryStorageInterface) string {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
// ParseFormData implements model.EntryMetaData.
|
||||
func (*MockEntryMetaData) ParseFormData(data model.HttpFormData, binSvc model.BinaryStorageInterface) (model.EntryMetaData, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
type MockEntry struct {
|
||||
model.EntryBase
|
||||
metaData *MockEntryMetaData
|
||||
|
|
|
@ -7,19 +7,6 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type DefaultForm struct{}
|
||||
|
||||
func (meta *DefaultForm) Form(binSvc model.BinaryStorageInterface) string {
|
||||
form := NewForm(meta, nil)
|
||||
htmlForm, _ := form.HtmlForm()
|
||||
return htmlForm
|
||||
}
|
||||
|
||||
func (meta *DefaultForm) ParseFormData(data model.HttpFormData, binSvc model.BinaryStorageInterface) (model.EntryMetaData, error) {
|
||||
form := NewForm(meta, binSvc)
|
||||
return form.Parse(data)
|
||||
}
|
||||
|
||||
type Form[T interface{}] struct {
|
||||
data T
|
||||
binSvc model.BinaryStorageInterface
|
||||
|
|
Loading…
Reference in New Issue