summaryrefslogtreecommitdiff
path: root/management/editor
diff options
context:
space:
mode:
Diffstat (limited to 'management/editor')
-rw-r--r--management/editor/editor.go70
-rw-r--r--management/editor/elements.go25
2 files changed, 89 insertions, 6 deletions
diff --git a/management/editor/editor.go b/management/editor/editor.go
index f8b1970..dc6f181 100644
--- a/management/editor/editor.go
+++ b/management/editor/editor.go
@@ -43,6 +43,58 @@ func Form(post Editable, fields ...Field) ([]byte, error) {
// content items with Item embedded have some default fields we need to render
editor.ViewBuf.Write([]byte(`<tr class="col s4 default-fields"><td>`))
+
+ publishTime := `
+<div class="row">
+ <div class="input-field col s6">
+ <label class="active">MM</label>
+ <select class="month __ponzu browser-default">
+ <option value="1">Jan - 01</option>
+ <option value="2">Feb - 02</option>
+ <option value="3">Mar - 03</option>
+ <option value="4">Apr - 04</option>
+ <option value="5">May - 05</option>
+ <option value="6">Jun - 06</option>
+ <option value="7">Jul - 07</option>
+ <option value="8">Aug - 08</option>
+ <option value="9">Sep - 09</option>
+ <option value="10">Oct - 10</option>
+ <option value="11">Nov - 11</option>
+ <option value="12">Dec - 12</option>
+ </select>
+ </div>
+ <div class="input-field col s2">
+ <label class="active">DD</label>
+ <input value="" class="day __ponzu" maxlength="2" type="text" placeholder="DD" />
+ </div>
+ <div class="input-field col s4">
+ <label class="active">YYYY</label>
+ <input value="" class="year __ponzu" maxlength="4" type="text" placeholder="YYYY" />
+ </div>
+</div>
+
+<div class="row">
+ <div class="input-field col s3">
+ <label class="active">HH</label>
+ <input value="" class="hour __ponzu" maxlength="2" type="text" placeholder="HH" />
+ </div>
+ <div class="col s1">:</div>
+ <div class="input-field col s3">
+ <label class="active">MM</label>
+ <input value="" class="minute __ponzu" maxlength="2" type="text" placeholder="MM" />
+ </div>
+ <div class="input-field col s4">
+ <label class="active">Period</label>
+ <select class="period __ponzu browser-default">
+ <option value="AM">AM</option>
+ <option value="PM">PM</option>
+ </select>
+ </div>
+</div>
+ `
+
+ editor.ViewBuf.Write([]byte(publishTime))
+
addPostDefaultFieldsToEditorView(post, editor)
submit := `
@@ -87,12 +139,6 @@ func addFieldToEditorView(e *Editor, f Field) {
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",
@@ -100,6 +146,18 @@ func addPostDefaultFieldsToEditorView(p Editable, e *Editor) {
"placeholder": "Will be set automatically",
}),
},
+ Field{
+ View: Timestamp("Timestamp", p, map[string]string{
+ "type": "hidden",
+ "class": "timestamp __ponzu",
+ }),
+ },
+ Field{
+ View: Timestamp("Updated", p, map[string]string{
+ "type": "hidden",
+ "class": "updated __ponzu",
+ }),
+ },
}
for _, f := range defaults {
diff --git a/management/editor/elements.go b/management/editor/elements.go
index e8a2fab..390d8df 100644
--- a/management/editor/elements.go
+++ b/management/editor/elements.go
@@ -37,6 +37,31 @@ func Textarea(fieldName string, p interface{}, attrs map[string]string) []byte {
return domElement(e)
}
+// Timestamp returns the []byte of an <input> HTML element with a label.
+// IMPORTANT:
+// 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 Timestamp(fieldName string, p interface{}, attrs map[string]string) []byte {
+ var data string
+ val := valueFromStructField(fieldName, p)
+ if val.Int() == 0 {
+ data = ""
+ } else {
+ data = fmt.Sprintf("%d", val.Int())
+ }
+
+ e := &element{
+ TagName: "input",
+ Attrs: attrs,
+ Name: tagNameFromStructField(fieldName, p),
+ label: attrs["label"],
+ data: data,
+ viewBuf: &bytes.Buffer{},
+ }
+
+ return domElementSelfClose(e)
+}
+
// File returns the []byte of a <input type="file"> HTML element with a label.
// IMPORTANT:
// The `fieldName` argument will cause a panic if it is not exactly the string