formagic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -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
+
@@ -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