From 37d3f13e071cfdb5e063c67dec604c10dbc6ddde Mon Sep 17 00:00:00 2001
From: Steve Manuel `))
e.viewBuf.Write([]byte(`<` + e.TagName + ` `))
for attr, value := range e.Attrs {
@@ -182,18 +168,19 @@ func domElementCheckbox(e *element) []byte {
}
e.viewBuf.Write([]byte(` name="` + e.Name + `"`))
e.viewBuf.Write([]byte(` /> `))
-
if e.label != "" {
- e.viewBuf.Write([]byte(e.label + `
`))
+
return editor.ViewBuf.Bytes(), nil
}
func addFieldToEditorView(e *Editor, f Field) {
e.ViewBuf.Write(f.View)
}
+
+func addPostDefaultFieldsToEditorView(p Editable, e *Editor) {
+ defaults := []Field{
+ Field{
+ View: Input("Timestamp", p, map[string]string{
+ "label": "Publish Date",
+ "type": "date",
+ }),
+ },
+ Field{
+ View: Input("Slug", p, map[string]string{
+ "label": "URL Slug",
+ "type": "text",
+ "disabled": "true",
+ "placeholder": "Will be set automatically",
+ }),
+ },
+ }
+
+ for _, f := range defaults {
+ addFieldToEditorView(e, f)
+ }
+
+}
diff --git a/management/editor/elements.go b/management/editor/elements.go
index 4ea0be0..dd71aa1 100644
--- a/management/editor/elements.go
+++ b/management/editor/elements.go
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"reflect"
+ "strings"
)
type element struct {
@@ -48,6 +49,7 @@ func Select(fieldName string, p interface{}, attrs, options map[string]string) [
// may need to alloc a buffer, as we will probably loop through options
// and append the []byte from domElement() called for each option
+ attrs["class"] = "browser-default"
sel := newElement("select", attrs["label"], fieldName, p, attrs)
var opts []*element
@@ -69,29 +71,22 @@ func Select(fieldName string, p interface{}, attrs, options map[string]string) [
opts = append(opts, cta, reset)
- var val string
for k, v := range options {
+ optAttrs := map[string]string{"value": k}
if k == fieldVal {
- val = "true"
- } else {
- val = "false"
+ optAttrs["selected"] = "true"
}
opt := &element{
TagName: "option",
- Attrs: map[string]string{"value": k, "selected": val},
+ Attrs: optAttrs,
data: v,
viewBuf: &bytes.Buffer{},
}
- // if val is false (unselected option), delete the attr for clarity
- if val == "false" {
- delete(opt.Attrs, "selected")
- }
-
opts = append(opts, opt)
}
- return domElementWithChildren(sel, opts)
+ return domElementWithChildrenSelect(sel, opts)
}
// Checkbox returns the []byte of a set of HTML elements
@@ -100,15 +95,9 @@ func Select(fieldName string, p interface{}, attrs, options map[string]string) [
// The `fieldName` argument will cause a panic if it is not exactly the string
// form of the struct field that this editor input is representing
func Checkbox(fieldName string, p interface{}, attrs, options map[string]string) []byte {
- // options are the value attr and the display value, i.e.
- /*
-
- */
-
+ attrs["class"] = "input-field col s12"
div := newElement("div", attrs["label"], "", p, attrs)
+
var opts []*element
// get the pre-checked options if this is already an existing post
@@ -120,12 +109,13 @@ func Checkbox(fieldName string, p interface{}, attrs, options map[string]string)
inputAttrs := map[string]string{
"type": "checkbox",
"value": k,
+ "id": strings.Join(strings.Split(v, " "), "-"),
}
// check if k is in the pre-checked values and set to checked
for _, x := range checked {
if k == x {
- inputAttrs["checked"] = "true"
+ inputAttrs["checked"] = "checked"
}
}
@@ -150,8 +140,9 @@ func Checkbox(fieldName string, p interface{}, attrs, options map[string]string)
// domElementSelfClose is a special DOM element which is parsed as a
// self-closing tag and thus needs to be created differently
func domElementSelfClose(e *element) []byte {
+ e.viewBuf.Write([]byte(` `))
+
+ // content items with Item embedded have some default fields we need to render
+ editor.ViewBuf.Write([]byte(``))
for _, f := range fields {
addFieldToEditorView(editor, f)
}
+ editor.ViewBuf.Write([]byte(` `))
+ addPostDefaultFieldsToEditorView(post, editor)
+
+ submit := `
+