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
data/Gruntfile.coffee
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
module.exports = (grunt) ->
|
|
2
|
-
# Project configuration
|
|
3
|
-
grunt.initConfig
|
|
4
|
-
pkg: grunt.file.readJSON('package.json')
|
|
5
|
-
coffee:
|
|
6
|
-
compileBare:
|
|
7
|
-
options:
|
|
8
|
-
bare: true
|
|
9
|
-
files:
|
|
10
|
-
'build/chr.js': [
|
|
11
|
-
# core
|
|
12
|
-
'app/assets/javascripts/chr/core/utils.coffee'
|
|
13
|
-
'app/assets/javascripts/chr/core/chr_router.coffee'
|
|
14
|
-
'app/assets/javascripts/chr/core/chr.coffee'
|
|
15
|
-
'app/assets/javascripts/chr/core/module.coffee'
|
|
16
|
-
'app/assets/javascripts/chr/core/list_config.coffee'
|
|
17
|
-
'app/assets/javascripts/chr/core/list_pagination.coffee'
|
|
18
|
-
'app/assets/javascripts/chr/core/list_reorder.coffee'
|
|
19
|
-
'app/assets/javascripts/chr/core/list_search.coffee'
|
|
20
|
-
'app/assets/javascripts/chr/core/list.coffee'
|
|
21
|
-
'app/assets/javascripts/chr/core/item.coffee'
|
|
22
|
-
'app/assets/javascripts/chr/core/view_local-storage.coffee'
|
|
23
|
-
'app/assets/javascripts/chr/core/view.coffee'
|
|
24
|
-
# stores
|
|
25
|
-
'app/assets/javascripts/chr/store/array-store.coffee'
|
|
26
|
-
'app/assets/javascripts/chr/store/object-store.coffee'
|
|
27
|
-
'app/assets/javascripts/chr/store/rest-array-store.coffee'
|
|
28
|
-
'app/assets/javascripts/chr/store/rest-object-store.coffee'
|
|
29
|
-
'app/assets/javascripts/chr/store/rails-form-object-parser.coffee'
|
|
30
|
-
'app/assets/javascripts/chr/store/rails-array-store.coffee'
|
|
31
|
-
'app/assets/javascripts/chr/store/rails-object-store.coffee'
|
|
32
|
-
# form
|
|
33
|
-
'app/assets/javascripts/form/form.coffee'
|
|
34
|
-
'app/assets/javascripts/form/input-form_reorder.coffee'
|
|
35
|
-
'app/assets/javascripts/form/input-form.coffee'
|
|
36
|
-
'app/assets/javascripts/form/input-string.coffee'
|
|
37
|
-
'app/assets/javascripts/form/input-hidden.coffee'
|
|
38
|
-
'app/assets/javascripts/form/input-checkbox.coffee'
|
|
39
|
-
'app/assets/javascripts/form/input-color.coffee'
|
|
40
|
-
'app/assets/javascripts/form/input-date.coffee'
|
|
41
|
-
'app/assets/javascripts/form/input-file.coffee'
|
|
42
|
-
'app/assets/javascripts/form/input-list_typeahead.coffee'
|
|
43
|
-
'app/assets/javascripts/form/input-list_reorder.coffee'
|
|
44
|
-
'app/assets/javascripts/form/input-list.coffee'
|
|
45
|
-
'app/assets/javascripts/form/input-password.coffee'
|
|
46
|
-
'app/assets/javascripts/form/input-select.coffee'
|
|
47
|
-
'app/assets/javascripts/form/input-text.coffee'
|
|
48
|
-
'app/assets/javascripts/form/input-select2.coffee'
|
|
49
|
-
'app/assets/javascripts/form/extendable-group.coffee'
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
'build/input-ace.js': [
|
|
53
|
-
'app/assets/javascripts/input-html.coffee'
|
|
54
|
-
'app/assets/javascripts/input-markdown.coffee'
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
-
'build/input-redactor.js': [
|
|
58
|
-
'app/assets/javascripts/input-redactor.coffee'
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
concat:
|
|
62
|
-
chr:
|
|
63
|
-
src: [
|
|
64
|
-
'app/assets/javascripts/vendor/slip.js'
|
|
65
|
-
'app/assets/javascripts/vendor/jquery.scrollparent.js'
|
|
66
|
-
'app/assets/javascripts/vendor/jquery.textarea_autosize.js'
|
|
67
|
-
'app/assets/javascripts/vendor/jquery.typeahead.js'
|
|
68
|
-
'build/chr.js'
|
|
69
|
-
]
|
|
70
|
-
dest: 'dist/chr.js'
|
|
71
|
-
|
|
72
|
-
ace:
|
|
73
|
-
src: [
|
|
74
|
-
'app/assets/javascripts/vendor/ace.js'
|
|
75
|
-
'app/assets/javascripts/vendor/mode-html.js'
|
|
76
|
-
'app/assets/javascripts/vendor/mode-markdown.js'
|
|
77
|
-
'app/assets/javascripts/vendor/marked.js'
|
|
78
|
-
'build/input-ace.js'
|
|
79
|
-
]
|
|
80
|
-
dest: 'dist/input-ace.js'
|
|
81
|
-
|
|
82
|
-
redactor:
|
|
83
|
-
src: [
|
|
84
|
-
'app/assets/javascripts/chr/vendor/redactor.fixedtoolbar.js'
|
|
85
|
-
'build/input-redactor.js'
|
|
86
|
-
]
|
|
87
|
-
dest: 'dist/input-redactor.js'
|
|
88
|
-
|
|
89
|
-
clean: [
|
|
90
|
-
'build'
|
|
91
|
-
]
|
|
92
|
-
|
|
93
|
-
grunt.loadNpmTasks('grunt-contrib-coffee')
|
|
94
|
-
grunt.loadNpmTasks('grunt-contrib-concat')
|
|
95
|
-
grunt.loadNpmTasks('grunt-contrib-clean')
|
|
96
|
-
|
|
97
|
-
grunt.registerTask('default', ['coffee', 'concat', 'clean'])
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
@@ -1,30 +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
|
-
# EXPANDABLE GROUP
|
|
11
|
-
# -----------------------------------------------------------------------------
|
|
12
|
-
#
|
|
13
|
-
# Usage: onInitialize: (form, group) -> new ExpandableGroup(form, group, 'Details')
|
|
14
|
-
#
|
|
15
|
-
# -----------------------------------------------------------------------------
|
|
16
|
-
|
|
17
|
-
#@_expandableGroupStateCache = {}
|
|
18
|
-
|
|
19
|
-
class @ExpandableGroup
|
|
20
|
-
constructor: (@form, @group, name) ->
|
|
21
|
-
@$expander =$ """<a href='#' class='group-edit hidden'>#{ name }</a>"""
|
|
22
|
-
@group.$el.before @$expander
|
|
23
|
-
|
|
24
|
-
@$expander.on 'click', (e) =>
|
|
25
|
-
@$expander.toggleClass('hidden')
|
|
26
|
-
e.preventDefault()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
@@ -1,221 +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
|
-
# 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
|
-
if config.type == 'group'
|
|
74
|
-
group = @_generate_inputs_group(fieldName, config)
|
|
75
|
-
$el.append group.$el
|
|
76
|
-
else
|
|
77
|
-
input = @_generate_input(fieldName, config)
|
|
78
|
-
$el.append input.$el
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
_generate_inputs_group: (klassName, groupConfig) ->
|
|
82
|
-
$group =$ """<div class='group #{ klassName }' />"""
|
|
83
|
-
if groupConfig.inputs
|
|
84
|
-
@_build_schema(groupConfig.inputs, $group)
|
|
85
|
-
group = { $el: $group, klassName: klassName, onInitialize: groupConfig.onInitialize }
|
|
86
|
-
@groups.push group
|
|
87
|
-
return group
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
_generate_input: (fieldName, inputConfig) ->
|
|
91
|
-
if @object
|
|
92
|
-
value = @object[fieldName]
|
|
93
|
-
else
|
|
94
|
-
value = inputConfig.default
|
|
95
|
-
|
|
96
|
-
value ?= ''
|
|
97
|
-
|
|
98
|
-
inputName = inputConfig.name || fieldName
|
|
99
|
-
input = @_render_input(inputName, inputConfig, value)
|
|
100
|
-
@inputs[fieldName] = input
|
|
101
|
-
return input
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
_render_input: (name, config, value) ->
|
|
105
|
-
inputConfig = $.extend {}, config
|
|
106
|
-
|
|
107
|
-
inputConfig.label ?= name.titleize()
|
|
108
|
-
inputConfig.type ?= 'string'
|
|
109
|
-
inputConfig.klass ?= 'stacked'
|
|
110
|
-
inputConfig.klassName = name
|
|
111
|
-
|
|
112
|
-
inputClass = chr.formInputs[inputConfig.type]
|
|
113
|
-
inputClass ?= chr.formInputs['string']
|
|
114
|
-
|
|
115
|
-
inputName = if @config.namePrefix then "#{ @config.namePrefix }[#{ name }]" else "[#{ name }]"
|
|
116
|
-
|
|
117
|
-
# add prefix for nested form inputs
|
|
118
|
-
if inputConfig.type == 'form'
|
|
119
|
-
inputConfig.namePrefix = inputName.replace("[#{ name }]", "[#{ name }_attributes]")
|
|
120
|
-
else
|
|
121
|
-
inputConfig.namePrefix = @config.namePrefix
|
|
122
|
-
|
|
123
|
-
return new inputClass(inputName, value, inputConfig, @object)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
# NESTED ================================================
|
|
127
|
-
|
|
128
|
-
_add_nested_form_remove_button: ->
|
|
129
|
-
if @config.removeButton
|
|
130
|
-
# add hidden input to the form
|
|
131
|
-
fieldName = '_destroy'
|
|
132
|
-
input = @_render_input(fieldName, { type: 'hidden' }, false)
|
|
133
|
-
@inputs[fieldName] = input
|
|
134
|
-
@$el.append input.$el
|
|
135
|
-
# remove button
|
|
136
|
-
@$removeButton =$ """<a href='#' class='nested-form-delete'>Delete</a>"""
|
|
137
|
-
@$el.append @$removeButton
|
|
138
|
-
@$removeButton.on 'click', (e) =>
|
|
139
|
-
e.preventDefault()
|
|
140
|
-
if confirm('Are you sure?')
|
|
141
|
-
input.updateValue('true')
|
|
142
|
-
@$el.hide()
|
|
143
|
-
@isRemoved = true
|
|
144
|
-
@config.onRemove?(this)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
_forms: ->
|
|
148
|
-
forms = [ @ ]
|
|
149
|
-
addNestedForms = (form) ->
|
|
150
|
-
for name, input of form.inputs
|
|
151
|
-
if input.config.type == 'form'
|
|
152
|
-
forms = forms.concat(input.forms)
|
|
153
|
-
addNestedForms(form) for form in input.forms
|
|
154
|
-
addNestedForms(@)
|
|
155
|
-
|
|
156
|
-
return forms
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
# PUBLIC ================================================
|
|
160
|
-
|
|
161
|
-
destroy: ->
|
|
162
|
-
group.destroy?() for group in @groups
|
|
163
|
-
input.destroy?() for name, input of @inputs
|
|
164
|
-
@$el.remove()
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
serialize: (obj={}) ->
|
|
168
|
-
# serialize everything except file inputs
|
|
169
|
-
obj[input.name] = input.value for input in @$el.serializeArray()
|
|
170
|
-
|
|
171
|
-
for form in @_forms()
|
|
172
|
-
# serialize file inputs for all forms (including nested)
|
|
173
|
-
for name, input of form.inputs
|
|
174
|
-
if input.config.type == 'file' or input.config.type == 'image'
|
|
175
|
-
file = input.$input.get()[0].files[0]
|
|
176
|
-
obj["__FILE__#{ input.name }"] = file
|
|
177
|
-
if input.isEmpty() then obj[input.removeName()] = 'true'
|
|
178
|
-
|
|
179
|
-
# remove fields with ignoreOnSubmission
|
|
180
|
-
for name, input of form.inputs
|
|
181
|
-
if input.config.ignoreOnSubmission
|
|
182
|
-
delete obj[name]
|
|
183
|
-
|
|
184
|
-
return obj
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
hash: (hash={}) ->
|
|
188
|
-
for name, input of @inputs
|
|
189
|
-
input.hash(hash)
|
|
190
|
-
return hash
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
initializePlugins: ->
|
|
194
|
-
for group in @groups
|
|
195
|
-
group.onInitialize?(@, group)
|
|
196
|
-
|
|
197
|
-
for name, input of @inputs
|
|
198
|
-
input.initialize()
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
showValidationErrors: (errors) ->
|
|
202
|
-
@hideValidationErrors()
|
|
203
|
-
for inputName, messages of errors
|
|
204
|
-
input = @inputs[inputName]
|
|
205
|
-
firstMessage = messages[0]
|
|
206
|
-
input.showErrorMessage(firstMessage)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
hideValidationErrors: ->
|
|
210
|
-
for inputName, input of @inputs
|
|
211
|
-
input.hideErrorMessage()
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
updateValues: (object) ->
|
|
215
|
-
for name, value of object
|
|
216
|
-
if @inputs[name]
|
|
217
|
-
@inputs[name].updateValue(value, object)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
@@ -1,83 +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 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
|
-
|
|
@@ -1,55 +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 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
|
-
|