summaryrefslogtreecommitdiff
path: root/system/item
diff options
context:
space:
mode:
authorSteve Manuel <nilslice@gmail.com>2017-04-29 22:43:44 -0500
committerSteve Manuel <nilslice@gmail.com>2017-04-29 22:43:44 -0500
commit3c8c848606b996e2c7a06331401e622f888b84c5 (patch)
treea8c5b6ce9492d33d18bf2a66bc0ec13c9fffc538 /system/item
parenta48ed8dc7f7ddb3ddbc8ea54ad0b0d2feb7c87f0 (diff)
adding search, edit/new, and list view for uploads
Diffstat (limited to 'system/item')
-rw-r--r--system/item/upload.go40
1 files changed, 21 insertions, 19 deletions
diff --git a/system/item/upload.go b/system/item/upload.go
index 9253fcc..800f663 100644
--- a/system/item/upload.go
+++ b/system/item/upload.go
@@ -2,6 +2,7 @@ package item
import (
"fmt"
+ "time"
"github.com/ponzu-cms/ponzu/management/editor"
)
@@ -30,15 +31,12 @@ func (f *FileUpload) MarshalEditor() ([]byte, error) {
return []byte(`
<div class="input-field col s12">
- <label class="active">` + f.Name + `</label>
<!-- Add your custom editor field view here. -->
- <h4>` + f.Name + `</h4>
-
- <img class="preview" src="` + f.Path + `"/>
- <p>File information:</p>
+ <h5>` + f.Name + `</h5>
<ul>
- <li>Content-Length: ` + fmt.Sprintf("%s", FmtBytes(float64(f.ContentLength))) + `</li>
- <li>Content-Type: ` + f.ContentType + `</li>
+ <li><span class="grey-text text-lighten-1">Content-Length:</span> ` + fmt.Sprintf("%s", FmtBytes(float64(f.ContentLength))) + `</li>
+ <li><span class="grey-text text-lighten-1">Content-Type:</span> ` + f.ContentType + `</li>
+ <li><span class="grey-text text-lighten-1">Uploaded:</span> ` + FmtTime(f.Timestamp) + `</li>
</ul>
</div>
`)
@@ -55,17 +53,13 @@ func (f *FileUpload) MarshalEditor() ([]byte, error) {
return nil, err
}
- open := []byte(`
- <div class="card">
- <div class="card-content">
- <div class="card-title">File Uploads</div>
- </div>
- <form action="/admin/uploads" method="post">
- `)
- close := []byte(`</form></div>`)
script := []byte(`
<script>
$(function() {
+ // change form action to upload-specific endpoint
+ var form = $('form');
+ form.attr('action', '/admin/edit/upload');
+
// hide default fields & labels unnecessary for the config
var fields = $('.default-fields');
fields.css('position', 'relative');
@@ -88,14 +82,17 @@ func (f *FileUpload) MarshalEditor() ([]byte, error) {
fields.find('input[name=client_secret]').attr('name', '');
// hide save, show delete
- fields.find('.save-post').hide();
- fields.find('.delete-post').show();
+ if ($('h5').length > 0) {
+ fields.find('.save-post').hide();
+ fields.find('.delete-post').show();
+ } else {
+ fields.find('.save-post').show();
+ fields.find('.delete-post').hide();
+ }
});
</script>
`)
- view = append(open, view...)
- view = append(view, close...)
view = append(view, script...)
return view, nil
@@ -136,3 +133,8 @@ func FmtBytes(size float64) string {
}
}
+
+// FmtTime shows a human readable time based on the timestamp
+func FmtTime(t int64) string {
+ return time.Unix(t/1000, 0).Format("03:04 PM Jan 2, 2006") + " (UTC)"
+}