diff options
-rw-r--r-- | content/item.go | 2 | ||||
-rw-r--r-- | management/editor/editor.go | 28 | ||||
-rw-r--r-- | management/manager/manager.go | 22 | ||||
-rw-r--r-- | system/admin/static/common/js/util.js | 11 |
4 files changed, 41 insertions, 22 deletions
diff --git a/content/item.go b/content/item.go index 09f0760..c9aa423 100644 --- a/content/item.go +++ b/content/item.go @@ -6,8 +6,6 @@ import "time" type Item struct { ID int `json:"id"` Slug string `json:"slug"` - Time string `json:"time"` - Date string `json:"date"` Timestamp time.Time `json:"timestamp"` Updated time.Time `json:"updated"` } diff --git a/management/editor/editor.go b/management/editor/editor.go index 486c22f..c7500b6 100644 --- a/management/editor/editor.go +++ b/management/editor/editor.go @@ -43,6 +43,20 @@ 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="input-field col s12"> + <label class="active" for="Publish-Date">Publish Date</label> + <input value="" class="date __ponzu" label="Publish Date" type="date" name="date" /> +</div> +<div class="input-field col s12"> + <label class="active" for="Publish-Time">Publish Time</label> + <input value="" class="time __ponzu" label="Publish Time" type="time" name="time" /> +</div> + ` + + editor.ViewBuf.Write([]byte(publishTime)) + addPostDefaultFieldsToEditorView(post, editor) submit := ` @@ -87,20 +101,6 @@ func addFieldToEditorView(e *Editor, f Field) { func addPostDefaultFieldsToEditorView(p Editable, e *Editor) { defaults := []Field{ Field{ - View: Input("Date", p, map[string]string{ - "label": "Publish Date", - "type": "date", - "class": "date __ponzu", - }), - }, - Field{ - View: Input("Time", p, map[string]string{ - "label": "Publish Time", - "type": "time", - "class": "time __ponzu", - }), - }, - Field{ View: Input("Slug", p, map[string]string{ "label": "URL Slug", "type": "text", diff --git a/management/manager/manager.go b/management/manager/manager.go index 75680d7..46ee82a 100644 --- a/management/manager/manager.go +++ b/management/manager/manager.go @@ -13,15 +13,25 @@ const managerHTML = ` <form method="post" action="/admin/edit" enctype="multipart/form-data"> <input type="hidden" name="id" value="{{.ID}}"/> <input type="hidden" name="type" value="{{.Kind}}"/> - <input type="hidden" name="timestamp" value="" /> - <input type="hidden" name="updated" value="" /> + <input type="hidden" name="timestamp" class="timestamp __ponzu" value="" /> + <input type="hidden" name="updated" class="updated __ponzu" value="" /> {{ .Editor }} </form> <script> - // remove all bad chars from all inputs in the form, except file fields - $('form input:not([type=file]), form textarea').on('blur', function(e) { - var val = e.target.value; - e.target.value = replaceBadChars(val); + $(function() { + // remove all bad chars from all inputs in the form, except file fields + $('form input:not([type=file]), form textarea').on('blur', function(e) { + var val = e.target.value; + e.target.value = replaceBadChars(val); + }); + + // set time time and date inputs using the hidden timestamp input. + // if it is empty, set it to now and use that value for time and date + var publish_time = $('input.__ponzu.time'), + publish_date = $('input.__ponzu.date'), + now = new Date(); + + // set updated value to now }); </script> </div> diff --git a/system/admin/static/common/js/util.js b/system/admin/static/common/js/util.js index d45d9e3..1e798d6 100644 --- a/system/admin/static/common/js/util.js +++ b/system/admin/static/common/js/util.js @@ -20,4 +20,15 @@ function replaceBadChars(text) { s = s.replace(/[\u02DC\u00A0]/g, " "); return s; +} + + +// Returns a local partial time based on unix timestamp +function getPartialTime(date) { + var parts = []; + parts.push(date.getHours()) + parts.push(date.getMinutes()) + parts.push(date.getSeconds()) + + return parts.join(":"); }
\ No newline at end of file |