formagic 0.1.0 → 0.2.5
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/formagic/form.coffee +31 -11
- data/app/assets/javascripts/formagic/inputs/checkbox.coffee +1 -0
- data/app/assets/javascripts/formagic/inputs/date.coffee +28 -3
- data/app/assets/javascripts/formagic/inputs/datetime.coffee +30 -2
- data/app/assets/javascripts/formagic/inputs/document.coffee +110 -0
- data/app/assets/javascripts/formagic/inputs/documents.coffee +39 -13
- data/app/assets/javascripts/formagic/inputs/documents_reorder.coffee +1 -1
- data/app/assets/javascripts/formagic/inputs/file.coffee +3 -0
- data/app/assets/javascripts/formagic/inputs/html.coffee +1 -0
- data/app/assets/javascripts/formagic/inputs/redactor.coffee +1 -0
- data/app/assets/javascripts/formagic/inputs/redactor_character.coffee +16 -14
- data/app/assets/javascripts/formagic/inputs/select2.coffee +1 -1
- data/app/assets/javascripts/formagic/inputs/string.coffee +5 -4
- data/app/assets/javascripts/formagic/inputs/text.coffee +4 -3
- data/app/assets/javascripts/formagic/inputs/url.coffee +37 -0
- data/app/assets/javascripts/formagic.coffee +2 -1
- data/app/assets/javascripts/vendor/ace.js +811 -577
- data/app/assets/javascripts/vendor/mode-html.js +24 -25
- data/app/assets/javascripts/vendor/mode-markdown.js +25 -26
- data/app/assets/javascripts/vendor/redactor.table.js +338 -0
- data/app/assets/stylesheets/formagic/date.scss +1 -0
- data/app/assets/stylesheets/formagic/file.scss +7 -0
- data/app/assets/stylesheets/formagic/form.scss +15 -10
- data/app/assets/stylesheets/formagic/image.scss +4 -0
- data/app/assets/stylesheets/formagic/label.scss +27 -0
- data/app/assets/stylesheets/formagic/nested-form.scss +3 -3
- data/app/assets/stylesheets/formagic/select2.scss +19 -1
- data/app/assets/stylesheets/formagic.scss +2 -1
- data/lib/formagic/version.rb +1 -1
- metadata +6 -3
- /data/app/assets/stylesheets/formagic/{redactor.scss → redactor1.scss} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b03dc0a52060aac37925bb13cfb132af6073841
|
4
|
+
data.tar.gz: d7ca3659fc899e73a9eb3eb9c953d8195563c198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d262ebec3c701d80415a780eeda8b336584b5827d985977526fa021fd9e2e1308f9a86f7f412be5db4cf0ebc4ff831a5001134a23b8d8ca41afc7ca9891e5d33
|
7
|
+
data.tar.gz: b45ea0148e06c4fbb9d156898a0ed6a09758bda71185b061ed42949a4ba9bb93809f275457ecc74c3aa3a45038270069d11f85fc949b1d73eb9908e157374598
|
@@ -122,7 +122,7 @@ class @Form
|
|
122
122
|
inputName = if @config.namePrefix then "#{ @config.namePrefix }[#{ name }]" else "[#{ name }]"
|
123
123
|
|
124
124
|
# add prefix for nested form inputs
|
125
|
-
if inputConfig.type == 'form' || inputConfig.type == 'documents'
|
125
|
+
if inputConfig.type == 'form' || inputConfig.type == 'documents' || inputConfig.type == 'document'
|
126
126
|
inputConfig.namePrefix = inputName.replace("[#{ name }]", "[#{ name }_attributes]")
|
127
127
|
|
128
128
|
else
|
@@ -135,14 +135,20 @@ class @Form
|
|
135
135
|
|
136
136
|
_add_nested_form_remove_button: ->
|
137
137
|
if @config.removeButton
|
138
|
+
|
138
139
|
# add hidden input to the form
|
139
|
-
fieldName
|
140
|
-
input
|
140
|
+
fieldName = '_destroy'
|
141
|
+
input = @_render_input(fieldName, {
|
142
|
+
type: 'hidden',
|
143
|
+
ignoreOnSubmission: @config.ignoreOnSubmission
|
144
|
+
}, false)
|
145
|
+
|
141
146
|
@inputs[fieldName] = input
|
142
|
-
@$el.
|
147
|
+
@$el.prepend input.$el
|
148
|
+
|
143
149
|
# remove button
|
144
150
|
@$removeButton =$ """<a href='#' class='nested-form-delete'>Delete</a>"""
|
145
|
-
@$el.
|
151
|
+
@$el.prepend @$removeButton
|
146
152
|
@$removeButton.on 'click', (e) =>
|
147
153
|
e.preventDefault()
|
148
154
|
if confirm('Are you sure?')
|
@@ -181,13 +187,19 @@ class @Form
|
|
181
187
|
for name, input of form.inputs
|
182
188
|
if input.config.type == 'file' or input.config.type == 'image'
|
183
189
|
file = input.$input.get()[0].files[0]
|
184
|
-
|
190
|
+
|
191
|
+
if file
|
192
|
+
obj["__FILE__#{ input.name }"] = file
|
193
|
+
|
185
194
|
if input.isEmpty() then obj[input.removeName()] = 'true'
|
186
195
|
|
187
196
|
# remove fields with ignoreOnSubmission
|
188
|
-
for
|
197
|
+
for key, input of form.inputs
|
189
198
|
if input.config.ignoreOnSubmission
|
190
|
-
delete obj[name]
|
199
|
+
delete obj[input.name]
|
200
|
+
|
201
|
+
# for k, v of obj
|
202
|
+
# console.log k
|
191
203
|
|
192
204
|
return obj
|
193
205
|
|
@@ -209,9 +221,17 @@ class @Form
|
|
209
221
|
showValidationErrors: (errors) ->
|
210
222
|
@hideValidationErrors()
|
211
223
|
for inputName, messages of errors
|
212
|
-
input
|
213
|
-
|
214
|
-
|
224
|
+
input = @inputs[inputName]
|
225
|
+
|
226
|
+
# Support nested documents validation errors
|
227
|
+
if ! input
|
228
|
+
for k, v of @inputs
|
229
|
+
if v.name == "[#{ inputName }]"
|
230
|
+
input = v
|
231
|
+
|
232
|
+
if input
|
233
|
+
firstMessage = messages[0]
|
234
|
+
input.showErrorMessage(firstMessage)
|
215
235
|
|
216
236
|
|
217
237
|
hideValidationErrors: ->
|
@@ -21,10 +21,17 @@ class @InputDate extends InputString
|
|
21
21
|
|
22
22
|
_update_date_label: ->
|
23
23
|
date = @$input.val()
|
24
|
-
|
24
|
+
|
25
|
+
if date
|
26
|
+
date_formatted = moment(date).format("dddd, MMMM Do, YYYY")
|
27
|
+
|
28
|
+
else
|
29
|
+
date_formatted = "<span class='placeholder'>Pick a date</span>"
|
30
|
+
|
25
31
|
@$dateLabel.html(date_formatted)
|
26
32
|
|
27
33
|
|
34
|
+
|
28
35
|
_add_input: ->
|
29
36
|
@$input =$ "<input type='text' name='#{ @name }' value='#{ @_safe_value() }' class='input-datetime-date' />"
|
30
37
|
@$el.append @$input
|
@@ -36,6 +43,25 @@ class @InputDate extends InputString
|
|
36
43
|
|
37
44
|
@_update_date_label()
|
38
45
|
|
46
|
+
@_add_actions()
|
47
|
+
|
48
|
+
|
49
|
+
_add_actions: ->
|
50
|
+
@$actions =$ "<span class='input-actions'></span>"
|
51
|
+
@$label.append @$actions
|
52
|
+
|
53
|
+
@_add_remove_button()
|
54
|
+
|
55
|
+
|
56
|
+
_add_remove_button: ->
|
57
|
+
@$removeBtn =$ "<a href='#' class='remove'>Remove</a>"
|
58
|
+
@$actions.append @$removeBtn
|
59
|
+
|
60
|
+
@$removeBtn.on 'click', (e) =>
|
61
|
+
e.preventDefault()
|
62
|
+
@updateValue('')
|
63
|
+
@_update_date_label()
|
64
|
+
|
39
65
|
|
40
66
|
# PUBLIC ================================================
|
41
67
|
|
@@ -58,8 +84,7 @@ class @InputDate extends InputString
|
|
58
84
|
|
59
85
|
updateValue: (@value) ->
|
60
86
|
@$input.val(@value)
|
61
|
-
|
62
|
-
#@_update_date_label()
|
87
|
+
@_update_date_label()
|
63
88
|
|
64
89
|
|
65
90
|
chr.formInputs['date'] = InputDate
|
@@ -21,6 +21,11 @@ class @InputDatetime extends InputDate
|
|
21
21
|
|
22
22
|
_update_value: ->
|
23
23
|
mt = moment(@$inputTime.val(), 'LT')
|
24
|
+
|
25
|
+
if @$inputDate.val() == '' && ! mt.isValid()
|
26
|
+
@$input.val('')
|
27
|
+
return
|
28
|
+
|
24
29
|
if ! mt.isValid()
|
25
30
|
mt = moment('1:00 pm', 'LT')
|
26
31
|
|
@@ -44,7 +49,8 @@ class @InputDatetime extends InputDate
|
|
44
49
|
|
45
50
|
_update_date_label: ->
|
46
51
|
m = moment(@$inputDate.val()).utcOffset(@tzOffset)
|
47
|
-
|
52
|
+
label = if m.isValid() then m.format('dddd, MMM D, YYYY') else "<span class='placeholder'>Pick a date</span>"
|
53
|
+
@$dateLabel.html label
|
48
54
|
|
49
55
|
|
50
56
|
_normalized_value: ->
|
@@ -52,7 +58,8 @@ class @InputDatetime extends InputDate
|
|
52
58
|
@tzOffset = @config.timezoneOffset
|
53
59
|
@tzOffset ?= (new Date()).getTimezoneOffset() * -1
|
54
60
|
|
55
|
-
|
61
|
+
m = moment(@value).utcOffset(@tzOffset)
|
62
|
+
@value = if m.isValid() then m.format() else ''
|
56
63
|
|
57
64
|
|
58
65
|
_add_input: ->
|
@@ -88,6 +95,27 @@ class @InputDatetime extends InputDate
|
|
88
95
|
|
89
96
|
@_update_time_input()
|
90
97
|
|
98
|
+
@_add_actions()
|
99
|
+
|
100
|
+
|
101
|
+
_add_actions: ->
|
102
|
+
@$actions =$ "<span class='input-actions'></span>"
|
103
|
+
@$label.append @$actions
|
104
|
+
|
105
|
+
@_add_remove_button()
|
106
|
+
|
107
|
+
|
108
|
+
_add_remove_button: ->
|
109
|
+
@$removeBtn =$ "<a href='#' class='remove'>Remove</a>"
|
110
|
+
@$actions.append @$removeBtn
|
111
|
+
|
112
|
+
@$removeBtn.on 'click', (e) =>
|
113
|
+
e.preventDefault()
|
114
|
+
@$inputTime.val('')
|
115
|
+
@$inputDate.val('')
|
116
|
+
@_update_date_label()
|
117
|
+
@_update_value()
|
118
|
+
|
91
119
|
|
92
120
|
# PUBLIC ================================================
|
93
121
|
|
@@ -0,0 +1,110 @@
|
|
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 DOCUMENT
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# 1-to-1 relation implementation. This is based on InputDocuments
|
13
|
+
# implementation and might require refactor.
|
14
|
+
#
|
15
|
+
# Public methods:
|
16
|
+
# initialize()
|
17
|
+
# hash(hash)
|
18
|
+
# updateValue(@value)
|
19
|
+
# showErrorMessage(message)
|
20
|
+
# hideErrorMessage()
|
21
|
+
#
|
22
|
+
# -----------------------------------------------------------------------------
|
23
|
+
|
24
|
+
class @InputDocument
|
25
|
+
constructor: (@name, @nestedObject, @config, @object) ->
|
26
|
+
@forms = []
|
27
|
+
|
28
|
+
@config.namePrefix ||= name
|
29
|
+
@config.removeButton = true
|
30
|
+
@config.ignoreOnSubmission ||= false
|
31
|
+
|
32
|
+
if @config.ignoreOnSubmission
|
33
|
+
for key, inputConfig of @config.formSchema
|
34
|
+
inputConfig.ignoreOnSubmission = true
|
35
|
+
|
36
|
+
@_create_el()
|
37
|
+
|
38
|
+
@_add_label()
|
39
|
+
@_add_forms()
|
40
|
+
|
41
|
+
return this
|
42
|
+
|
43
|
+
|
44
|
+
# PRIVATE ===============================================
|
45
|
+
|
46
|
+
_create_el: ->
|
47
|
+
@$el =$ "<div class='input-stacked nested-forms input-#{ @config.klassName }'>"
|
48
|
+
|
49
|
+
|
50
|
+
_add_label: ->
|
51
|
+
@$label =$ "<span class='label'>#{ @config.label }</span>"
|
52
|
+
@$errorMessage =$ "<span class='error-message'></span>"
|
53
|
+
@$label.append(@$errorMessage)
|
54
|
+
@$el.append(@$label)
|
55
|
+
|
56
|
+
|
57
|
+
_add_forms: ->
|
58
|
+
@nestedForm = @_render_form(@nestedObject, @config.namePrefix, @config)
|
59
|
+
|
60
|
+
@$form = @nestedForm.$el
|
61
|
+
@$label.after @$form
|
62
|
+
|
63
|
+
|
64
|
+
_render_form: (object, namePrefix, config) ->
|
65
|
+
formConfig = $.extend {}, config,
|
66
|
+
namePrefix: namePrefix
|
67
|
+
rootEl: "<div>"
|
68
|
+
removeButton: false
|
69
|
+
|
70
|
+
form = new Form(object, formConfig)
|
71
|
+
return form
|
72
|
+
|
73
|
+
|
74
|
+
# PUBLIC ================================================
|
75
|
+
|
76
|
+
initialize: ->
|
77
|
+
@config.beforeInitialize?(this)
|
78
|
+
|
79
|
+
@nestedForm.initializePlugins()
|
80
|
+
|
81
|
+
@config.onInitialize?(this)
|
82
|
+
|
83
|
+
|
84
|
+
hash: (hash={}) ->
|
85
|
+
objects = []
|
86
|
+
hash[@config.fieldName] = @nestedForm.hash()
|
87
|
+
return hash
|
88
|
+
|
89
|
+
|
90
|
+
showErrorMessage: (message) ->
|
91
|
+
@$el.addClass 'error'
|
92
|
+
@$errorMessage.html(message)
|
93
|
+
|
94
|
+
|
95
|
+
hideErrorMessage: ->
|
96
|
+
@$el.removeClass 'error'
|
97
|
+
@$errorMessage.html('')
|
98
|
+
|
99
|
+
|
100
|
+
updateValue: (@nestedObject, @object) ->
|
101
|
+
for name, value of @nestedObject
|
102
|
+
if @nestedForm.inputs[name]
|
103
|
+
@nestedForm.inputs[name].updateValue(value, @object)
|
104
|
+
|
105
|
+
|
106
|
+
chr.formInputs['document'] = InputDocument
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
@@ -28,11 +28,16 @@ class @InputForm
|
|
28
28
|
constructor: (@name, @nestedObjects, @config, @object) ->
|
29
29
|
@forms = []
|
30
30
|
|
31
|
-
@config.namePrefix
|
32
|
-
@config.removeButton
|
33
|
-
@config.
|
31
|
+
@config.namePrefix ||= name
|
32
|
+
@config.removeButton = if @config.disableRemoveDocuments then false else true
|
33
|
+
@config.ignoreOnSubmission ||= false
|
34
|
+
|
34
35
|
@reorderContainerClass = "nested-forms-#{@config.klassName}"
|
35
36
|
|
37
|
+
if @config.ignoreOnSubmission
|
38
|
+
for key, inputConfig of @config.formSchema
|
39
|
+
inputConfig.ignoreOnSubmission = true
|
40
|
+
|
36
41
|
@_create_el()
|
37
42
|
|
38
43
|
@_add_label()
|
@@ -55,7 +60,21 @@ class @InputForm
|
|
55
60
|
@$el.append(@$label)
|
56
61
|
|
57
62
|
|
63
|
+
_extend_schema_with: (name, config) ->
|
64
|
+
schemaConfig = {}
|
65
|
+
schemaConfig[name] = config
|
66
|
+
@config.formSchema = $.extend(schemaConfig, @config.formSchema)
|
67
|
+
|
68
|
+
|
58
69
|
_add_forms: ->
|
70
|
+
# add id to schema
|
71
|
+
# @NOTE: here we use _id, cause mongosteen returns objects _id, but we should send id for nested documents
|
72
|
+
@_extend_schema_with('_id', { type: 'hidden', name: 'id', ignoreOnSubmission: @config.ignoreOnSubmission })
|
73
|
+
|
74
|
+
# add position to schema
|
75
|
+
if @config.sortBy
|
76
|
+
@_extend_schema_with(@config.sortBy, { type: 'hidden', ignoreOnSubmission: @config.ignoreOnSubmission })
|
77
|
+
|
59
78
|
@$forms =$ "<ul>"
|
60
79
|
@$label.after @$forms
|
61
80
|
|
@@ -72,7 +91,6 @@ class @InputForm
|
|
72
91
|
|
73
92
|
_sort_nested_objects: ->
|
74
93
|
if @config.sortBy
|
75
|
-
@config.formSchema[@config.sortBy] = { type: 'hidden' }
|
76
94
|
if @nestedObjects
|
77
95
|
# this is not required but make things a bit easier on the backend
|
78
96
|
# as object don't have to be in a specific order.
|
@@ -93,10 +111,13 @@ class @InputForm
|
|
93
111
|
|
94
112
|
|
95
113
|
_add_new_button: ->
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
114
|
+
if ! @config.disableNewDocuments
|
115
|
+
label = @config.newButtonLabel || "Add"
|
116
|
+
|
117
|
+
@$newButton =$ """<a href='#' class='nested-form-new'>#{ label }</a>"""
|
118
|
+
@$el.append @$newButton
|
119
|
+
|
120
|
+
@$newButton.on 'click', (e) => e.preventDefault() ; @addNewForm()
|
100
121
|
|
101
122
|
|
102
123
|
# PUBLIC ================================================
|
@@ -141,11 +162,8 @@ class @InputForm
|
|
141
162
|
prevForm = _last(@forms)
|
142
163
|
position = if prevForm then prevForm.inputs[@config.sortBy].value + 1 else 1
|
143
164
|
|
144
|
-
#
|
145
|
-
#
|
146
|
-
console.log @config
|
147
|
-
console.log @config.sortBy
|
148
|
-
console.log form.inputs
|
165
|
+
# Had a problem here for new documents, but now seems to be resolved by adding
|
166
|
+
# _position to schema in constructor (to be removed when stable).
|
149
167
|
|
150
168
|
form.inputs[@config.sortBy].updateValue(position)
|
151
169
|
|
@@ -157,10 +175,18 @@ class @InputForm
|
|
157
175
|
|
158
176
|
|
159
177
|
updateValue: (@nestedObjects, @object) ->
|
178
|
+
# New document should update id, also after uploading images form for existing
|
179
|
+
# document might change, so we reset all nested forms to reflect these updates.
|
180
|
+
# This implementation has some problems with jumping screen when using plugins
|
181
|
+
# also it requires complex implementation for data local storage caching.
|
160
182
|
@$forms.remove()
|
161
183
|
@forms = []
|
162
184
|
@_add_forms()
|
163
185
|
|
186
|
+
# Initialize input plugins after update
|
187
|
+
for nestedForm in @forms
|
188
|
+
nestedForm.initializePlugins()
|
189
|
+
|
164
190
|
|
165
191
|
include(InputForm, inputFormReorder)
|
166
192
|
|
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
|
56
56
|
_add_form_reorder_button: (form) ->
|
57
|
-
form.$el.
|
57
|
+
form.$el.prepend("""<div class='icon-reorder' data-container-class='#{@reorderContainerClass}'></div>""").addClass('reorderable')
|
58
58
|
|
59
59
|
|
60
60
|
_find_form_by_target: (el) ->
|
@@ -20,6 +20,7 @@ class @InputFile extends InputString
|
|
20
20
|
@_add_input()
|
21
21
|
@_update_state()
|
22
22
|
@_add_required()
|
23
|
+
@_add_disabled()
|
23
24
|
|
24
25
|
return this
|
25
26
|
|
@@ -82,8 +83,10 @@ class @InputFile extends InputString
|
|
82
83
|
if @filename
|
83
84
|
@$el.removeClass('empty')
|
84
85
|
@_update_inputs()
|
86
|
+
|
85
87
|
else
|
86
88
|
@$el.addClass('empty')
|
89
|
+
@$clearButton.hide()
|
87
90
|
|
88
91
|
|
89
92
|
# PUBLIC ================================================
|
@@ -43,20 +43,22 @@ $.fx.speeds.fast = 10
|
|
43
43
|
|
44
44
|
|
45
45
|
_get_default_config: () ->
|
46
|
-
focus:
|
47
|
-
imageFloatMargin:
|
48
|
-
buttonSource:
|
49
|
-
pastePlainText:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
46
|
+
focus: false
|
47
|
+
imageFloatMargin: '20px'
|
48
|
+
buttonSource: true
|
49
|
+
pastePlainText: true
|
50
|
+
replaceDivs: false
|
51
|
+
scrollTarget: chr.module.view.$content
|
52
|
+
plugins: [ 'table' ]
|
53
|
+
buttons: [ 'html'
|
54
|
+
'formatting'
|
55
|
+
'bold'
|
56
|
+
'italic'
|
57
|
+
'deleted'
|
58
|
+
'unorderedlist'
|
59
|
+
'orderedlist'
|
60
|
+
'table'
|
61
|
+
'link' ]
|
60
62
|
|
61
63
|
# to have caching working we need to trigger 'change' event for textarea
|
62
64
|
# when content got changed in redactor, but skip this when updating value
|
@@ -20,7 +20,7 @@ class @InputSelect2 extends InputSelect
|
|
20
20
|
@config.beforeInitialize?(this)
|
21
21
|
|
22
22
|
# https://select2.github.io/options.html
|
23
|
-
options = @config.pluginOptions || {}
|
23
|
+
options = @config.pluginOptions || { placeholder: @config.placeholder }
|
24
24
|
@$input.select2(options)
|
25
25
|
|
26
26
|
@config.onInitialize?(this)
|
@@ -50,10 +50,11 @@ class @InputString
|
|
50
50
|
|
51
51
|
|
52
52
|
_add_label: ->
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
if @config.label != false
|
54
|
+
@$label =$ "<span class='label'>#{ @config.label }</span>"
|
55
|
+
@$errorMessage =$ "<span class='error-message'></span>"
|
56
|
+
@$label.append(@$errorMessage)
|
57
|
+
@$el.append(@$label)
|
57
58
|
|
58
59
|
|
59
60
|
_add_input: ->
|
@@ -0,0 +1,37 @@
|
|
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 URL
|
11
|
+
# - depends on Loft character plugin for assets management
|
12
|
+
# -----------------------------------------------------------------------------
|
13
|
+
class @InputUrl extends InputString
|
14
|
+
|
15
|
+
_add_choose_button: ->
|
16
|
+
@$actions =$ "<span class='input-actions'></span>"
|
17
|
+
@$label.append @$actions
|
18
|
+
|
19
|
+
@$chooseBtn =$ "<a href='#' class='choose'>Choose or upload a file</a>"
|
20
|
+
@$actions.append @$chooseBtn
|
21
|
+
|
22
|
+
@$chooseBtn.on 'click', (e) =>
|
23
|
+
e.preventDefault()
|
24
|
+
|
25
|
+
chr.modules.loft.showModal 'all', false, (objects) =>
|
26
|
+
url = objects[0].file.url
|
27
|
+
@updateValue(url)
|
28
|
+
|
29
|
+
|
30
|
+
# PUBLIC ================================================
|
31
|
+
|
32
|
+
initialize: ->
|
33
|
+
@_add_choose_button()
|
34
|
+
@config.onInitialize?(this)
|
35
|
+
|
36
|
+
|
37
|
+
chr.formInputs['url'] = InputUrl
|