formagic 0.3.4 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/app/assets/javascripts/formagic.coffee +2 -0
- data/app/assets/javascripts/formagic/form.coffee +9 -39
- data/app/assets/javascripts/formagic/group.coffee +1 -11
- data/app/assets/javascripts/formagic/inputs/array.coffee +8 -26
- data/app/assets/javascripts/formagic/inputs/checkbox.coffee +3 -20
- data/app/assets/javascripts/formagic/inputs/color.coffee +2 -16
- data/app/assets/javascripts/formagic/inputs/date.coffee +6 -24
- data/app/assets/javascripts/formagic/inputs/datetime.coffee +6 -27
- data/app/assets/javascripts/formagic/inputs/document.coffee +9 -25
- data/app/assets/javascripts/formagic/inputs/documents.coffee +11 -32
- data/app/assets/javascripts/formagic/inputs/documents_reorder.coffee +1 -12
- data/app/assets/javascripts/formagic/inputs/file.coffee +2 -22
- data/app/assets/javascripts/formagic/inputs/hash.coffee +1 -4
- data/app/assets/javascripts/formagic/inputs/hidden.coffee +2 -19
- data/app/assets/javascripts/formagic/inputs/html.coffee +2 -18
- data/app/assets/javascripts/formagic/inputs/image.coffee +3 -2
- data/app/assets/javascripts/formagic/inputs/list.coffee +2 -21
- data/app/assets/javascripts/formagic/inputs/list_reorder.coffee +1 -12
- data/app/assets/javascripts/formagic/inputs/list_typeahead.coffee +1 -13
- data/app/assets/javascripts/formagic/inputs/markdown.coffee +2 -18
- data/app/assets/javascripts/formagic/inputs/password.coffee +2 -14
- data/app/assets/javascripts/formagic/inputs/redactor.coffee +2 -18
- data/app/assets/javascripts/formagic/inputs/redactor_character.coffee +1 -13
- data/app/assets/javascripts/formagic/inputs/redactor_images.coffee +0 -13
- data/app/assets/javascripts/formagic/inputs/select.coffee +2 -21
- data/app/assets/javascripts/formagic/inputs/select2.coffee +0 -13
- data/app/assets/javascripts/formagic/inputs/select2_multiple.coffee +90 -0
- data/app/assets/javascripts/formagic/inputs/select2_single.coffee +57 -0
- data/app/assets/javascripts/formagic/inputs/string.coffee +13 -34
- data/app/assets/javascripts/formagic/inputs/text.coffee +2 -13
- data/app/assets/javascripts/formagic/inputs/url.coffee +3 -12
- data/app/assets/stylesheets/formagic.scss +2 -0
- data/app/assets/stylesheets/formagic/actions.scss +9 -0
- data/app/assets/stylesheets/formagic/form.scss +16 -24
- data/app/assets/stylesheets/formagic/nested-form.scss +3 -9
- data/app/assets/stylesheets/formagic/select.scss +24 -5
- data/app/assets/stylesheets/formagic/url.scss +5 -0
- data/lib/formagic/version.rb +1 -1
- metadata +6 -2
@@ -1,11 +1,6 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT FILE
|
11
6
|
# -----------------------------------------------------------------------------
|
@@ -24,13 +19,11 @@ class @InputFile extends InputString
|
|
24
19
|
|
25
20
|
return this
|
26
21
|
|
27
|
-
|
28
|
-
# PRIVATE ===============================================
|
22
|
+
# PRIVATE ===================================================================
|
29
23
|
|
30
24
|
_create_el: ->
|
31
25
|
@$el =$ "<div class='form-input input-#{ @config.type } input-#{ @config.klassName }'>"
|
32
26
|
|
33
|
-
|
34
27
|
_add_input: ->
|
35
28
|
@$link =$ "<a href='#' target='_blank' title=''></a>"
|
36
29
|
@$el.append(@$link)
|
@@ -41,7 +34,6 @@ class @InputFile extends InputString
|
|
41
34
|
@_add_clear_button()
|
42
35
|
@_add_remove_checkbox()
|
43
36
|
|
44
|
-
|
45
37
|
_add_clear_button: ->
|
46
38
|
@$clearButton =$ "<a href='#' class='input-file-clear'></a>"
|
47
39
|
@$input.after @$clearButton
|
@@ -57,7 +49,6 @@ class @InputFile extends InputString
|
|
57
49
|
@$input.on 'change', (e) =>
|
58
50
|
@$clearButton.show()
|
59
51
|
|
60
|
-
|
61
52
|
_add_remove_checkbox: ->
|
62
53
|
removeInputName = @removeName()
|
63
54
|
@$removeLabel =$ "<label for='#{ removeInputName }'>Remove</label>"
|
@@ -67,11 +58,9 @@ class @InputFile extends InputString
|
|
67
58
|
@$link.after(@$removeInput)
|
68
59
|
@$link.after(@$hiddenRemoveInput)
|
69
60
|
|
70
|
-
|
71
61
|
_update_inputs: ->
|
72
62
|
@$link.html(@filename).attr('title', @filename).attr('href', @value.url)
|
73
63
|
|
74
|
-
|
75
64
|
_update_state: (@filename=null) ->
|
76
65
|
@$input.val('')
|
77
66
|
@$removeInput.prop('checked', false)
|
@@ -88,30 +77,21 @@ class @InputFile extends InputString
|
|
88
77
|
@$el.addClass('empty')
|
89
78
|
@$clearButton.hide()
|
90
79
|
|
91
|
-
|
92
|
-
# PUBLIC ================================================
|
80
|
+
# PUBLIC ====================================================================
|
93
81
|
|
94
82
|
# when no file uploaded and no file selected, send remove flag so
|
95
83
|
# carrierwave does not catch _old_ value
|
96
84
|
isEmpty: ->
|
97
85
|
( ! @$input.get()[0].files[0] && ! @filename )
|
98
86
|
|
99
|
-
|
100
87
|
removeName: ->
|
101
88
|
@name.reverse().replace('[', '[remove_'.reverse()).reverse()
|
102
89
|
|
103
|
-
|
104
90
|
updateValue: (@value, @object) ->
|
105
91
|
@_update_state()
|
106
92
|
|
107
|
-
|
108
93
|
hash: (hash={})->
|
109
94
|
# @TODO: file input type does not support caching and versioning as of now
|
110
95
|
return hash
|
111
96
|
|
112
|
-
|
113
97
|
chr.formInputs['file'] = InputFile
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
@@ -1,14 +1,11 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
# -----------------------------------------------------------------------------
|
5
|
-
|
6
4
|
# -----------------------------------------------------------------------------
|
7
5
|
# INPUT HASH
|
8
6
|
# -----------------------------------------------------------------------------
|
9
|
-
#
|
7
|
+
# Allows to work with hash fields in nested forms way.
|
10
8
|
# -----------------------------------------------------------------------------
|
11
|
-
|
12
9
|
class @InputHash extends InputDocument
|
13
10
|
|
14
11
|
_create_el: ->
|
@@ -1,11 +1,6 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT HIDDEN
|
11
6
|
# -----------------------------------------------------------------------------
|
@@ -15,43 +10,31 @@ class @InputHidden
|
|
15
10
|
|
16
11
|
return this
|
17
12
|
|
18
|
-
|
19
|
-
# PRIVATE ===============================================
|
13
|
+
# PRIVATE ===================================================================
|
20
14
|
|
21
15
|
_create_el: ->
|
22
16
|
@$el =$ "<input type='hidden' name='#{ @name }' value='#{ @_safe_value() }' />"
|
23
17
|
|
24
|
-
|
25
18
|
_safe_value: ->
|
26
19
|
if typeof(@value) == 'object'
|
27
20
|
return JSON.stringify(@value)
|
28
21
|
else
|
29
22
|
_escapeHtml(@value)
|
30
23
|
|
31
|
-
|
32
|
-
# PUBLIC ================================================
|
24
|
+
# PUBLIC ====================================================================
|
33
25
|
|
34
26
|
showErrorMessage: (message) -> ;
|
35
27
|
|
36
|
-
|
37
28
|
hideErrorMessage: -> ;
|
38
29
|
|
39
|
-
|
40
30
|
initialize: ->
|
41
31
|
@config.onInitialize?(this)
|
42
32
|
|
43
|
-
|
44
33
|
hash: (hash={}) ->
|
45
34
|
hash[@config.klassName] = @$el.val()
|
46
35
|
return hash
|
47
36
|
|
48
|
-
|
49
37
|
updateValue: (@value) ->
|
50
38
|
@$el.val(@value)
|
51
39
|
|
52
|
-
|
53
40
|
chr.formInputs['hidden'] = InputHidden
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
@@ -1,15 +1,9 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT HTML
|
11
6
|
# -----------------------------------------------------------------------------
|
12
|
-
#
|
13
7
|
# Config options:
|
14
8
|
# label - Input label
|
15
9
|
# aceOptions - Custom options for overriding default ones
|
@@ -20,12 +14,10 @@
|
|
20
14
|
# Dependencies:
|
21
15
|
#= require vendor/ace
|
22
16
|
#= require vendor/mode-html
|
23
|
-
#
|
24
17
|
# -----------------------------------------------------------------------------
|
25
|
-
|
26
18
|
class @InputHtml extends InputString
|
27
19
|
|
28
|
-
# PRIVATE
|
20
|
+
# PRIVATE ===================================================================
|
29
21
|
|
30
22
|
_add_input: ->
|
31
23
|
@$input =$ "<input type='hidden' name='#{ @name }' value='#{ @_safe_value() }' />"
|
@@ -34,14 +26,12 @@ class @InputHtml extends InputString
|
|
34
26
|
@$editor =$ "<div></div>"
|
35
27
|
@$el.append @$editor
|
36
28
|
|
37
|
-
|
38
29
|
_update_inputs: ->
|
39
30
|
@value = @editor.getSession().getValue()
|
40
31
|
@$input.val(@value)
|
41
32
|
@$input.trigger('change')
|
42
33
|
|
43
|
-
|
44
|
-
# PUBLIC ================================================
|
34
|
+
# PUBLIC ====================================================================
|
45
35
|
|
46
36
|
initialize: ->
|
47
37
|
@config.beforeInitialize?(this)
|
@@ -69,14 +59,8 @@ class @InputHtml extends InputString
|
|
69
59
|
|
70
60
|
@config.onInitialize?(this)
|
71
61
|
|
72
|
-
|
73
62
|
updateValue: (@value) ->
|
74
63
|
@editor.getSession().setValue(@value)
|
75
64
|
@$input.val(@value)
|
76
65
|
|
77
|
-
|
78
66
|
chr.formInputs['html'] = InputHtml
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
@@ -1,4 +1,7 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
+
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
|
+
# Slate Studio (http://www.slatestudio.com)
|
4
|
+
# -----------------------------------------------------------------------------
|
2
5
|
# INPUT FILE IMAGE
|
3
6
|
# -----------------------------------------------------------------------------
|
4
7
|
# Config options:
|
@@ -18,11 +21,9 @@ class @InputFileImage extends InputFile
|
|
18
21
|
@_add_clear_button()
|
19
22
|
@_add_remove_checkbox()
|
20
23
|
|
21
|
-
|
22
24
|
_update_inputs: ->
|
23
25
|
@$link.html(@filename).attr('title', @filename).attr('href', @value.url)
|
24
26
|
image_thumb_url = if @config.thumbnail then @config.thumbnail(@object) else @value.url
|
25
27
|
@$thumb.attr('src', image_thumb_url).attr('alt', @filename)
|
26
28
|
|
27
|
-
|
28
29
|
chr.formInputs['image'] = InputFileImage
|
@@ -1,11 +1,6 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT LIST
|
11
6
|
# -----------------------------------------------------------------------------
|
@@ -17,12 +12,10 @@
|
|
17
12
|
# Dependencies:
|
18
13
|
#= require ./list_reorder
|
19
14
|
#= require ./list_typeahead
|
20
|
-
#
|
21
15
|
# -----------------------------------------------------------------------------
|
22
|
-
|
23
16
|
class @InputList extends InputString
|
24
17
|
|
25
|
-
# PRIVATE
|
18
|
+
# PRIVATE ===================================================================
|
26
19
|
|
27
20
|
_add_input: ->
|
28
21
|
# @TODO: check if we can use @config.name instead of @config.target
|
@@ -47,7 +40,6 @@ class @InputList extends InputString
|
|
47
40
|
@_render_items()
|
48
41
|
@_update_input_value()
|
49
42
|
|
50
|
-
|
51
43
|
_update_input_value: ->
|
52
44
|
ids = []
|
53
45
|
@$items.children('li').each (i, el) -> ids.push $(el).attr('data-id')
|
@@ -57,7 +49,6 @@ class @InputList extends InputString
|
|
57
49
|
@$input.val(value)
|
58
50
|
@$input.trigger('change')
|
59
51
|
|
60
|
-
|
61
52
|
_remove_item: ($el) ->
|
62
53
|
id = $el.attr('data-id')
|
63
54
|
delete @objects[id]
|
@@ -65,13 +56,11 @@ class @InputList extends InputString
|
|
65
56
|
$el.parent().remove()
|
66
57
|
@_update_input_value()
|
67
58
|
|
68
|
-
|
69
59
|
_ordered_ids: ->
|
70
60
|
ids = @$input.val().split(',')
|
71
61
|
if ids[0] == '' then ids = []
|
72
62
|
return ids
|
73
63
|
|
74
|
-
|
75
64
|
_render_items: ->
|
76
65
|
@$items.html('')
|
77
66
|
@objects = {}
|
@@ -79,7 +68,6 @@ class @InputList extends InputString
|
|
79
68
|
for o in @value
|
80
69
|
@_render_item(o)
|
81
70
|
|
82
|
-
|
83
71
|
_render_item: (o) ->
|
84
72
|
@_add_object(o)
|
85
73
|
|
@@ -99,18 +87,15 @@ class @InputList extends InputString
|
|
99
87
|
@$items.append(listItem)
|
100
88
|
@_update_input_value()
|
101
89
|
|
102
|
-
|
103
90
|
_add_object: (o) ->
|
104
91
|
@_normalize_object(o)
|
105
92
|
@objects[o._id] = o
|
106
93
|
|
107
|
-
|
108
94
|
_normalize_object: (o) ->
|
109
95
|
o._id ?= o.id
|
110
96
|
if ! o._id then console.log("::: list item is missing an 'id' or '_id' :::")
|
111
97
|
|
112
|
-
|
113
|
-
# PUBLIC ================================================
|
98
|
+
# PUBLIC ====================================================================
|
114
99
|
|
115
100
|
initialize: ->
|
116
101
|
@config.beforeInitialize?(this)
|
@@ -127,11 +112,9 @@ class @InputList extends InputString
|
|
127
112
|
|
128
113
|
@config.onInitialize?(this)
|
129
114
|
|
130
|
-
|
131
115
|
updateValue: (@value) ->
|
132
116
|
@_render_items()
|
133
117
|
|
134
|
-
|
135
118
|
hash: (hash={}) ->
|
136
119
|
hash[@config.target] = @$input.val()
|
137
120
|
ordered_objects = []
|
@@ -142,9 +125,7 @@ class @InputList extends InputString
|
|
142
125
|
hash[@config.klassName] = ordered_objects
|
143
126
|
return hash
|
144
127
|
|
145
|
-
|
146
128
|
include(InputList, inputListReorder)
|
147
129
|
include(InputList, inputListTypeahead)
|
148
130
|
|
149
|
-
|
150
131
|
chr.formInputs['list'] = InputList
|
@@ -1,18 +1,11 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT LIST REORDER
|
11
6
|
# -----------------------------------------------------------------------------
|
12
|
-
|
13
7
|
@inputListReorder =
|
14
|
-
|
15
|
-
# PRIVATE ===============================================
|
8
|
+
# PRIVATE ===================================================================
|
16
9
|
|
17
10
|
_bind_reorder: ->
|
18
11
|
list = @$items.get(0)
|
@@ -33,7 +26,3 @@
|
|
33
26
|
@_update_input_value()
|
34
27
|
return false
|
35
28
|
), false
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
@@ -1,25 +1,17 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT LIST TYPEAHEAD
|
11
6
|
# -----------------------------------------------------------------------------
|
12
|
-
|
13
7
|
@inputListTypeahead =
|
14
|
-
|
15
|
-
# PRIVATE ===============================================
|
8
|
+
# PRIVATE ===================================================================
|
16
9
|
|
17
10
|
_create_typeahead_el: (placeholder) ->
|
18
11
|
# typeahead input for adding new items
|
19
12
|
@typeaheadInput =$ "<input type='text' placeholder='#{ placeholder }' />"
|
20
13
|
@$el.append @typeaheadInput
|
21
14
|
|
22
|
-
|
23
15
|
_bind_typeahead: ->
|
24
16
|
limit = @config.typeahead.limit || 5
|
25
17
|
dataSource = new Bloodhound
|
@@ -49,7 +41,3 @@
|
|
49
41
|
@typeaheadInput.on 'typeahead:selected', (e, object, dataset) =>
|
50
42
|
@_render_item(object)
|
51
43
|
@typeaheadInput.typeahead('val', '')
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
@@ -1,11 +1,6 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
2
|
# Author: Alexander Kravets <alex@slatestudio.com>,
|
3
3
|
# Slate Studio (http://www.slatestudio.com)
|
4
|
-
#
|
5
|
-
# Coding Guide:
|
6
|
-
# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
|
7
|
-
# -----------------------------------------------------------------------------
|
8
|
-
|
9
4
|
# -----------------------------------------------------------------------------
|
10
5
|
# INPUT MARKDOWN
|
11
6
|
# -----------------------------------------------------------------------------
|
@@ -23,12 +18,9 @@
|
|
23
18
|
#= require vendor/marked
|
24
19
|
#= require vendor/ace
|
25
20
|
#= require vendor/mode-markdown
|
26
|
-
#
|
27
21
|
# -----------------------------------------------------------------------------
|
28
|
-
|
29
22
|
class @InputMarkdown extends InputString
|
30
|
-
|
31
|
-
# PRIVATE ===============================================
|
23
|
+
# PRIVATE ===================================================================
|
32
24
|
|
33
25
|
_add_input: ->
|
34
26
|
if @config.htmlFieldName
|
@@ -43,7 +35,6 @@ class @InputMarkdown extends InputString
|
|
43
35
|
@$editor =$ "<div></div>"
|
44
36
|
@$el.append @$editor
|
45
37
|
|
46
|
-
|
47
38
|
_update_inputs: ->
|
48
39
|
md_source = @session.getValue()
|
49
40
|
@$input.val(md_source)
|
@@ -54,8 +45,7 @@ class @InputMarkdown extends InputString
|
|
54
45
|
@$inputHtml.val(html)
|
55
46
|
@$inputHtml.trigger('change')
|
56
47
|
|
57
|
-
|
58
|
-
# PUBLIC ================================================
|
48
|
+
# PUBLIC ====================================================================
|
59
49
|
|
60
50
|
initialize: ->
|
61
51
|
@config.beforeInitialize?(this)
|
@@ -84,19 +74,13 @@ class @InputMarkdown extends InputString
|
|
84
74
|
|
85
75
|
@config.onInitialize?(this)
|
86
76
|
|
87
|
-
|
88
77
|
updateValue: (@value) ->
|
89
78
|
@session.setValue(@value)
|
90
79
|
@_update_inputs()
|
91
80
|
|
92
|
-
|
93
81
|
hash: (hash={}) ->
|
94
82
|
hash[@config.htmlFieldName] = @$inputHtml.val()
|
95
83
|
hash[@config.klassName] = @$input.val()
|
96
84
|
return hash
|
97
85
|
|
98
86
|
chr.formInputs['markdown'] = InputMarkdown
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|