From a8a626c96a699ceb6cfda0ed81a9910ed8ae9991 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Tue, 20 Dec 2016 18:00:19 -0800 Subject: fixing scope of FileRepeater and minor css updates --- management/editor/repeaters.go | 101 ++++++++++++++++++++++++---- system/admin/static/dashboard/css/admin.css | 4 ++ 2 files changed, 91 insertions(+), 14 deletions(-) diff --git a/management/editor/repeaters.go b/management/editor/repeaters.go index f9c4da6..f84c5ad 100644 --- a/management/editor/repeaters.go +++ b/management/editor/repeaters.go @@ -5,11 +5,11 @@ import ( "strings" ) -// RepeatSelect returns the []byte of a HTML element plus internal 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 RepeatSelect(fieldName string, p interface{}, attrs, options map[string]string) []byte { +func SelectRepeater(fieldName string, p interface{}, attrs, options map[string]string) []byte { // options are the value attr and the display value, i.e. // scope := tagNameFromStructField(fieldName, p) @@ -78,12 +78,86 @@ func RepeatSelect(fieldName string, p interface{}, attrs, options map[string]str } html.WriteString(``) - return append(html.Bytes(), RepeatController(fieldName, p, "select")...) + return append(html.Bytes(), RepeatController(fieldName, p, "select", ".input-field")...) +} + +// FileRepeater returns the []byte of a 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 FileRepeater(fieldName string, p interface{}, attrs map[string]string) []byte { + name := tagNameFromStructField(fieldName, p) + tmpl := + `
+ +
+
+ Upload + +
+
+ +
+
+
+ +
` + + script := + `` + + html := `` + tmpl + `` + return append([]byte(html+script), RepeatController(fieldName, p, "input.store."+name, "div.file-input."+name)...) } // RepeatController generates the javascript to control any repeatable form // element in an editor based on its type, field name and HTML tag name -func RepeatController(fieldName string, p interface{}, htmlTagName string) []byte { +func RepeatController(fieldName string, p interface{}, inputSelector, cloneSelector string) []byte { scope := tagNameFromStructField(fieldName, p) script := `