chr 0.3.5 → 0.4.9
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/.coveralls.yml +2 -0
- data/.gitignore +6 -1
- data/.ruby-version +1 -0
- data/.travis.yml +18 -0
- data/README.md +4 -0
- data/Rakefile +17 -2
- data/app/assets/javascripts/chr.coffee +13 -26
- data/app/assets/javascripts/chr/{core/chr.coffee → chr.coffee} +4 -1
- data/app/assets/javascripts/chr/{core/chr_router.coffee → chr_router.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/item.coffee → item.coffee} +2 -1
- data/app/assets/javascripts/chr/{core/list.coffee → list.coffee} +1 -1
- data/app/assets/javascripts/chr/{core/list_config.coffee → list_config.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/list_pagination.coffee → list_pagination.coffee} +15 -4
- data/app/assets/javascripts/chr/{core/list_reorder.coffee → list_reorder.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/list_search.coffee → list_search.coffee} +1 -1
- data/app/assets/javascripts/chr/{core/module.coffee → module.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/utils.coffee → utils.coffee} +0 -0
- data/app/assets/javascripts/chr/{core/view.coffee → view.coffee} +21 -9
- data/app/assets/javascripts/chr/{core/view_local-storage.coffee → view_local-storage.coffee} +0 -0
- data/app/assets/javascripts/{chr/store/array-store.coffee → stores/array.coffee} +0 -0
- data/app/assets/javascripts/{chr/store/object-store.coffee → stores/object.coffee} +0 -0
- data/app/assets/javascripts/{chr/store/rails-array-store.coffee → stores/rails-array.coffee} +0 -0
- data/app/assets/javascripts/{chr/store → stores}/rails-form-object-parser.coffee +4 -1
- data/app/assets/javascripts/{chr/store/rails-object-store.coffee → stores/rails-object.coffee} +0 -0
- data/app/assets/javascripts/{chr/store/rest-array-store.coffee → stores/rest-array.coffee} +5 -2
- data/app/assets/javascripts/{chr/store/rest-object-store.coffee → stores/rest-object.coffee} +0 -0
- data/app/assets/stylesheets/{_chr.scss → chr.scss} +2 -7
- data/app/assets/stylesheets/chr/{_icons.scss → icons.scss} +0 -0
- data/app/assets/stylesheets/chr/{_main.scss → main.scss} +10 -3
- data/app/assets/stylesheets/chr/{_mixins.scss → mixins.scss} +0 -77
- data/app/assets/stylesheets/chr/{_settings.scss → settings.scss} +1 -1
- data/bin/chr +13 -0
- data/bin/rake +16 -0
- data/bin/setup +13 -0
- data/chr.gemspec +41 -21
- data/docs/tests.md +64 -0
- data/lib/chr.rb +10 -2
- data/lib/chr/app_builder.rb +385 -0
- data/lib/chr/generators/app_generator.rb +213 -0
- data/lib/chr/version.rb +3 -1
- data/lib/generators/chr/controller_generator.rb +18 -0
- data/templates/Gemfile.erb +38 -0
- data/templates/Procfile +1 -0
- data/templates/README.md.erb +45 -0
- data/templates/_analytics.html.erb +9 -0
- data/templates/_flashes.html.erb +7 -0
- data/templates/_javascript.html.erb +12 -0
- data/templates/application.coffee +2 -0
- data/templates/application.scss +1 -0
- data/templates/application.yml +6 -0
- data/templates/application_gitignore +14 -0
- data/templates/application_layout.html.erb.erb +29 -0
- data/templates/asset_sync.rb +28 -0
- data/templates/bin_setup.erb +36 -0
- data/templates/body_class_helper.rb +19 -0
- data/templates/bundler_audit.rake +12 -0
- data/templates/carrierwave.rb +23 -0
- data/templates/character_admin.coffee.erb +28 -0
- data/templates/character_admin.scss +3 -0
- data/templates/character_admin_index.html.erb +2 -0
- data/templates/character_admin_layout.html.erb +21 -0
- data/templates/character_base_controller.rb +16 -0
- data/templates/development_seeds.rb +12 -0
- data/templates/devise_overrides_passwords_controller.rb +10 -0
- data/templates/devise_overrides_passwords_edit.html.erb +30 -0
- data/templates/devise_overrides_passwords_new.html.erb +21 -0
- data/templates/devise_overrides_sessions_controller.rb +12 -0
- data/templates/devise_overrides_sessions_new.html.erb +31 -0
- data/templates/errors.rb +34 -0
- data/templates/json_encoding.rb +1 -0
- data/templates/newrelic.yml.erb +34 -0
- data/templates/puma.rb +18 -0
- data/templates/routes.rb +90 -0
- data/templates/sample.env +6 -0
- data/templates/secrets.yml +14 -0
- data/templates/smtp.rb +9 -0
- data/templates/staging.rb +5 -0
- data/test/factories/article_factory.rb +19 -0
- data/test/files/test.jpg +0 -0
- data/test/integration/article_fullsize_test.rb +33 -0
- data/test/integration/article_test.rb +33 -0
- data/test/integration/magazine_article_test.rb +33 -0
- data/test/integration/restricted_article_test.rb +33 -0
- data/test/integration/sport_article_test.rb +34 -0
- data/test/rails_app/Rakefile +6 -0
- data/test/rails_app/app/assets/javascripts/admin.coffee +137 -0
- data/test/rails_app/app/assets/javascripts/application.js +1 -0
- data/test/rails_app/app/assets/stylesheets/admin.scss +1 -0
- data/test/rails_app/app/assets/stylesheets/application.css +1 -0
- data/test/rails_app/app/controllers/admin/articles_controller.rb +7 -0
- data/test/rails_app/app/controllers/admin/base_controller.rb +8 -0
- data/test/rails_app/app/controllers/application_controller.rb +5 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/models/article.rb +46 -0
- data/test/rails_app/app/uploaders/article_image_uploader.rb +16 -0
- data/test/rails_app/app/views/admin/index.html.erb +4 -0
- data/test/rails_app/app/views/layouts/admin.html.erb +17 -0
- data/test/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/rails_app/bin/bundle +3 -0
- data/test/rails_app/bin/rails +8 -0
- data/test/rails_app/bin/rake +8 -0
- data/test/rails_app/bin/setup +29 -0
- data/test/rails_app/bin/spring +15 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/config/application.rb +36 -0
- data/test/rails_app/config/boot.rb +3 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +38 -0
- data/test/rails_app/config/environments/production.rb +76 -0
- data/test/rails_app/config/environments/test.rb +46 -0
- data/test/rails_app/config/initializers/assets.rb +12 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/carrierwave.rb +5 -0
- data/test/rails_app/config/initializers/cookies_serializer.rb +3 -0
- data/test/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/rails_app/config/initializers/inflections.rb +16 -0
- data/test/rails_app/config/initializers/mime_types.rb +4 -0
- data/test/rails_app/config/initializers/session_store.rb +3 -0
- data/test/rails_app/config/initializers/wrap_parameters.rb +9 -0
- data/test/rails_app/config/locales/en.yml +23 -0
- data/test/rails_app/config/mongoid.yml +9 -0
- data/test/rails_app/config/routes.rb +8 -0
- data/test/rails_app/config/secrets.yml +22 -0
- data/test/rails_app/db/seeds.rb +7 -0
- data/test/rails_app/public/404.html +67 -0
- data/test/rails_app/public/422.html +67 -0
- data/test/rails_app/public/500.html +66 -0
- data/{app/assets/javascripts/form/input-date.coffee → test/rails_app/public/favicon.ico} +0 -0
- data/test/rails_app/public/robots.txt +5 -0
- data/test/support/character_front_end.rb +196 -0
- data/test/support/chr/item.rb +32 -0
- data/test/support/chr/list.rb +31 -0
- data/test/support/chr/list_pagination.rb +163 -0
- data/test/support/chr/list_reorder.rb +46 -0
- data/test/support/chr/list_search.rb +41 -0
- data/test/support/chr/view.rb +112 -0
- data/test/support/stores/array.rb +20 -0
- data/test/support/stores/rest-array.rb +34 -0
- data/test/test_helper.rb +68 -0
- metadata +373 -80
- data/Gruntfile.coffee +0 -101
- data/app/assets/javascripts/form/expandable-group.coffee +0 -30
- data/app/assets/javascripts/form/form.coffee +0 -221
- data/app/assets/javascripts/form/input-checkbox.coffee +0 -83
- data/app/assets/javascripts/form/input-color.coffee +0 -55
- data/app/assets/javascripts/form/input-file.coffee +0 -144
- data/app/assets/javascripts/form/input-form.coffee +0 -171
- data/app/assets/javascripts/form/input-form_reorder.coffee +0 -67
- data/app/assets/javascripts/form/input-hidden.coffee +0 -57
- data/app/assets/javascripts/form/input-list.coffee +0 -154
- data/app/assets/javascripts/form/input-list_reorder.coffee +0 -39
- data/app/assets/javascripts/form/input-list_typeahead.coffee +0 -55
- data/app/assets/javascripts/form/input-password.coffee +0 -32
- data/app/assets/javascripts/form/input-select.coffee +0 -84
- data/app/assets/javascripts/form/input-select2.coffee +0 -33
- data/app/assets/javascripts/form/input-string.coffee +0 -160
- data/app/assets/javascripts/form/input-text.coffee +0 -43
- data/app/assets/javascripts/input-html.coffee +0 -81
- data/app/assets/javascripts/input-markdown.coffee +0 -93
- data/app/assets/javascripts/input-redactor.coffee +0 -1
- data/app/assets/javascripts/redactor/input-redactor.coffee +0 -53
- data/app/assets/javascripts/redactor/input-redactor_character.coffee +0 -83
- data/app/assets/javascripts/redactor/input-redactor_images.coffee +0 -166
- data/app/assets/javascripts/vendor/ace.js +0 -18280
- data/app/assets/javascripts/vendor/jquery.scrollparent.js +0 -14
- data/app/assets/javascripts/vendor/jquery.textarea_autosize.js +0 -55
- data/app/assets/javascripts/vendor/jquery.typeahead.js +0 -1782
- data/app/assets/javascripts/vendor/marked.js +0 -1272
- data/app/assets/javascripts/vendor/mode-html.js +0 -2436
- data/app/assets/javascripts/vendor/mode-markdown.js +0 -2820
- data/app/assets/javascripts/vendor/redactor.fixedtoolbar.js +0 -107
- data/app/assets/javascripts/vendor/select2.js +0 -5274
- data/app/assets/stylesheets/_input-redactor.scss +0 -35
- data/app/assets/stylesheets/form/_expandable-group.scss +0 -16
- data/app/assets/stylesheets/form/_input-select2.scss +0 -94
- data/app/assets/stylesheets/form/_main.scss +0 -180
- data/app/assets/stylesheets/vendor/select2.css +0 -258
- data/bower.json +0 -38
- data/dist/chr.js +0 -5949
- data/dist/input-ace.js +0 -24946
- data/dist/input-redactor.js +0 -1
- data/lib/mongoid/character.rb +0 -30
- data/package.json +0 -10
|
@@ -1,144 +0,0 @@
|
|
|
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 FILE
|
|
11
|
-
# -----------------------------------------------------------------------------
|
|
12
|
-
# @TODO: add clear button when file is picked for the first time and you want
|
|
13
|
-
# to cancel that pick
|
|
14
|
-
# -----------------------------------------------------------------------------
|
|
15
|
-
class @InputFile extends InputString
|
|
16
|
-
constructor: (@name, @value, @config, @object) ->
|
|
17
|
-
@_create_el()
|
|
18
|
-
|
|
19
|
-
@_add_label()
|
|
20
|
-
@_add_input()
|
|
21
|
-
@_update_state()
|
|
22
|
-
@_add_required()
|
|
23
|
-
|
|
24
|
-
return this
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# PRIVATE ===============================================
|
|
28
|
-
|
|
29
|
-
_create_el: ->
|
|
30
|
-
@$el =$ "<div class='input-#{ @config.type } input-#{ @config.klass } input-#{ @config.klassName }'>"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
_add_input: ->
|
|
34
|
-
@$link =$ "<a href='#' target='_blank' title=''></a>"
|
|
35
|
-
@$el.append(@$link)
|
|
36
|
-
|
|
37
|
-
@$input =$ "<input type='file' name='#{ @name }' id='#{ @name }'>"
|
|
38
|
-
@$el.append @$input
|
|
39
|
-
|
|
40
|
-
@_add_clear_button()
|
|
41
|
-
@_add_remove_checkbox()
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
_add_clear_button: ->
|
|
45
|
-
@$clearButton =$ "<a href='#' class='input-file-clear'></a>"
|
|
46
|
-
@$input.after @$clearButton
|
|
47
|
-
@$clearButton.hide()
|
|
48
|
-
|
|
49
|
-
@$clearButton.on 'click', (e) =>
|
|
50
|
-
# clear file input:
|
|
51
|
-
# http://stackoverflow.com/questions/1043957/clearing-input-type-file-using-jquery
|
|
52
|
-
@$input.replaceWith(@$input = @$input.clone(true))
|
|
53
|
-
@$clearButton.hide()
|
|
54
|
-
e.preventDefault()
|
|
55
|
-
|
|
56
|
-
@$input.on 'change', (e) =>
|
|
57
|
-
@$clearButton.show()
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_add_remove_checkbox: ->
|
|
61
|
-
removeInputName = @removeName()
|
|
62
|
-
@$removeLabel =$ "<label for='#{ removeInputName }'>Remove</label>"
|
|
63
|
-
@$hiddenRemoveInput =$ "<input type='hidden' name='#{ removeInputName }' value='false'>"
|
|
64
|
-
@$removeInput =$ "<input type='checkbox' name='#{ removeInputName }' id='#{ removeInputName }' value='true'>"
|
|
65
|
-
@$link.after(@$removeLabel)
|
|
66
|
-
@$link.after(@$removeInput)
|
|
67
|
-
@$link.after(@$hiddenRemoveInput)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
_update_inputs: ->
|
|
71
|
-
@$link.html(@filename).attr('title', @filename).attr('href', @value.url)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
_update_state: (@filename=null) ->
|
|
75
|
-
@$input.val('')
|
|
76
|
-
@$removeInput.prop('checked', false)
|
|
77
|
-
|
|
78
|
-
if @value.url
|
|
79
|
-
@filename = _last(@value.url.split('/'))
|
|
80
|
-
if @filename == '_old_' then @filename = null # carrierwave filename workaround
|
|
81
|
-
|
|
82
|
-
if @filename
|
|
83
|
-
@$el.removeClass('empty')
|
|
84
|
-
@_update_inputs()
|
|
85
|
-
else
|
|
86
|
-
@$el.addClass('empty')
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
# PUBLIC ================================================
|
|
90
|
-
|
|
91
|
-
# when no file uploaded and no file selected, send remove flag so
|
|
92
|
-
# carrierwave does not catch _old_ value
|
|
93
|
-
isEmpty: ->
|
|
94
|
-
( ! @$input.get()[0].files[0] && ! @filename )
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
removeName: ->
|
|
98
|
-
@name.reverse().replace('[', '[remove_'.reverse()).reverse()
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
updateValue: (@value, @object) ->
|
|
102
|
-
@_update_state()
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
hash: (hash={})->
|
|
106
|
-
# @TODO: file input type does not support caching and versioning as of now
|
|
107
|
-
return hash
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
chr.formInputs['file'] = InputFile
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
# -----------------------------------------------------------------------------
|
|
114
|
-
# INPUT FILE IMAGE
|
|
115
|
-
# -----------------------------------------------------------------------------
|
|
116
|
-
# Config options:
|
|
117
|
-
# thumbnail(object) - method that returns thumbnail for input
|
|
118
|
-
# -----------------------------------------------------------------------------
|
|
119
|
-
class @InputFileImage extends InputFile
|
|
120
|
-
_add_input: ->
|
|
121
|
-
@$link =$ "<a href='#' target='_blank' title=''></a>"
|
|
122
|
-
@$el.append @$link
|
|
123
|
-
|
|
124
|
-
@$thumb =$ "<img src='' />"
|
|
125
|
-
@$el.append @$thumb
|
|
126
|
-
|
|
127
|
-
@$input =$ "<input type='file' name='#{ @name }' id='#{ @name }' />"
|
|
128
|
-
@$el.append @$input
|
|
129
|
-
|
|
130
|
-
@_add_clear_button()
|
|
131
|
-
@_add_remove_checkbox()
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
_update_inputs: ->
|
|
135
|
-
@$link.html(@filename).attr('title', @filename).attr('href', @value.url)
|
|
136
|
-
image_thumb_url = if @config.thumbnail then @config.thumbnail(@object) else @value.url
|
|
137
|
-
@$thumb.attr('src', image_thumb_url).attr('alt', @filename)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
chr.formInputs['image'] = InputFileImage
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
@@ -1,171 +0,0 @@
|
|
|
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 "NESTED" FORM
|
|
11
|
-
# -----------------------------------------------------------------------------
|
|
12
|
-
# Name for this input comes from the Rails gem 'nested_forms'.
|
|
13
|
-
#
|
|
14
|
-
# Public methods:
|
|
15
|
-
# initialize()
|
|
16
|
-
# hash(hash)
|
|
17
|
-
# updateValue(@value)
|
|
18
|
-
# showErrorMessage(message)
|
|
19
|
-
# hideErrorMessage()
|
|
20
|
-
# addNewForm(object)
|
|
21
|
-
#
|
|
22
|
-
# Dependencies:
|
|
23
|
-
#= require ./input-form_reorder
|
|
24
|
-
#
|
|
25
|
-
# -----------------------------------------------------------------------------
|
|
26
|
-
|
|
27
|
-
class @InputForm
|
|
28
|
-
constructor: (@name, @nestedObjects, @config, @object) ->
|
|
29
|
-
@forms = []
|
|
30
|
-
|
|
31
|
-
@config.namePrefix ||= name
|
|
32
|
-
@config.removeButton = true
|
|
33
|
-
@config.formSchema._id = { type: 'hidden', name: 'id' }
|
|
34
|
-
@reorderContainerClass = "nested-forms-#{@config.klassName}"
|
|
35
|
-
|
|
36
|
-
@_create_el()
|
|
37
|
-
|
|
38
|
-
@_add_label()
|
|
39
|
-
@_add_forms()
|
|
40
|
-
@_add_new_button()
|
|
41
|
-
|
|
42
|
-
return this
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
# PRIVATE ===============================================
|
|
46
|
-
|
|
47
|
-
_create_el: ->
|
|
48
|
-
@$el =$ "<div class='input-stacked nested-forms input-#{ @config.klassName }'>"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
_add_label: ->
|
|
52
|
-
@$label =$ "<span class='label'>#{ @config.label }</span>"
|
|
53
|
-
@$errorMessage =$ "<span class='error-message'></span>"
|
|
54
|
-
@$label.append(@$errorMessage)
|
|
55
|
-
@$el.append(@$label)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
_add_forms: ->
|
|
59
|
-
@$forms =$ "<ul>"
|
|
60
|
-
@$label.after @$forms
|
|
61
|
-
|
|
62
|
-
# if not default value which means no objects
|
|
63
|
-
if @nestedObjects != ''
|
|
64
|
-
@_sort_nested_objects()
|
|
65
|
-
|
|
66
|
-
for i, object of @nestedObjects
|
|
67
|
-
namePrefix = "#{ @config.namePrefix }[#{ i }]"
|
|
68
|
-
@forms.push @_render_form(object, namePrefix, @config)
|
|
69
|
-
|
|
70
|
-
@_bind_forms_reorder()
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
_sort_nested_objects: ->
|
|
74
|
-
if @config.sortBy
|
|
75
|
-
@config.formSchema[@config.sortBy] = { type: 'hidden' }
|
|
76
|
-
if @nestedObjects
|
|
77
|
-
# this is not required but make things a bit easier on the backend
|
|
78
|
-
# as object don't have to be in a specific order.
|
|
79
|
-
@nestedObjects.sort (a, b) => parseFloat(a[@config.sortBy]) - parseFloat(b[@config.sortBy])
|
|
80
|
-
# normalizes nested objects positions
|
|
81
|
-
(o[@config.sortBy] = parseInt(i) + 1) for i, o of @nestedObjects
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
_render_form: (object, namePrefix, config) ->
|
|
85
|
-
formConfig = $.extend {}, config,
|
|
86
|
-
namePrefix: namePrefix
|
|
87
|
-
rootEl: "<li>"
|
|
88
|
-
|
|
89
|
-
form = new Form(object, formConfig)
|
|
90
|
-
@$forms.append form.$el
|
|
91
|
-
|
|
92
|
-
return form
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_add_new_button: ->
|
|
96
|
-
label = @config.newButtonLabel || "Add"
|
|
97
|
-
@$newButton =$ """<a href='#' class='nested-form-new'>#{ label }</a>"""
|
|
98
|
-
@$el.append @$newButton
|
|
99
|
-
@$newButton.on 'click', (e) => e.preventDefault() ; @addNewForm()
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
# PUBLIC ================================================
|
|
103
|
-
|
|
104
|
-
initialize: ->
|
|
105
|
-
@config.beforeInitialize?(this)
|
|
106
|
-
|
|
107
|
-
for nestedForm in @forms
|
|
108
|
-
nestedForm.initializePlugins()
|
|
109
|
-
@config.onInitialize?(this)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
hash: (hash={}) ->
|
|
113
|
-
objects = []
|
|
114
|
-
objects.push(form.hash()) for form in @forms
|
|
115
|
-
hash[@config.fieldName] = objects
|
|
116
|
-
return hash
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
showErrorMessage: (message) ->
|
|
120
|
-
@$el.addClass 'error'
|
|
121
|
-
@$errorMessage.html(message)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
hideErrorMessage: ->
|
|
125
|
-
@$el.removeClass 'error'
|
|
126
|
-
@$errorMessage.html('')
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
addNewForm: (object=null) ->
|
|
130
|
-
namePrefix = "#{ @config.namePrefix }[#{ Date.now() }]"
|
|
131
|
-
newFormConfig = $.extend({}, @config)
|
|
132
|
-
|
|
133
|
-
delete newFormConfig.formSchema._id
|
|
134
|
-
|
|
135
|
-
form = @_render_form(object, namePrefix, newFormConfig)
|
|
136
|
-
form.initializePlugins()
|
|
137
|
-
|
|
138
|
-
if @config.sortBy
|
|
139
|
-
@_add_form_reorder_button(form)
|
|
140
|
-
prevForm = _last(@forms)
|
|
141
|
-
position = if prevForm then prevForm.inputs[@config.sortBy].value + 1 else 1
|
|
142
|
-
|
|
143
|
-
# @TODO: having an issue here for scenario when no nested object are there for new object
|
|
144
|
-
# form.inputs doesn't include sortBy field
|
|
145
|
-
console.log @config
|
|
146
|
-
console.log @config.sortBy
|
|
147
|
-
console.log form.inputs
|
|
148
|
-
|
|
149
|
-
form.inputs[@config.sortBy].updateValue(position)
|
|
150
|
-
|
|
151
|
-
@forms.push(form)
|
|
152
|
-
|
|
153
|
-
@config.onNew?(form)
|
|
154
|
-
|
|
155
|
-
return form
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
updateValue: (@nestedObjects, @object) ->
|
|
159
|
-
@$forms.remove()
|
|
160
|
-
@forms = []
|
|
161
|
-
@_add_forms()
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
include(InputForm, inputFormReorder)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
chr.formInputs['form'] = InputForm
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
@@ -1,67 +0,0 @@
|
|
|
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 "NESTED" FORM REORDER
|
|
11
|
-
# -----------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
@inputFormReorder =
|
|
14
|
-
# PRIVATE ===============================================
|
|
15
|
-
|
|
16
|
-
_bind_forms_reorder: ->
|
|
17
|
-
if @config.sortBy
|
|
18
|
-
list = @$forms.addClass(@reorderContainerClass).get(0)
|
|
19
|
-
|
|
20
|
-
new Slip(list)
|
|
21
|
-
|
|
22
|
-
list.addEventListener 'slip:beforeswipe', (e) -> e.preventDefault()
|
|
23
|
-
|
|
24
|
-
list.addEventListener 'slip:beforewait', ((e) ->
|
|
25
|
-
if $(e.target).hasClass("icon-reorder") then e.preventDefault()
|
|
26
|
-
), false
|
|
27
|
-
|
|
28
|
-
list.addEventListener 'slip:beforereorder', ((e) ->
|
|
29
|
-
if not $(e.target).hasClass("icon-reorder") then e.preventDefault()
|
|
30
|
-
), false
|
|
31
|
-
|
|
32
|
-
list.addEventListener 'slip:reorder', ((e) =>
|
|
33
|
-
# this event called for all parent lists, add a check for context:
|
|
34
|
-
# process this event only if target form is in the @forms list.
|
|
35
|
-
targetForm = @_find_form_by_target(e.target)
|
|
36
|
-
if targetForm
|
|
37
|
-
# when `e.detail.insertBefore` is null, item put to the end of the list.
|
|
38
|
-
e.target.parentNode.insertBefore(e.target, e.detail.insertBefore)
|
|
39
|
-
|
|
40
|
-
$targetForm =$ e.target
|
|
41
|
-
prevForm = @_find_form_by_target($targetForm.prev().get(0))
|
|
42
|
-
nextForm = @_find_form_by_target($targetForm.next().get(0))
|
|
43
|
-
|
|
44
|
-
prevFormPosition = if prevForm then prevForm.inputs[@config.sortBy].value else 0
|
|
45
|
-
nextFormPosition = if nextForm then nextForm.inputs[@config.sortBy].value else 0
|
|
46
|
-
newTargetFormPosition = prevFormPosition + Math.abs(nextFormPosition - prevFormPosition) / 2.0
|
|
47
|
-
|
|
48
|
-
targetForm.inputs[@config.sortBy].updateValue(newTargetFormPosition)
|
|
49
|
-
|
|
50
|
-
return false
|
|
51
|
-
), false
|
|
52
|
-
|
|
53
|
-
@_add_form_reorder_button(form) for form in @forms
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
_add_form_reorder_button: (form) ->
|
|
57
|
-
form.$el.append("""<div class='icon-reorder' data-container-class='#{@reorderContainerClass}'></div>""").addClass('reorderable')
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
_find_form_by_target: (el) ->
|
|
61
|
-
if el
|
|
62
|
-
for form in @forms
|
|
63
|
-
if form.$el.get(0) == el then return form
|
|
64
|
-
return null
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
@@ -1,57 +0,0 @@
|
|
|
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 HIDDEN
|
|
11
|
-
# -----------------------------------------------------------------------------
|
|
12
|
-
class @InputHidden
|
|
13
|
-
constructor: (@name, @value, @config, @object) ->
|
|
14
|
-
@_create_el()
|
|
15
|
-
|
|
16
|
-
return this
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# PRIVATE ===============================================
|
|
20
|
-
|
|
21
|
-
_create_el: ->
|
|
22
|
-
@$el =$ "<input type='hidden' name='#{ @name }' value='#{ @_safe_value() }' />"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
_safe_value: ->
|
|
26
|
-
if typeof(@value) == 'object'
|
|
27
|
-
return JSON.stringify(@value)
|
|
28
|
-
else
|
|
29
|
-
_escapeHtml(@value)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
# PUBLIC ================================================
|
|
33
|
-
|
|
34
|
-
showErrorMessage: (message) -> ;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
hideErrorMessage: -> ;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
initialize: ->
|
|
41
|
-
@config.onInitialize?(this)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
hash: (hash={}) ->
|
|
45
|
-
hash[@config.klassName] = @$el.val()
|
|
46
|
-
return hash
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
updateValue: (@value) ->
|
|
50
|
-
@$el.val(@value)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
chr.formInputs['hidden'] = InputHidden
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
@@ -1,154 +0,0 @@
|
|
|
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 LIST
|
|
11
|
-
# -----------------------------------------------------------------------------
|
|
12
|
-
# Allows to create/delete/reorder list items connected to dynamic or static
|
|
13
|
-
# collection. Value should be an array of objects.
|
|
14
|
-
#
|
|
15
|
-
# All items should be unique for now.
|
|
16
|
-
#
|
|
17
|
-
# Dependencies:
|
|
18
|
-
#= require ./input-list_reorder
|
|
19
|
-
#= require ./input-list_typeahead
|
|
20
|
-
#
|
|
21
|
-
# -----------------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
class @InputList extends InputString
|
|
24
|
-
|
|
25
|
-
# PRIVATE ===============================================
|
|
26
|
-
|
|
27
|
-
_add_input: ->
|
|
28
|
-
# @TODO: check if we can use @config.name instead of @config.target
|
|
29
|
-
# @config.target ?= @config.klassName
|
|
30
|
-
|
|
31
|
-
# hidden input that stores ids, we use __LIST__ prefix to identify
|
|
32
|
-
# ARRAY input type and process it's value while form submission.
|
|
33
|
-
name = if @config.namePrefix then "#{ @config.namePrefix }[__LIST__#{ @config.target }]" else "[__LIST__#{ @config.target }]"
|
|
34
|
-
|
|
35
|
-
@$input =$ "<input type='hidden' name='#{ name }' value='' />"
|
|
36
|
-
@$el.append @$input
|
|
37
|
-
|
|
38
|
-
# list holder for items
|
|
39
|
-
@reorderContainerClass = @config.klassName
|
|
40
|
-
@$items =$ "<ul class='#{ @reorderContainerClass }'></ul>"
|
|
41
|
-
@$el.append @$items
|
|
42
|
-
|
|
43
|
-
# other options might be added here (static collection)
|
|
44
|
-
|
|
45
|
-
@_create_typeahead_el(@config.typeahead.placeholder)
|
|
46
|
-
|
|
47
|
-
@_render_items()
|
|
48
|
-
@_update_input_value()
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
_update_input_value: ->
|
|
52
|
-
ids = []
|
|
53
|
-
@$items.children('li').each (i, el) -> ids.push $(el).attr('data-id')
|
|
54
|
-
|
|
55
|
-
# @TODO: we need a better separator here, comma is too generic
|
|
56
|
-
# it's used cause most cases list of IDs concidered to be here,
|
|
57
|
-
# we might make this a @config setting.
|
|
58
|
-
value = ids.join(',')
|
|
59
|
-
|
|
60
|
-
@$input.val(value)
|
|
61
|
-
@$input.trigger('change')
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
_remove_item: ($el) ->
|
|
65
|
-
id = $el.attr('data-id')
|
|
66
|
-
delete @objects[id]
|
|
67
|
-
|
|
68
|
-
$el.parent().remove()
|
|
69
|
-
@_update_input_value()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
_ordered_ids: ->
|
|
73
|
-
ids = @$input.val().split(',')
|
|
74
|
-
if ids[0] == '' then ids = []
|
|
75
|
-
return ids
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
_render_items: ->
|
|
79
|
-
@$items.html('')
|
|
80
|
-
@objects = {}
|
|
81
|
-
|
|
82
|
-
for o in @value
|
|
83
|
-
@_render_item(o)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
_render_item: (o) ->
|
|
87
|
-
@_add_object(o)
|
|
88
|
-
|
|
89
|
-
if @config.itemTemplate
|
|
90
|
-
item = @config.itemTemplate(o)
|
|
91
|
-
else
|
|
92
|
-
item = o[@config.titleFieldName]
|
|
93
|
-
|
|
94
|
-
listItem =$ """<li data-id='#{ o._id }'>
|
|
95
|
-
<span class='icon-reorder' data-container-class='#{ @reorderContainerClass }'></span>
|
|
96
|
-
#{ item }
|
|
97
|
-
<a href='#' class='action_remove'>Remove</a>
|
|
98
|
-
</li>"""
|
|
99
|
-
@$items.append(listItem)
|
|
100
|
-
@_update_input_value()
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
_add_object: (o) ->
|
|
104
|
-
@_normalize_object(o)
|
|
105
|
-
@objects[o._id] = o
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
_normalize_object: (o) ->
|
|
109
|
-
o._id ?= o.id
|
|
110
|
-
if ! o._id then console.log("::: list item is missing an 'id' or '_id' :::")
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
# PUBLIC ================================================
|
|
114
|
-
|
|
115
|
-
initialize: ->
|
|
116
|
-
@config.beforeInitialize?(this)
|
|
117
|
-
|
|
118
|
-
# typeahead
|
|
119
|
-
@_bind_typeahead()
|
|
120
|
-
|
|
121
|
-
# remove
|
|
122
|
-
@$items.on 'click', '.action_remove', (e) =>
|
|
123
|
-
e.preventDefault()
|
|
124
|
-
if confirm('Are you sure?') then @_remove_item($(e.currentTarget))
|
|
125
|
-
|
|
126
|
-
@_bind_reorder()
|
|
127
|
-
|
|
128
|
-
@config.onInitialize?(this)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
updateValue: (@value) ->
|
|
132
|
-
@_render_items()
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
hash: (hash={}) ->
|
|
136
|
-
hash[@config.target] = @$input.val()
|
|
137
|
-
ordered_objects = []
|
|
138
|
-
|
|
139
|
-
for id in @_ordered_ids()
|
|
140
|
-
ordered_objects.push(@objects[id])
|
|
141
|
-
|
|
142
|
-
hash[@config.klassName] = ordered_objects
|
|
143
|
-
return hash
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
include(InputList, inputListReorder)
|
|
147
|
-
include(InputList, inputListTypeahead)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
chr.formInputs['list'] = InputList
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|