formagic 0.3.4 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/app/assets/javascripts/formagic.coffee +2 -0
  4. data/app/assets/javascripts/formagic/form.coffee +9 -39
  5. data/app/assets/javascripts/formagic/group.coffee +1 -11
  6. data/app/assets/javascripts/formagic/inputs/array.coffee +8 -26
  7. data/app/assets/javascripts/formagic/inputs/checkbox.coffee +3 -20
  8. data/app/assets/javascripts/formagic/inputs/color.coffee +2 -16
  9. data/app/assets/javascripts/formagic/inputs/date.coffee +6 -24
  10. data/app/assets/javascripts/formagic/inputs/datetime.coffee +6 -27
  11. data/app/assets/javascripts/formagic/inputs/document.coffee +9 -25
  12. data/app/assets/javascripts/formagic/inputs/documents.coffee +11 -32
  13. data/app/assets/javascripts/formagic/inputs/documents_reorder.coffee +1 -12
  14. data/app/assets/javascripts/formagic/inputs/file.coffee +2 -22
  15. data/app/assets/javascripts/formagic/inputs/hash.coffee +1 -4
  16. data/app/assets/javascripts/formagic/inputs/hidden.coffee +2 -19
  17. data/app/assets/javascripts/formagic/inputs/html.coffee +2 -18
  18. data/app/assets/javascripts/formagic/inputs/image.coffee +3 -2
  19. data/app/assets/javascripts/formagic/inputs/list.coffee +2 -21
  20. data/app/assets/javascripts/formagic/inputs/list_reorder.coffee +1 -12
  21. data/app/assets/javascripts/formagic/inputs/list_typeahead.coffee +1 -13
  22. data/app/assets/javascripts/formagic/inputs/markdown.coffee +2 -18
  23. data/app/assets/javascripts/formagic/inputs/password.coffee +2 -14
  24. data/app/assets/javascripts/formagic/inputs/redactor.coffee +2 -18
  25. data/app/assets/javascripts/formagic/inputs/redactor_character.coffee +1 -13
  26. data/app/assets/javascripts/formagic/inputs/redactor_images.coffee +0 -13
  27. data/app/assets/javascripts/formagic/inputs/select.coffee +2 -21
  28. data/app/assets/javascripts/formagic/inputs/select2.coffee +0 -13
  29. data/app/assets/javascripts/formagic/inputs/select2_multiple.coffee +90 -0
  30. data/app/assets/javascripts/formagic/inputs/select2_single.coffee +57 -0
  31. data/app/assets/javascripts/formagic/inputs/string.coffee +13 -34
  32. data/app/assets/javascripts/formagic/inputs/text.coffee +2 -13
  33. data/app/assets/javascripts/formagic/inputs/url.coffee +3 -12
  34. data/app/assets/stylesheets/formagic.scss +2 -0
  35. data/app/assets/stylesheets/formagic/actions.scss +9 -0
  36. data/app/assets/stylesheets/formagic/form.scss +16 -24
  37. data/app/assets/stylesheets/formagic/nested-form.scss +3 -9
  38. data/app/assets/stylesheets/formagic/select.scss +24 -5
  39. data/app/assets/stylesheets/formagic/url.scss +5 -0
  40. data/lib/formagic/version.rb +1 -1
  41. metadata +6 -2
@@ -1,23 +1,16 @@
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 DATE
11
6
  # -----------------------------------------------------------------------------
12
- #
13
7
  # Dependencies:
14
8
  #= require vendor/datedropper
15
9
  #= require vendor/moment
16
- #
17
10
  # -----------------------------------------------------------------------------
18
11
  class @InputDate extends InputString
19
12
 
20
- # PRIVATE ===============================================
13
+ # PRIVATE ===================================================================
21
14
 
22
15
  _update_date_label: ->
23
16
  date = @$input.val()
@@ -30,8 +23,6 @@ class @InputDate extends InputString
30
23
 
31
24
  @$dateLabel.html(date_formatted)
32
25
 
33
-
34
-
35
26
  _add_input: ->
36
27
  @$input =$ "<input type='text' name='#{ @name }' value='#{ @_safe_value() }' class='input-datetime-date' />"
37
28
  @$el.append @$input
@@ -45,25 +36,22 @@ class @InputDate extends InputString
45
36
 
46
37
  @_add_actions()
47
38
 
48
-
49
39
  _add_actions: ->
50
40
  @$actions =$ "<span class='input-actions'></span>"
51
41
  @$label.append @$actions
52
42
 
53
- @_add_remove_button()
54
-
43
+ if not @config.disableClear
44
+ @_add_clear_button()
55
45
 
56
- _add_remove_button: ->
57
- @$removeBtn =$ "<a href='#' class='remove'>Remove</a>"
46
+ _add_clear_button: ->
47
+ @$removeBtn =$ "<button class='clear'>Clear</button>"
58
48
  @$actions.append @$removeBtn
59
49
 
60
50
  @$removeBtn.on 'click', (e) =>
61
- e.preventDefault()
62
51
  @updateValue('')
63
52
  @_update_date_label()
64
53
 
65
-
66
- # PUBLIC ================================================
54
+ # PUBLIC ====================================================================
67
55
 
68
56
  initialize: ->
69
57
  @config.beforeInitialize?(this)
@@ -81,14 +69,8 @@ class @InputDate extends InputString
81
69
 
82
70
  @config.onInitialize?(this)
83
71
 
84
-
85
72
  updateValue: (@value) ->
86
73
  @$input.val(@value)
87
74
  @_update_date_label()
88
75
 
89
-
90
76
  chr.formInputs['date'] = InputDate
91
-
92
-
93
-
94
-
@@ -1,23 +1,16 @@
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 DATE
11
6
  # -----------------------------------------------------------------------------
12
- #
13
7
  # Dependencies:
14
8
  #= require vendor/datedropper
15
9
  #= require vendor/moment
16
- #
17
10
  # -----------------------------------------------------------------------------
18
11
  class @InputDatetime extends InputDate
19
12
 
20
- # PRIVATE ===============================================
13
+ # PRIVATE ===================================================================
21
14
 
22
15
  _update_value: ->
23
16
  mt = moment(@$inputTime.val(), 'LT')
@@ -36,23 +29,19 @@ class @InputDatetime extends InputDate
36
29
 
37
30
  @$input.val(value)
38
31
 
39
-
40
32
  _update_date_input: ->
41
33
  m = moment(@$input.val()).utcOffset(@tzOffset)
42
34
  @$inputDate.val ( if m.isValid() then m.format('YYYY-MM-DD') else '' )
43
35
 
44
-
45
36
  _update_time_input: ->
46
37
  m = moment(@$input.val()).utcOffset(@tzOffset)
47
38
  @$inputTime.val ( if m.isValid() then m.format('h:mm a') else '' )
48
39
 
49
-
50
40
  _update_date_label: ->
51
41
  m = moment(@$inputDate.val()).utcOffset(@tzOffset)
52
42
  label = if m.isValid() then m.format('dddd, MMM D, YYYY') else "<span class='placeholder'>Pick a date</span>"
53
43
  @$dateLabel.html label
54
44
 
55
-
56
45
  _normalized_value: ->
57
46
  # -- use local timezone to represent time
58
47
  @tzOffset = @config.timezoneOffset
@@ -61,7 +50,6 @@ class @InputDatetime extends InputDate
61
50
  m = moment(@value).utcOffset(@tzOffset)
62
51
  @value = if m.isValid() then m.format() else ''
63
52
 
64
-
65
53
  _add_input: ->
66
54
  @_normalized_value()
67
55
 
@@ -97,27 +85,24 @@ class @InputDatetime extends InputDate
97
85
 
98
86
  @_add_actions()
99
87
 
100
-
101
88
  _add_actions: ->
102
89
  @$actions =$ "<span class='input-actions'></span>"
103
90
  @$label.append @$actions
104
91
 
105
- @_add_remove_button()
92
+ if not @config.disableClear
93
+ @_add_clear_button()
106
94
 
107
-
108
- _add_remove_button: ->
109
- @$removeBtn =$ "<a href='#' class='remove'>Remove</a>"
95
+ _add_clear_button: ->
96
+ @$removeBtn =$ "<button class='clear'>Clear</button>"
110
97
  @$actions.append @$removeBtn
111
98
 
112
99
  @$removeBtn.on 'click', (e) =>
113
- e.preventDefault()
114
100
  @$inputTime.val('')
115
101
  @$inputDate.val('')
116
102
  @_update_date_label()
117
103
  @_update_value()
118
104
 
119
-
120
- # PUBLIC ================================================
105
+ # PUBLIC ====================================================================
121
106
 
122
107
  initialize: ->
123
108
  @config.beforeInitialize?(this)
@@ -141,7 +126,6 @@ class @InputDatetime extends InputDate
141
126
 
142
127
  @config.onInitialize?(this)
143
128
 
144
-
145
129
  updateValue: (@value) ->
146
130
  @_normalized_value()
147
131
  @$input.val(@value)
@@ -150,9 +134,4 @@ class @InputDatetime extends InputDate
150
134
  @_update_date_label()
151
135
  @_update_time_input()
152
136
 
153
-
154
137
  chr.formInputs['datetime'] = InputDatetime
155
-
156
-
157
-
158
-
@@ -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 DOCUMENT
11
6
  # -----------------------------------------------------------------------------
@@ -18,9 +13,7 @@
18
13
  # updateValue(@value)
19
14
  # showErrorMessage(message)
20
15
  # hideErrorMessage()
21
- #
22
16
  # -----------------------------------------------------------------------------
23
-
24
17
  class @InputDocument
25
18
  constructor: (@name, @nestedObject, @config, @object) ->
26
19
  @forms = []
@@ -40,19 +33,21 @@ class @InputDocument
40
33
 
41
34
  return this
42
35
 
43
-
44
- # PRIVATE ===============================================
36
+ # PRIVATE ===================================================================
45
37
 
46
38
  _create_el: ->
47
39
  @$el =$ "<div class='form-input nested-forms input-#{ @config.klassName }'>"
48
40
 
49
-
50
41
  _add_label: ->
51
- @$label =$ "<span class='label'>#{ @config.label }</span>"
42
+ @$label =$ "<span class='label'></span>"
43
+ @$labelTitle =$ "<span class='label-title'>#{ @config.label }</span>"
52
44
  @$errorMessage =$ "<span class='error-message'></span>"
53
- @$label.append(@$errorMessage)
54
- @$el.append(@$label)
45
+ @$label.append @$labelTitle
46
+ @$label.append @$errorMessage
47
+ @$el.append @$label
55
48
 
49
+ if @config.label == false
50
+ @$labelTitle.hide()
56
51
 
57
52
  _add_forms: ->
58
53
  @nestedForm = @_render_form(@nestedObject, @config.namePrefix, @config)
@@ -62,7 +57,6 @@ class @InputDocument
62
57
  @$form = @nestedForm.$el
63
58
  @$label.after @$form
64
59
 
65
-
66
60
  _render_form: (object, namePrefix, config) ->
67
61
  formConfig = $.extend {}, config,
68
62
  namePrefix: namePrefix
@@ -72,8 +66,7 @@ class @InputDocument
72
66
  form = new Form(object, formConfig)
73
67
  return form
74
68
 
75
-
76
- # PUBLIC ================================================
69
+ # PUBLIC ====================================================================
77
70
 
78
71
  initialize: ->
79
72
  @config.beforeInitialize?(this)
@@ -82,31 +75,22 @@ class @InputDocument
82
75
 
83
76
  @config.onInitialize?(this)
84
77
 
85
-
86
78
  hash: (hash={}) ->
87
79
  objects = []
88
80
  hash[@config.fieldName] = @nestedForm.hash()
89
81
  return hash
90
82
 
91
-
92
83
  showErrorMessage: (message) ->
93
84
  @$el.addClass 'error'
94
85
  @$errorMessage.html(message)
95
86
 
96
-
97
87
  hideErrorMessage: ->
98
88
  @$el.removeClass 'error'
99
89
  @$errorMessage.html('')
100
90
 
101
-
102
91
  updateValue: (@nestedObject, @object) ->
103
92
  for name, value of @nestedObject
104
93
  if @nestedForm.inputs[name]
105
94
  @nestedForm.inputs[name].updateValue(value, @object)
106
95
 
107
-
108
96
  chr.formInputs['document'] = InputDocument
109
-
110
-
111
-
112
-
@@ -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 "NESTED" FORM
11
6
  # -----------------------------------------------------------------------------
@@ -21,9 +16,7 @@
21
16
  #
22
17
  # Dependencies:
23
18
  #= require ./documents_reorder
24
- #
25
19
  # -----------------------------------------------------------------------------
26
-
27
20
  class @InputForm
28
21
  constructor: (@name, @nestedObjects, @config, @object) ->
29
22
  @forms = []
@@ -46,26 +39,27 @@ class @InputForm
46
39
 
47
40
  return this
48
41
 
49
-
50
- # PRIVATE ===============================================
42
+ # PRIVATE ===================================================================
51
43
 
52
44
  _create_el: ->
53
45
  @$el =$ "<div class='form-input nested-forms input-#{ @config.klassName }'>"
54
46
 
55
-
56
47
  _add_label: ->
57
- @$label =$ "<span class='label'>#{ @config.label }</span>"
48
+ @$label =$ "<span class='label'></span>"
49
+ @$labelTitle =$ "<span class='label-title'>#{ @config.label }</span>"
58
50
  @$errorMessage =$ "<span class='error-message'></span>"
59
- @$label.append(@$errorMessage)
60
- @$el.append(@$label)
51
+ @$label.append @$labelTitle
52
+ @$label.append @$errorMessage
53
+ @$el.append @$label
61
54
 
55
+ if @config.label == false
56
+ @$labelTitle.hide()
62
57
 
63
58
  _extend_schema_with: (name, config) ->
64
59
  schemaConfig = {}
65
60
  schemaConfig[name] = config
66
61
  @config.formSchema = $.extend(schemaConfig, @config.formSchema)
67
62
 
68
-
69
63
  _add_forms: ->
70
64
  # add id to schema
71
65
  # @NOTE: here we use _id, cause mongosteen returns objects _id, but we should send id for nested documents
@@ -88,7 +82,6 @@ class @InputForm
88
82
 
89
83
  @_bind_forms_reorder()
90
84
 
91
-
92
85
  _sort_nested_objects: ->
93
86
  if @config.sortBy
94
87
  if @nestedObjects
@@ -98,7 +91,6 @@ class @InputForm
98
91
  # normalizes nested objects positions
99
92
  (o[@config.sortBy] = parseInt(i) + 1) for i, o of @nestedObjects
100
93
 
101
-
102
94
  _render_form: (object, namePrefix, config) ->
103
95
  formConfig = $.extend {}, config,
104
96
  namePrefix: namePrefix
@@ -109,18 +101,16 @@ class @InputForm
109
101
 
110
102
  return form
111
103
 
112
-
113
104
  _add_new_button: ->
114
105
  if ! @config.disableNewDocuments
115
106
  label = @config.newButtonLabel || "Add"
116
107
 
117
- @$newButton =$ """<a href='#' class='nested-form-new'>#{ label }</a>"""
108
+ @$newButton =$ """<button class='nested-form-new'>#{ label }</button>"""
118
109
  @$el.append @$newButton
119
110
 
120
- @$newButton.on 'click', (e) => e.preventDefault() ; @addNewForm()
121
-
111
+ @$newButton.on 'click', (e) => @addNewForm()
122
112
 
123
- # PUBLIC ================================================
113
+ # PUBLIC ====================================================================
124
114
 
125
115
  initialize: ->
126
116
  @config.beforeInitialize?(this)
@@ -130,24 +120,20 @@ class @InputForm
130
120
 
131
121
  @config.onInitialize?(this)
132
122
 
133
-
134
123
  hash: (hash={}) ->
135
124
  objects = []
136
125
  objects.push(form.hash()) for form in @forms
137
126
  hash[@config.fieldName] = objects
138
127
  return hash
139
128
 
140
-
141
129
  showErrorMessage: (message) ->
142
130
  @$el.addClass 'error'
143
131
  @$errorMessage.html(message)
144
132
 
145
-
146
133
  hideErrorMessage: ->
147
134
  @$el.removeClass 'error'
148
135
  @$errorMessage.html('')
149
136
 
150
-
151
137
  addNewForm: (object=null) ->
152
138
  namePrefix = "#{ @config.namePrefix }[#{ Date.now() }]"
153
139
  newFormConfig = $.extend({}, @config)
@@ -173,7 +159,6 @@ class @InputForm
173
159
 
174
160
  return form
175
161
 
176
-
177
162
  updateValue: (@nestedObjects, @object) ->
178
163
  # New document should update id, also after uploading images form for existing
179
164
  # document might change, so we reset all nested forms to reflect these updates.
@@ -187,13 +172,7 @@ class @InputForm
187
172
  for nestedForm in @forms
188
173
  nestedForm.initializePlugins()
189
174
 
190
-
191
175
  include(InputForm, inputFormReorder)
192
176
 
193
-
194
177
  chr.formInputs['form'] = InputForm
195
178
  chr.formInputs['documents'] = InputForm
196
-
197
-
198
-
199
-
@@ -1,17 +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 "NESTED" FORM REORDER
11
6
  # -----------------------------------------------------------------------------
12
-
13
7
  @inputFormReorder =
14
- # PRIVATE ===============================================
8
+ # PRIVATE ===================================================================
15
9
 
16
10
  _bind_forms_reorder: ->
17
11
  if @config.sortBy
@@ -52,7 +46,6 @@
52
46
 
53
47
  @_add_form_reorder_button(form) for form in @forms
54
48
 
55
-
56
49
  _add_form_reorder_button: (form) ->
57
50
  reorderIcon = """<div class='icon-reorder'
58
51
  data-container-class='#{@reorderContainerClass}'>
@@ -60,12 +53,8 @@
60
53
  </div>"""
61
54
  form.$el.prepend(reorderIcon).addClass('reorderable')
62
55
 
63
-
64
56
  _find_form_by_target: (el) ->
65
57
  if el
66
58
  for form in @forms
67
59
  if form.$el.get(0) == el then return form
68
60
  return null
69
-
70
-
71
-