formagic 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/CONTRIBUTING.md +24 -0
- data/Gemfile +3 -0
- data/LICENSE.md +21 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/assets/images/datedropper/done.png +0 -0
- data/app/assets/images/datedropper/done.svg +1 -0
- data/app/assets/images/datedropper/next.png +0 -0
- data/app/assets/images/datedropper/next.svg +1 -0
- data/app/assets/images/datedropper/prev.png +0 -0
- data/app/assets/images/datedropper/prev.svg +1 -0
- data/app/assets/javascripts/formagic/form.coffee +229 -0
- data/app/assets/javascripts/formagic/group.coffee +28 -0
- data/app/assets/javascripts/formagic/inputs/checkbox.coffee +83 -0
- data/app/assets/javascripts/formagic/inputs/color.coffee +55 -0
- data/app/assets/javascripts/formagic/inputs/date.coffee +69 -0
- data/app/assets/javascripts/formagic/inputs/datetime.coffee +130 -0
- data/app/assets/javascripts/formagic/inputs/document.coffee +0 -0
- data/app/assets/javascripts/formagic/inputs/documents.coffee +173 -0
- data/app/assets/javascripts/formagic/inputs/documents_reorder.coffee +67 -0
- data/app/assets/javascripts/formagic/inputs/file.coffee +114 -0
- data/app/assets/javascripts/formagic/inputs/hidden.coffee +57 -0
- data/app/assets/javascripts/formagic/inputs/html.coffee +81 -0
- data/app/assets/javascripts/formagic/inputs/image.coffee +28 -0
- data/app/assets/javascripts/formagic/inputs/list.coffee +154 -0
- data/app/assets/javascripts/formagic/inputs/list_reorder.coffee +39 -0
- data/app/assets/javascripts/formagic/inputs/list_typeahead.coffee +55 -0
- data/app/assets/javascripts/formagic/inputs/markdown.coffee +93 -0
- data/app/assets/javascripts/formagic/inputs/password.coffee +32 -0
- data/app/assets/javascripts/formagic/inputs/redactor.coffee +53 -0
- data/app/assets/javascripts/formagic/inputs/redactor_character.coffee +75 -0
- data/app/assets/javascripts/formagic/inputs/redactor_images.coffee +166 -0
- data/app/assets/javascripts/formagic/inputs/select.coffee +84 -0
- data/app/assets/javascripts/formagic/inputs/select2.coffee +33 -0
- data/app/assets/javascripts/formagic/inputs/string.coffee +160 -0
- data/app/assets/javascripts/formagic/inputs/text.coffee +43 -0
- data/app/assets/javascripts/formagic/inputs/time.coffee +0 -0
- data/app/assets/javascripts/formagic.coffee +22 -0
- data/app/assets/javascripts/vendor/ace.js +18280 -0
- data/app/assets/javascripts/vendor/datedropper.js +1005 -0
- data/app/assets/javascripts/vendor/jquery.scrollparent.js +14 -0
- data/app/assets/javascripts/vendor/jquery.textarea_autosize.js +55 -0
- data/app/assets/javascripts/vendor/jquery.typeahead.js +1782 -0
- data/app/assets/javascripts/vendor/marked.js +1272 -0
- data/app/assets/javascripts/vendor/mode-html.js +2436 -0
- data/app/assets/javascripts/vendor/mode-markdown.js +2820 -0
- data/app/assets/javascripts/vendor/moment.js +3083 -0
- data/app/assets/javascripts/vendor/redactor.fixedtoolbar.js +107 -0
- data/app/assets/javascripts/vendor/select2.js +5274 -0
- data/app/assets/stylesheets/formagic/checkbox.scss +8 -0
- data/app/assets/stylesheets/formagic/color.scss +12 -0
- data/app/assets/stylesheets/formagic/date.scss +37 -0
- data/app/assets/stylesheets/formagic/file.scss +29 -0
- data/app/assets/stylesheets/formagic/form.scss +36 -0
- data/app/assets/stylesheets/formagic/group.scss +22 -0
- data/app/assets/stylesheets/formagic/image.scss +19 -0
- data/app/assets/stylesheets/formagic/list.scss +39 -0
- data/app/assets/stylesheets/formagic/nested-form.scss +23 -0
- data/app/assets/stylesheets/formagic/redactor.scss +41 -0
- data/app/assets/stylesheets/formagic/select.scss +5 -0
- data/app/assets/stylesheets/formagic/select2.scss +95 -0
- data/app/assets/stylesheets/formagic/string.scss +14 -0
- data/app/assets/stylesheets/formagic/switch.scss +86 -0
- data/app/assets/stylesheets/formagic/text.scss +9 -0
- data/app/assets/stylesheets/formagic.scss +15 -0
- data/app/assets/stylesheets/vendor/datedropper.scss +523 -0
- data/app/assets/stylesheets/vendor/select2.scss +258 -0
- data/formagic.gemspec +30 -0
- data/lib/formagic/engine.rb +5 -0
- data/lib/formagic/version.rb +3 -0
- data/lib/formagic.rb +5 -0
- metadata +146 -0
@@ -0,0 +1,84 @@
|
|
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 SELECT
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
|
13
|
+
class @InputSelect extends InputString
|
14
|
+
|
15
|
+
# PRIVATE ===============================================
|
16
|
+
|
17
|
+
_create_el: ->
|
18
|
+
@$el =$ "<div class='input-#{ @config.type } input-#{ @config.klass } input-#{ @config.klassName }'>"
|
19
|
+
|
20
|
+
|
21
|
+
_add_input: ->
|
22
|
+
@$input =$ """<select name='#{ @name }'></select>"""
|
23
|
+
@$el.append @$input
|
24
|
+
|
25
|
+
@_add_options()
|
26
|
+
|
27
|
+
|
28
|
+
_add_options: ->
|
29
|
+
if @config.optionsHashFieldName
|
30
|
+
@value = String(@value)
|
31
|
+
if @object
|
32
|
+
@config.optionsHash = @object[@config.optionsHashFieldName]
|
33
|
+
else
|
34
|
+
@config.optionsHash = { '': '--' }
|
35
|
+
|
36
|
+
if @config.collection
|
37
|
+
@_add_collection_options()
|
38
|
+
|
39
|
+
else if @config.optionsList
|
40
|
+
@_add_list_options()
|
41
|
+
|
42
|
+
else if @config.optionsHash
|
43
|
+
@_add_hash_options()
|
44
|
+
|
45
|
+
|
46
|
+
_add_collection_options: ->
|
47
|
+
for o in @config.collection.data
|
48
|
+
title = o[@config.collection.titleField]
|
49
|
+
value = o[@config.collection.valueField]
|
50
|
+
@_add_option(title, value)
|
51
|
+
|
52
|
+
|
53
|
+
_add_list_options: ->
|
54
|
+
data = @config.optionsList
|
55
|
+
for o in data
|
56
|
+
@_add_option(o, o)
|
57
|
+
|
58
|
+
|
59
|
+
_add_hash_options: ->
|
60
|
+
data = @config.optionsHash
|
61
|
+
for value, title of data
|
62
|
+
@_add_option(title, value)
|
63
|
+
|
64
|
+
|
65
|
+
_add_option: (title, value) ->
|
66
|
+
selected = if @value == value then 'selected' else ''
|
67
|
+
$option =$ """<option value='#{ value }' #{ selected }>#{ title }</option>"""
|
68
|
+
@$input.append $option
|
69
|
+
|
70
|
+
|
71
|
+
# PUBLIC ================================================
|
72
|
+
|
73
|
+
updateValue: (@value, @object) ->
|
74
|
+
@$input.html('')
|
75
|
+
@_add_options()
|
76
|
+
|
77
|
+
@$input.val(@value).prop('selected', true)
|
78
|
+
|
79
|
+
|
80
|
+
chr.formInputs['select'] = InputSelect
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
@@ -0,0 +1,33 @@
|
|
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 SELECT 2
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
#
|
13
|
+
# Dependencies:
|
14
|
+
#= require vendor/select2
|
15
|
+
#
|
16
|
+
# -----------------------------------------------------------------------------
|
17
|
+
|
18
|
+
class @InputSelect2 extends InputSelect
|
19
|
+
initialize: ->
|
20
|
+
@config.beforeInitialize?(this)
|
21
|
+
|
22
|
+
# https://select2.github.io/options.html
|
23
|
+
options = @config.pluginOptions || {}
|
24
|
+
@$input.select2(options)
|
25
|
+
|
26
|
+
@config.onInitialize?(this)
|
27
|
+
|
28
|
+
|
29
|
+
chr.formInputs['select2'] = InputSelect2
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,160 @@
|
|
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 STRING
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# Basic string input implementation, this is base class for many chr inputs.
|
13
|
+
# This input also serves as a demo for implementing other input types.
|
14
|
+
#
|
15
|
+
# Public methods:
|
16
|
+
# initialize() - run input plugin initializations if any
|
17
|
+
# hash(hash) - update hash with inputs: hash[name] = value
|
18
|
+
# updateValue(@value) - update inputs value
|
19
|
+
# showErrorMessage(message) - show error (validation) message for input
|
20
|
+
# hideErrorMessage() - hide error message
|
21
|
+
#
|
22
|
+
# Dependencies:
|
23
|
+
#= require vendor/jquery.typeahead
|
24
|
+
#
|
25
|
+
# -----------------------------------------------------------------------------
|
26
|
+
class @InputString
|
27
|
+
constructor: (@name, @value, @config, @object) ->
|
28
|
+
@_create_el()
|
29
|
+
@_add_label()
|
30
|
+
@_add_input()
|
31
|
+
@_add_placeholder()
|
32
|
+
@_add_disabled()
|
33
|
+
@_add_required()
|
34
|
+
@_add_limit()
|
35
|
+
|
36
|
+
return this
|
37
|
+
|
38
|
+
|
39
|
+
# PRIVATE ===============================================
|
40
|
+
|
41
|
+
_safe_value: ->
|
42
|
+
if typeof(@value) == 'object'
|
43
|
+
return JSON.stringify(@value)
|
44
|
+
else
|
45
|
+
return _escapeHtml(@value)
|
46
|
+
|
47
|
+
|
48
|
+
_create_el: ->
|
49
|
+
@$el =$ "<label for='#{ @name }' class='input-#{ @config.type } input-#{ @config.klass } input-#{ @config.klassName }'>"
|
50
|
+
|
51
|
+
|
52
|
+
_add_label: ->
|
53
|
+
@$label =$ "<span class='label'>#{ @config.label }</span>"
|
54
|
+
@$errorMessage =$ "<span class='error-message'></span>"
|
55
|
+
@$label.append(@$errorMessage)
|
56
|
+
@$el.append(@$label)
|
57
|
+
|
58
|
+
|
59
|
+
_add_input: ->
|
60
|
+
@$input =$ "<input type='text' name='#{ @name }' value='#{ @_safe_value() }' />"
|
61
|
+
# trigger change event on keyup so value is cached while typing
|
62
|
+
@$input.on 'keyup', (e) => @$input.trigger('change')
|
63
|
+
@$el.append @$input
|
64
|
+
|
65
|
+
|
66
|
+
if @config.options and $.isArray(@config.options)
|
67
|
+
data = new Bloodhound
|
68
|
+
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value')
|
69
|
+
queryTokenizer: Bloodhound.tokenizers.whitespace
|
70
|
+
local: $.map @config.options, (opt) -> { value: opt }
|
71
|
+
|
72
|
+
data.initialize()
|
73
|
+
|
74
|
+
@$input.typeahead({
|
75
|
+
hint: true
|
76
|
+
highlight: true
|
77
|
+
minLength: 1
|
78
|
+
},
|
79
|
+
{
|
80
|
+
name: 'options'
|
81
|
+
displayKey: 'value'
|
82
|
+
source: data.ttAdapter()
|
83
|
+
})
|
84
|
+
|
85
|
+
|
86
|
+
_add_placeholder: ->
|
87
|
+
if @config.klass in [ 'placeholder', 'stacked' ]
|
88
|
+
@$input.attr 'placeholder', @config.label
|
89
|
+
|
90
|
+
if @config.placeholder
|
91
|
+
@$input.attr 'placeholder', @config.placeholder
|
92
|
+
|
93
|
+
|
94
|
+
_add_disabled: ->
|
95
|
+
if @config.disabled
|
96
|
+
@$input.prop('disabled', true)
|
97
|
+
@$el.addClass('input-disabled')
|
98
|
+
|
99
|
+
|
100
|
+
_add_required: ->
|
101
|
+
if @config.required
|
102
|
+
@$el.addClass('input-required')
|
103
|
+
|
104
|
+
|
105
|
+
_add_limit: ->
|
106
|
+
if @config.limit
|
107
|
+
@$charCounter =$ "<span class='input-character-counter'></span>"
|
108
|
+
@$errorMessage.before @$charCounter
|
109
|
+
@$input.on 'keyup', =>
|
110
|
+
@_update_character_counter()
|
111
|
+
@_update_character_counter()
|
112
|
+
|
113
|
+
|
114
|
+
_update_character_counter: ->
|
115
|
+
characters = @$input.val().length
|
116
|
+
left = @config.limit - characters
|
117
|
+
|
118
|
+
if left >= 0
|
119
|
+
@$charCounter.html("(#{ left } left)")
|
120
|
+
|
121
|
+
else
|
122
|
+
@$charCounter.html("(#{ left })")
|
123
|
+
|
124
|
+
|
125
|
+
if characters > @config.limit
|
126
|
+
@$charCounter.addClass('exceeds')
|
127
|
+
else
|
128
|
+
@$charCounter.removeClass('exceeds')
|
129
|
+
|
130
|
+
|
131
|
+
# PUBLIC ================================================
|
132
|
+
|
133
|
+
initialize: ->
|
134
|
+
@config.onInitialize?(this)
|
135
|
+
|
136
|
+
|
137
|
+
hash: (hash={}) ->
|
138
|
+
hash[@config.klassName] = @$input.val()
|
139
|
+
return hash
|
140
|
+
|
141
|
+
|
142
|
+
updateValue: (@value) ->
|
143
|
+
@$input.val(@value)
|
144
|
+
|
145
|
+
|
146
|
+
showErrorMessage: (message) ->
|
147
|
+
@$el.addClass('error')
|
148
|
+
@$errorMessage.html(message)
|
149
|
+
|
150
|
+
|
151
|
+
hideErrorMessage: ->
|
152
|
+
@$el.removeClass('error')
|
153
|
+
@$errorMessage.html('')
|
154
|
+
|
155
|
+
|
156
|
+
chr.formInputs['string'] = InputString
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
@@ -0,0 +1,43 @@
|
|
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 TEXT
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
#
|
13
|
+
# Dependencies:
|
14
|
+
#= require vendor/jquery.scrollparent
|
15
|
+
#= require vendor/jquery.textarea_autosize
|
16
|
+
#
|
17
|
+
# -----------------------------------------------------------------------------
|
18
|
+
class @InputText extends InputString
|
19
|
+
|
20
|
+
# PRIVATE ===============================================
|
21
|
+
|
22
|
+
_add_input: ->
|
23
|
+
@$input =$ "<textarea class='autosize' name='#{ @name }' rows=1>#{ @_safe_value() }</textarea>"
|
24
|
+
# trigger change event on keyup so value is cached while typing
|
25
|
+
@$input.on 'keyup', (e) => @$input.trigger('change')
|
26
|
+
@$el.append @$input
|
27
|
+
|
28
|
+
|
29
|
+
# PUBLIC ================================================
|
30
|
+
|
31
|
+
initialize: ->
|
32
|
+
@config.beforeInitialize?(this)
|
33
|
+
|
34
|
+
@$input.textareaAutoSize()
|
35
|
+
|
36
|
+
@config.onInitialize?(this)
|
37
|
+
|
38
|
+
|
39
|
+
chr.formInputs['text'] = InputText
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#= require ./formagic/form
|
2
|
+
#= require ./formagic/group
|
3
|
+
|
4
|
+
#= require ./formagic/inputs/hidden
|
5
|
+
#= require ./formagic/inputs/string
|
6
|
+
#= require ./formagic/inputs/text
|
7
|
+
#= require ./formagic/inputs/checkbox
|
8
|
+
#= require ./formagic/inputs/color
|
9
|
+
#= require ./formagic/inputs/date
|
10
|
+
#= require ./formagic/inputs/datetime
|
11
|
+
#= require ./formagic/inputs/document
|
12
|
+
#= require ./formagic/inputs/documents
|
13
|
+
#= require ./formagic/inputs/file
|
14
|
+
#= require ./formagic/inputs/html
|
15
|
+
#= require ./formagic/inputs/image
|
16
|
+
#= require ./formagic/inputs/list
|
17
|
+
#= require ./formagic/inputs/markdown
|
18
|
+
#= require ./formagic/inputs/password
|
19
|
+
#= require ./formagic/inputs/redactor
|
20
|
+
#= require ./formagic/inputs/select
|
21
|
+
#= require ./formagic/inputs/select2
|
22
|
+
#= require ./formagic/inputs/time
|