summaryrefslogtreecommitdiff
path: root/content/post.go
blob: 7dc99c13fbebc10e3ec84ca576e7fb4b4aeb6bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package content

import (
	"fmt"

	"github.com/bosssauce/ponzu/management/editor"
)

// Post is the generic content struct
type Post struct {
	Item
	editor editor.Editor

	Title      string   `json:"title"`
	Content    string   `json:"content"`
	Photo      string   `json:"photo"`
	Author     string   `json:"author"`
	Category   []string `json:"category"`
	ThemeStyle string   `json:"theme"`
}

func init() {
	Types["Post"] = func() interface{} { return new(Post) }
}

// SetContentID partially implements editor.Editable
func (p *Post) SetContentID(id int) { p.ID = id }

// ContentID partially implements editor.Editable
func (p *Post) ContentID() int { return p.ID }

// ContentName partially implements editor.Editable
func (p *Post) ContentName() string { return p.Title }

// SetSlug partially implements editor.Editable
func (p *Post) SetSlug(slug string) { p.Slug = slug }

// Editor partially implements editor.Editable
func (p *Post) Editor() *editor.Editor { return &p.editor }

// MarshalEditor writes a buffer of html to edit a Post and partially implements editor.Editable
func (p *Post) MarshalEditor() ([]byte, error) {
	view, err := editor.Form(p,
		editor.Field{
			View: editor.Input("Title", p, map[string]string{
				"label":       "Post Title",
				"type":        "text",
				"placeholder": "Enter your Post Title here",
			}),
		},
		editor.Field{
			View: editor.Richtext("Content", p, map[string]string{
				"label":       "Content",
				"placeholder": "Add the content of your post here",
			}),
		},
		editor.Field{
			View: editor.File("Picture", p, map[string]string{
				"label":       "Author Photo",
				"placeholder": "Upload a profile picture for the author",
			}),
		},
		editor.Field{
			View: editor.Input("Author", p, map[string]string{
				"label":       "Author",
				"type":        "text",
				"placeholder": "Enter the author name here",
			}),
		},
		editor.Field{
			View: editor.Checkbox("Category", p, map[string]string{
				"label": "Post Category",
			}, map[string]string{
				"important": "Important",
				"active":    "Active",
				"unplanned": "Unplanned",
			}),
		},
		editor.Field{
			View: editor.Select("ThemeStyle", p, map[string]string{
				"label": "Theme Style",
			}, map[string]string{
				"dark":  "Dark",
				"light": "Light",
			}),
		},
	)

	if err != nil {
		return nil, fmt.Errorf("Failed to render Post editor view: %s", err.Error())
	}

	return view, nil
}