formagic 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/CONTRIBUTING.md +24 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE.md +21 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/app/assets/images/datedropper/done.png +0 -0
  9. data/app/assets/images/datedropper/done.svg +1 -0
  10. data/app/assets/images/datedropper/next.png +0 -0
  11. data/app/assets/images/datedropper/next.svg +1 -0
  12. data/app/assets/images/datedropper/prev.png +0 -0
  13. data/app/assets/images/datedropper/prev.svg +1 -0
  14. data/app/assets/javascripts/formagic/form.coffee +229 -0
  15. data/app/assets/javascripts/formagic/group.coffee +28 -0
  16. data/app/assets/javascripts/formagic/inputs/checkbox.coffee +83 -0
  17. data/app/assets/javascripts/formagic/inputs/color.coffee +55 -0
  18. data/app/assets/javascripts/formagic/inputs/date.coffee +69 -0
  19. data/app/assets/javascripts/formagic/inputs/datetime.coffee +130 -0
  20. data/app/assets/javascripts/formagic/inputs/document.coffee +0 -0
  21. data/app/assets/javascripts/formagic/inputs/documents.coffee +173 -0
  22. data/app/assets/javascripts/formagic/inputs/documents_reorder.coffee +67 -0
  23. data/app/assets/javascripts/formagic/inputs/file.coffee +114 -0
  24. data/app/assets/javascripts/formagic/inputs/hidden.coffee +57 -0
  25. data/app/assets/javascripts/formagic/inputs/html.coffee +81 -0
  26. data/app/assets/javascripts/formagic/inputs/image.coffee +28 -0
  27. data/app/assets/javascripts/formagic/inputs/list.coffee +154 -0
  28. data/app/assets/javascripts/formagic/inputs/list_reorder.coffee +39 -0
  29. data/app/assets/javascripts/formagic/inputs/list_typeahead.coffee +55 -0
  30. data/app/assets/javascripts/formagic/inputs/markdown.coffee +93 -0
  31. data/app/assets/javascripts/formagic/inputs/password.coffee +32 -0
  32. data/app/assets/javascripts/formagic/inputs/redactor.coffee +53 -0
  33. data/app/assets/javascripts/formagic/inputs/redactor_character.coffee +75 -0
  34. data/app/assets/javascripts/formagic/inputs/redactor_images.coffee +166 -0
  35. data/app/assets/javascripts/formagic/inputs/select.coffee +84 -0
  36. data/app/assets/javascripts/formagic/inputs/select2.coffee +33 -0
  37. data/app/assets/javascripts/formagic/inputs/string.coffee +160 -0
  38. data/app/assets/javascripts/formagic/inputs/text.coffee +43 -0
  39. data/app/assets/javascripts/formagic/inputs/time.coffee +0 -0
  40. data/app/assets/javascripts/formagic.coffee +22 -0
  41. data/app/assets/javascripts/vendor/ace.js +18280 -0
  42. data/app/assets/javascripts/vendor/datedropper.js +1005 -0
  43. data/app/assets/javascripts/vendor/jquery.scrollparent.js +14 -0
  44. data/app/assets/javascripts/vendor/jquery.textarea_autosize.js +55 -0
  45. data/app/assets/javascripts/vendor/jquery.typeahead.js +1782 -0
  46. data/app/assets/javascripts/vendor/marked.js +1272 -0
  47. data/app/assets/javascripts/vendor/mode-html.js +2436 -0
  48. data/app/assets/javascripts/vendor/mode-markdown.js +2820 -0
  49. data/app/assets/javascripts/vendor/moment.js +3083 -0
  50. data/app/assets/javascripts/vendor/redactor.fixedtoolbar.js +107 -0
  51. data/app/assets/javascripts/vendor/select2.js +5274 -0
  52. data/app/assets/stylesheets/formagic/checkbox.scss +8 -0
  53. data/app/assets/stylesheets/formagic/color.scss +12 -0
  54. data/app/assets/stylesheets/formagic/date.scss +37 -0
  55. data/app/assets/stylesheets/formagic/file.scss +29 -0
  56. data/app/assets/stylesheets/formagic/form.scss +36 -0
  57. data/app/assets/stylesheets/formagic/group.scss +22 -0
  58. data/app/assets/stylesheets/formagic/image.scss +19 -0
  59. data/app/assets/stylesheets/formagic/list.scss +39 -0
  60. data/app/assets/stylesheets/formagic/nested-form.scss +23 -0
  61. data/app/assets/stylesheets/formagic/redactor.scss +41 -0
  62. data/app/assets/stylesheets/formagic/select.scss +5 -0
  63. data/app/assets/stylesheets/formagic/select2.scss +95 -0
  64. data/app/assets/stylesheets/formagic/string.scss +14 -0
  65. data/app/assets/stylesheets/formagic/switch.scss +86 -0
  66. data/app/assets/stylesheets/formagic/text.scss +9 -0
  67. data/app/assets/stylesheets/formagic.scss +15 -0
  68. data/app/assets/stylesheets/vendor/datedropper.scss +523 -0
  69. data/app/assets/stylesheets/vendor/select2.scss +258 -0
  70. data/formagic.gemspec +30 -0
  71. data/lib/formagic/engine.rb +5 -0
  72. data/lib/formagic/version.rb +3 -0
  73. data/lib/formagic.rb +5 -0
  74. metadata +146 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eaeeb3489a798aafed4d51440ab9fb4d933f9f27
4
+ data.tar.gz: c0717929f3661809eeab159d8419b940d38eb5a4
5
+ SHA512:
6
+ metadata.gz: e41c4ae09383eed7c534784e4b8896e7938a3171c11dad5adbf282783cdec2089c798b8b1ca2816ec73ede8aade18c1973a055fbaf4790297538badf695ada8f
7
+ data.tar.gz: 0d8465bdc12df5d3d1e9d0e39cf57c10881552519899e0a8589cbf9bc1fb75b90dc8c1f2cbba7915b699e79350695f5dd750d48a784718db6aadf182db338f9d
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg/
2
+ .DS_Store
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,24 @@
1
+ We love pull requests. Here’s a quick guide:
2
+
3
+ 1. Fork the repository.
4
+ 2. Make your changes in a topic branch.
5
+ 3. Squash your commits into a single one (more on that [here](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html)).
6
+ 4. Rebase against `origin/master`, push to your fork and submit a pull request.
7
+ 5. If you are writing a new feature please add documentation for it by making another pull request to the `gh-pages` branch.
8
+
9
+ At this point you’re waiting on us. We like to at least comment on, if not
10
+ accept, pull requests within three business days (and, typically, one business
11
+ day). We may suggest some changes or improvements or alternatives.
12
+
13
+ Some things that will increase the chance that your pull request is accepted:
14
+
15
+ * Fix a bug, refactor code or expand an existing feature.
16
+ * Use the right syntax and naming conventions.
17
+ * Update parts of the documentation that are affected by your contribution.
18
+
19
+ **Git Commit Messages**
20
+
21
+ * Capitalize your commit messages.
22
+ * Start your message with a verb.
23
+ * Use present tense.
24
+ * Refer to the issue/PR number in your squashed commit message.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2015 [Slate Studio, LLC](http://slatestudio.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the “Software”), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Formagic
2
+
3
+ *Easy to use javascript forms builder*
4
+
5
+ This library is heavily used by Character project and provides a very easy and convinient way to build and customize forms with javascript. This supposed to be working with Rails on the first place.
6
+
7
+
8
+ ## Formagic Family:
9
+
10
+ - [Character](https://github.com/slate-studio/chr): Powerful responsive javascript CMS for apps
11
+ - [Mongosteen](https://github.com/slate-studio/mongosteen): An easy way to add RESTful actions for Mongoid models
12
+ - [Inverter](https://github.com/slate-studio/inverter): An easy way to connect Rails templates content to Character CMS
13
+ - [Loft](https://github.com/slate-studio/loft): Media assets manager for Character CMS
14
+
15
+
16
+ ## License
17
+
18
+ Copyright © 2015 [Slate Studio, LLC](http://slatestudio.com). Formagic is free software, and may be redistributed under the terms specified in the [license](LICENSE.md).
19
+
20
+
21
+ ## About Slate Studio
22
+
23
+ [![Slate Studio](https://slate-git-images.s3-us-west-1.amazonaws.com/slate.png)](http://slatestudio.com)
24
+
25
+ Formagic is maintained and funded by [Slate Studio, LLC](http://slatestudio.com). Tweet your questions or suggestions to [@slatestudio](https://twitter.com/slatestudio) and while you’re at it follow us too.
26
+
27
+
28
+
29
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 32 32" height="32px" id="Layer_1" version="1.1" viewBox="0 0 32 32" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M30.171,6.131l-0.858-0.858c-0.944-0.945-2.489-0.945-3.433,0L11.294,19.859l-5.175-5.174 c-0.943-0.944-2.489-0.944-3.432,0.001l-0.858,0.857c-0.943,0.944-0.943,2.489,0,3.433l7.744,7.75c0.944,0.945,2.489,0.945,3.433,0 L30.171,9.564C31.112,8.62,31.112,7.075,30.171,6.131z" fill="#f8f8f8"/></svg>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 32 32" height="32px" id="Layer_1" version="1.1" viewBox="0 0 32 32" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M24.291,14.276L14.705,4.69c-0.878-0.878-2.317-0.878-3.195,0l-0.8,0.8c-0.878,0.877-0.878,2.316,0,3.194 L18.024,16l-7.315,7.315c-0.878,0.878-0.878,2.317,0,3.194l0.8,0.8c0.878,0.879,2.317,0.879,3.195,0l9.586-9.587 c0.472-0.471,0.682-1.103,0.647-1.723C24.973,15.38,24.763,14.748,24.291,14.276z" fill="#dddddd"/></svg>
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'><svg enable-background="new 0 0 32 32" height="32px" id="Layer_1" version="1.1" viewBox="0 0 32 32" width="32px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M7.701,14.276l9.586-9.585c0.879-0.878,2.317-0.878,3.195,0l0.801,0.8c0.878,0.877,0.878,2.316,0,3.194 L13.968,16l7.315,7.315c0.878,0.878,0.878,2.317,0,3.194l-0.801,0.8c-0.878,0.879-2.316,0.879-3.195,0l-9.586-9.587 C7.229,17.252,7.02,16.62,7.054,16C7.02,15.38,7.229,14.748,7.701,14.276z" fill="#dddddd"/></svg>
@@ -0,0 +1,229 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # FORM
11
+ # -----------------------------------------------------------------------------
12
+ #
13
+ # Generates form based on provided configuration schema. If schema is not
14
+ # provided generates default form based on object keys. This uses Rails
15
+ # conventions for managing names for attributes, arrays, hashs and nested
16
+ # objects.
17
+ #
18
+ # -----------------------------------------------------------------------------
19
+
20
+ class @Form
21
+ constructor: (@object, @config) ->
22
+ @groups = []
23
+ @inputs = {}
24
+ @$el = $(@config.rootEl || "<form class='form'>")
25
+ @schema = @_get_schema()
26
+ @isRemoved = false
27
+
28
+ @_build_schema(@schema, @$el)
29
+ @_add_nested_form_remove_button()
30
+
31
+
32
+ # PRIVATE ===============================================
33
+
34
+ _get_schema: ->
35
+ schema = @config.formSchema
36
+ if @object
37
+ schema ?= @_generate_default_schema()
38
+ return schema
39
+
40
+
41
+ _generate_default_schema: ->
42
+ schema = {}
43
+ for key, value of @object
44
+ schema[key] = @_generate_default_input_config(key, value)
45
+ return schema
46
+
47
+
48
+ _generate_default_input_config: (fieldName, value) ->
49
+ config = {}
50
+
51
+ if fieldName[0] == '_'
52
+ config.type = 'hidden'
53
+
54
+ else if value in [ true, false ]
55
+ config.type = 'checkbox'
56
+
57
+ else if value
58
+
59
+ if value.hasOwnProperty('url')
60
+ config.type = 'file'
61
+
62
+ else if value.length > 60
63
+ config.type = 'text'
64
+
65
+ return config
66
+
67
+
68
+ # INPUTS ================================================
69
+
70
+ _build_schema: (schema, $el) ->
71
+ for fieldName, config of schema
72
+ config.fieldName = fieldName
73
+
74
+ if config.type == 'group'
75
+ group = @_generate_inputs_group(fieldName, config)
76
+ $el.append group.$el
77
+
78
+ else
79
+ input = @_generate_input(fieldName, config)
80
+ $el.append input.$el
81
+
82
+
83
+ _generate_inputs_group: (klassName, groupConfig) ->
84
+ $group =$ """<div class='group #{ klassName }' />"""
85
+
86
+ if groupConfig.inputs
87
+ @_build_schema(groupConfig.inputs, $group)
88
+
89
+ group = { $el: $group, klassName: klassName, onInitialize: groupConfig.onInitialize }
90
+ @groups.push group
91
+
92
+ return group
93
+
94
+
95
+ _generate_input: (fieldName, inputConfig) ->
96
+ if @object
97
+ value = @object[fieldName]
98
+
99
+ else
100
+ value = inputConfig.default
101
+
102
+ value ?= ''
103
+
104
+ inputName = inputConfig.name || fieldName
105
+ input = @_render_input(inputName, inputConfig, value)
106
+ @inputs[fieldName] = input
107
+
108
+ return input
109
+
110
+
111
+ _render_input: (name, config, value) ->
112
+ inputConfig = $.extend {}, config
113
+
114
+ inputConfig.label ?= name.titleize()
115
+ inputConfig.type ?= 'string'
116
+ inputConfig.klass ?= 'stacked'
117
+ inputConfig.klassName = name
118
+
119
+ inputClass = chr.formInputs[inputConfig.type]
120
+ inputClass ?= chr.formInputs['string']
121
+
122
+ inputName = if @config.namePrefix then "#{ @config.namePrefix }[#{ name }]" else "[#{ name }]"
123
+
124
+ # add prefix for nested form inputs
125
+ if inputConfig.type == 'form' || inputConfig.type == 'documents'
126
+ inputConfig.namePrefix = inputName.replace("[#{ name }]", "[#{ name }_attributes]")
127
+
128
+ else
129
+ inputConfig.namePrefix = @config.namePrefix
130
+
131
+ return new inputClass(inputName, value, inputConfig, @object)
132
+
133
+
134
+ # NESTED ================================================
135
+
136
+ _add_nested_form_remove_button: ->
137
+ if @config.removeButton
138
+ # add hidden input to the form
139
+ fieldName = '_destroy'
140
+ input = @_render_input(fieldName, { type: 'hidden' }, false)
141
+ @inputs[fieldName] = input
142
+ @$el.append input.$el
143
+ # remove button
144
+ @$removeButton =$ """<a href='#' class='nested-form-delete'>Delete</a>"""
145
+ @$el.append @$removeButton
146
+ @$removeButton.on 'click', (e) =>
147
+ e.preventDefault()
148
+ if confirm('Are you sure?')
149
+ input.updateValue('true')
150
+ @$el.hide()
151
+ @isRemoved = true
152
+ @config.onRemove?(this)
153
+
154
+
155
+ _forms: ->
156
+ forms = [ @ ]
157
+ addNestedForms = (form) ->
158
+ for name, input of form.inputs
159
+ if input.config.type == 'form' || input.config.type == 'documents'
160
+ forms = forms.concat(input.forms)
161
+ addNestedForms(form) for form in input.forms
162
+ addNestedForms(@)
163
+
164
+ return forms
165
+
166
+
167
+ # PUBLIC ================================================
168
+
169
+ destroy: ->
170
+ group.destroy?() for group in @groups
171
+ input.destroy?() for name, input of @inputs
172
+ @$el.remove()
173
+
174
+
175
+ serialize: (obj={}) ->
176
+ # serialize everything except file inputs
177
+ obj[input.name] = input.value for input in @$el.serializeArray()
178
+
179
+ for form in @_forms()
180
+ # serialize file inputs for all forms (including nested)
181
+ for name, input of form.inputs
182
+ if input.config.type == 'file' or input.config.type == 'image'
183
+ file = input.$input.get()[0].files[0]
184
+ obj["__FILE__#{ input.name }"] = file
185
+ if input.isEmpty() then obj[input.removeName()] = 'true'
186
+
187
+ # remove fields with ignoreOnSubmission
188
+ for name, input of form.inputs
189
+ if input.config.ignoreOnSubmission
190
+ delete obj[name]
191
+
192
+ return obj
193
+
194
+
195
+ hash: (hash={}) ->
196
+ for name, input of @inputs
197
+ input.hash(hash)
198
+ return hash
199
+
200
+
201
+ initializePlugins: ->
202
+ for group in @groups
203
+ group.onInitialize?(@, group)
204
+
205
+ for name, input of @inputs
206
+ input.initialize()
207
+
208
+
209
+ showValidationErrors: (errors) ->
210
+ @hideValidationErrors()
211
+ for inputName, messages of errors
212
+ input = @inputs[inputName]
213
+ firstMessage = messages[0]
214
+ input.showErrorMessage(firstMessage)
215
+
216
+
217
+ hideValidationErrors: ->
218
+ for inputName, input of @inputs
219
+ input.hideErrorMessage()
220
+
221
+
222
+ updateValues: (object) ->
223
+ for name, value of object
224
+ if @inputs[name]
225
+ @inputs[name].updateValue(value, object)
226
+
227
+
228
+
229
+
@@ -0,0 +1,28 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # EXPANDABLE GROUP
11
+ # -----------------------------------------------------------------------------
12
+ #
13
+ # Usage: onInitialize: (form, group) -> new ExpandableGroup(form, group, 'Details')
14
+ #
15
+ # -----------------------------------------------------------------------------
16
+
17
+ class @ExpandableGroup
18
+ constructor: (@form, @group, name) ->
19
+ @$expander =$ """<a href='#' class='group-edit hidden'>#{ name }</a>"""
20
+ @group.$el.before @$expander
21
+
22
+ @$expander.on 'click', (e) =>
23
+ @$expander.toggleClass('hidden')
24
+ e.preventDefault()
25
+
26
+
27
+
28
+
@@ -0,0 +1,83 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # INPUT CHECKBOX
11
+ # -----------------------------------------------------------------------------
12
+ class @InputCheckbox extends InputString
13
+ constructor: (@name, @value, @config, @object) ->
14
+ @_create_el()
15
+ @_add_input()
16
+ @_add_label()
17
+
18
+ return this
19
+
20
+
21
+ # PRIVATE ===============================================
22
+
23
+ _create_el: ->
24
+ @$el =$ "<label for='#{ @name }' class='input-#{ @config.type } input-#{ @config.klass } input-#{ @config.klassName }'>"
25
+
26
+
27
+ _safe_value: ->
28
+ if not @value or @value == 'false' or @value == 0 or @value == '0'
29
+ return false
30
+ else
31
+ return true
32
+
33
+
34
+ _add_input: ->
35
+ # for boolean checkbox to be serialized correctly we need a hidden false
36
+ # value which is used by default and overriden by checked value
37
+ @$false_hidden_input =$ "<input type='hidden' name='#{ @name }' value='false' />"
38
+ @$el.append @$false_hidden_input
39
+
40
+ @$input =$ "<input type='checkbox' id='#{ @name }' name='#{ @name }' value='true' #{ if @_safe_value() then 'checked' else '' } />"
41
+ @$el.append @$input
42
+
43
+
44
+ # PUBLIC ================================================
45
+
46
+ updateValue: (@value) ->
47
+ @$input.prop('checked', @_safe_value())
48
+
49
+
50
+ hash: (hash={}) ->
51
+ hash[@config.klassName] = @$input.prop('checked')
52
+ return hash
53
+
54
+
55
+ chr.formInputs['checkbox'] = InputCheckbox
56
+
57
+
58
+ # -----------------------------------------------------------------------------
59
+ # INPUT CHECKBOX SWITCH
60
+ # -----------------------------------------------------------------------------
61
+ class @InputCheckboxSwitch extends InputCheckbox
62
+
63
+ # PRIVATE ===============================================
64
+
65
+ _add_input: ->
66
+ @$switch =$ "<div class='switch'>"
67
+ @$el.append @$switch
68
+
69
+ @$false_hidden_input =$ "<input type='hidden' name='#{ @name }' value='false' />"
70
+ @$switch.append @$false_hidden_input
71
+
72
+ @$input =$ "<input type='checkbox' id='#{ @name }' name='#{ @name }' value='true' #{ if @_safe_value() then 'checked' else '' } />"
73
+ @$switch.append @$input
74
+
75
+ @$checkbox =$ "<div class='checkbox'>"
76
+ @$switch.append @$checkbox
77
+
78
+
79
+ chr.formInputs['switch'] = InputCheckboxSwitch
80
+
81
+
82
+
83
+
@@ -0,0 +1,55 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # INPUT COLOR
11
+ # -----------------------------------------------------------------------------
12
+ class @InputColor extends InputString
13
+
14
+ # PRIVATE ===============================================
15
+
16
+ _add_color_preview: ->
17
+ @$colorPreview =$ "<div class='preview'>"
18
+ @$el.append @$colorPreview
19
+
20
+
21
+ _update_color_preview: ->
22
+ @$colorPreview.css { 'background-color': "##{ @$input.val() }" }
23
+
24
+
25
+ _validate_input_value: ->
26
+ if (/^(?:[0-9a-f]{3}){1,2}$/i).test(@$input.val())
27
+ @hideErrorMessage()
28
+ else
29
+ @showErrorMessage('Invalid hex value')
30
+
31
+
32
+ # PUBLIC ================================================
33
+
34
+ initialize: ->
35
+ @config.beforeInitialize?(this)
36
+
37
+ @$input.attr('placeholder', @config.placeholder || 'e.g. #eee')
38
+
39
+ @_add_color_preview()
40
+ @_update_color_preview()
41
+
42
+ @$input.on 'change keyup', (e) =>
43
+ @hideErrorMessage()
44
+ @_validate_input_value()
45
+ @_update_color_preview()
46
+
47
+ @config.onInitialize?(this)
48
+
49
+
50
+ chr.formInputs['color'] = InputColor
51
+
52
+
53
+
54
+
55
+
@@ -0,0 +1,69 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Author: Alexander Kravets <alex@slatestudio.com>,
3
+ # Slate Studio (http://www.slatestudio.com)
4
+ #
5
+ # Coding Guide:
6
+ # https://github.com/thoughtbot/guides/tree/master/style/coffeescript
7
+ # -----------------------------------------------------------------------------
8
+
9
+ # -----------------------------------------------------------------------------
10
+ # INPUT DATE
11
+ # -----------------------------------------------------------------------------
12
+ #
13
+ # Dependencies:
14
+ #= require vendor/datedropper
15
+ #= require vendor/moment
16
+ #
17
+ # -----------------------------------------------------------------------------
18
+ class @InputDate extends InputString
19
+
20
+ # PRIVATE ===============================================
21
+
22
+ _update_date_label: ->
23
+ date = @$input.val()
24
+ date_formatted = moment(date).format("dddd, MMMM Do, YYYY")
25
+ @$dateLabel.html(date_formatted)
26
+
27
+
28
+ _add_input: ->
29
+ @$input =$ "<input type='text' name='#{ @name }' value='#{ @_safe_value() }' class='input-datetime-date' />"
30
+ @$el.append @$input
31
+ @$input.on 'change', (e) => @_update_date_label()
32
+
33
+ @$dateLabel =$ "<div class='input-date-label'>"
34
+ @$el.append @$dateLabel
35
+ @$dateLabel.on 'click', (e) => @$input.trigger 'click'
36
+
37
+ @_update_date_label()
38
+
39
+
40
+ # PUBLIC ================================================
41
+
42
+ initialize: ->
43
+ @config.beforeInitialize?(this)
44
+
45
+ # http://felicegattuso.com/projects/datedropper/
46
+ @config.pluginConfig ?= {}
47
+
48
+ config =
49
+ animation: 'fadein'
50
+ format: 'Y-m-d'
51
+
52
+ $.extend(config, @config.pluginConfig)
53
+
54
+ @$input.dateDropper(config)
55
+
56
+ @config.onInitialize?(this)
57
+
58
+
59
+ updateValue: (@value) ->
60
+ @$input.val(@value)
61
+ # @TODO: check if required, cause change event might be triggered
62
+ #@_update_date_label()
63
+
64
+
65
+ chr.formInputs['date'] = InputDate
66
+
67
+
68
+
69
+