chr 0.2.8 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/Gruntfile.coffee +33 -27
  3. data/README.md +6 -1
  4. data/app/assets/javascripts/chr.coffee +18 -16
  5. data/app/assets/javascripts/chr/core/chr.coffee +41 -76
  6. data/app/assets/javascripts/chr/core/chr_router.coffee +141 -0
  7. data/app/assets/javascripts/chr/core/item.coffee +36 -49
  8. data/app/assets/javascripts/chr/core/list.coffee +26 -71
  9. data/app/assets/javascripts/chr/core/list_config.coffee +28 -13
  10. data/app/assets/javascripts/chr/core/list_pagination.coffee +56 -13
  11. data/app/assets/javascripts/chr/core/list_reorder.coffee +2 -2
  12. data/app/assets/javascripts/chr/core/list_search.coffee +2 -2
  13. data/app/assets/javascripts/chr/core/module.coffee +24 -93
  14. data/app/assets/javascripts/chr/core/utils.coffee +4 -0
  15. data/app/assets/javascripts/chr/core/view.coffee +123 -43
  16. data/app/assets/javascripts/chr/core/view_local-storage.coffee +58 -0
  17. data/app/assets/javascripts/chr/store/{_array-store.coffee → array-store.coffee} +3 -1
  18. data/app/assets/javascripts/chr/store/{_object-store.coffee → object-store.coffee} +0 -0
  19. data/app/assets/javascripts/chr/store/rails-array-store.coffee +39 -0
  20. data/app/assets/javascripts/chr/store/{mongosteen-object-store.coffee → rails-form-object-parser.coffee} +11 -20
  21. data/app/assets/javascripts/chr/store/rails-object-store.coffee +35 -0
  22. data/app/assets/javascripts/chr/store/rest-array-store.coffee +3 -5
  23. data/app/assets/javascripts/chr/store/rest-object-store.coffee +1 -1
  24. data/app/assets/javascripts/form/expandable-group.coffee +30 -0
  25. data/app/assets/javascripts/{chr/form → form}/form.coffee +3 -1
  26. data/app/assets/javascripts/{chr/form → form}/input-checkbox.coffee +1 -1
  27. data/app/assets/javascripts/{chr/form → form}/input-color.coffee +2 -0
  28. data/app/assets/javascripts/{chr/form → form}/input-date.coffee +0 -0
  29. data/app/assets/javascripts/{chr/form → form}/input-file.coffee +28 -1
  30. data/app/assets/javascripts/{chr/form → form}/input-form.coffee +14 -5
  31. data/app/assets/javascripts/{chr/form → form}/input-form_reorder.coffee +0 -0
  32. data/app/assets/javascripts/{chr/form → form}/input-hidden.coffee +9 -9
  33. data/app/assets/javascripts/{chr/form → form}/input-list.coffee +61 -53
  34. data/app/assets/javascripts/{chr/form → form}/input-list_reorder.coffee +2 -0
  35. data/app/assets/javascripts/form/input-list_typeahead.coffee +55 -0
  36. data/app/assets/javascripts/{chr/form → form}/input-password.coffee +1 -0
  37. data/app/assets/javascripts/{chr/form → form}/input-select.coffee +10 -11
  38. data/app/assets/javascripts/form/input-select2.coffee +33 -0
  39. data/app/assets/javascripts/{chr/form → form}/input-string.coffee +45 -2
  40. data/app/assets/javascripts/{chr/form → form}/input-text.coffee +6 -3
  41. data/app/assets/javascripts/input-html.coffee +8 -5
  42. data/app/assets/javascripts/input-markdown.coffee +10 -5
  43. data/app/assets/javascripts/input-redactor.coffee +1 -61
  44. data/app/assets/javascripts/redactor/input-redactor.coffee +53 -0
  45. data/app/assets/javascripts/redactor/input-redactor_character.coffee +83 -0
  46. data/app/assets/javascripts/redactor/input-redactor_images.coffee +166 -0
  47. data/app/assets/javascripts/{chr/vendor → vendor}/ace.js +0 -0
  48. data/app/assets/javascripts/{chr/vendor → vendor}/jquery.scrollparent.js +0 -0
  49. data/app/assets/javascripts/{chr/vendor → vendor}/jquery.textarea_autosize.js +0 -0
  50. data/app/assets/javascripts/{chr/vendor → vendor}/jquery.typeahead.js +0 -0
  51. data/app/assets/javascripts/{chr/vendor → vendor}/marked.js +0 -0
  52. data/app/assets/javascripts/{chr/vendor → vendor}/mode-html.js +0 -0
  53. data/app/assets/javascripts/{chr/vendor → vendor}/mode-markdown.js +0 -0
  54. data/app/assets/javascripts/{chr/vendor → vendor}/redactor.fixedtoolbar.js +1 -1
  55. data/app/assets/javascripts/vendor/select2.js +5274 -0
  56. data/app/assets/javascripts/{chr/vendor → vendor}/slip.js +0 -0
  57. data/app/assets/stylesheets/_chr.scss +11 -13
  58. data/app/assets/stylesheets/_input-redactor.scss +17 -16
  59. data/app/assets/stylesheets/{core → chr}/_icons.scss +1 -1
  60. data/app/assets/stylesheets/chr/_main.scss +110 -0
  61. data/app/assets/stylesheets/{core → chr}/_mixins.scss +58 -34
  62. data/app/assets/stylesheets/{core → chr}/_settings.scss +7 -1
  63. data/app/assets/stylesheets/form/_expandable-group.scss +16 -0
  64. data/app/assets/stylesheets/form/_input-select2.scss +94 -0
  65. data/app/assets/stylesheets/form/_main.scss +180 -0
  66. data/app/assets/stylesheets/vendor/select2.css +258 -0
  67. data/bower.json +2 -2
  68. data/dist/chr.js +2292 -2030
  69. data/dist/input-ace.js +18 -8
  70. data/dist/input-redactor.js +0 -156
  71. data/docs/bootstrap.md +1 -1
  72. data/docs/rails.md +10 -10
  73. data/lib/chr.rb +1 -8
  74. data/lib/chr/version.rb +1 -1
  75. data/lib/mongoid/character.rb +30 -0
  76. data/package.json +1 -1
  77. metadata +49 -43
  78. data/app/assets/javascripts/chr/store/mongosteen-array-store.coffee +0 -55
  79. data/app/assets/stylesheets/core/_list.scss +0 -39
  80. data/app/assets/stylesheets/core/_main.scss +0 -49
  81. data/app/assets/stylesheets/core/_responsive.scss +0 -62
  82. data/app/assets/stylesheets/form/_form.scss +0 -41
  83. data/app/assets/stylesheets/form/_input-checkbox.scss +0 -18
  84. data/app/assets/stylesheets/form/_input-color.scss +0 -10
  85. data/app/assets/stylesheets/form/_input-file.scss +0 -29
  86. data/app/assets/stylesheets/form/_input-form.scss +0 -26
  87. data/app/assets/stylesheets/form/_input-list.scss +0 -36
  88. data/app/assets/stylesheets/form/_input-string.scss +0 -8
@@ -0,0 +1,58 @@
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
+ # VIEW LOCAL STORAGE
11
+ # -----------------------------------------------------------------------------
12
+ # @TODO: test how this works with nested forms
13
+ # -----------------------------------------------------------------------------
14
+
15
+ @viewLocalStorage =
16
+
17
+ # PRIVATE ===============================================
18
+
19
+ _bind_form_change: ->
20
+ if typeof(Storage)
21
+ @form.$el.on 'change', (e) => @_cache_form_state()
22
+ else
23
+ console.log ':: local storage is not supported ::'
24
+
25
+
26
+ _cache_form_state: ->
27
+ hash = @form.hash()
28
+ json = JSON.stringify(hash)
29
+ localStorage.setItem(@path, json)
30
+
31
+ @$el.addClass 'has-unsaved-changes'
32
+
33
+
34
+ _update_object_from_local_storage: ->
35
+ if typeof(Storage)
36
+ json = localStorage.getItem(@path)
37
+ if json
38
+ hash = JSON.parse(json)
39
+ $.extend(@object, hash)
40
+
41
+ @$el.addClass 'has-unsaved-changes'
42
+
43
+
44
+ _changes_not_saved: ->
45
+ if typeof(Storage)
46
+ # if object is missing localStorage.getItem returns null
47
+ if localStorage.getItem(@path) then true else false
48
+
49
+
50
+ _clear_local_storage_cache: ->
51
+ if typeof(Storage)
52
+ localStorage.removeItem(@path)
53
+
54
+ @$el.removeClass 'has-unsaved-changes'
55
+
56
+
57
+
58
+
@@ -65,7 +65,7 @@ class @ArrayStore
65
65
  @sortBy = @reorderable.positionFieldName
66
66
  @sortReverse = @reorderable.sortReverse ? false
67
67
  else
68
- console.log 'Wrong reordering configuration, missing positionFieldName parameter.'
68
+ console.log ':: wrong reordering configuration, missing positionFieldName parameter ::'
69
69
  @reorderable = false
70
70
 
71
71
 
@@ -113,6 +113,8 @@ class @ArrayStore
113
113
  _add_data_object: (object) ->
114
114
  object = @_normalize_object_id(object)
115
115
 
116
+ # TODO: double check if we still need this
117
+
116
118
  # if object with same id already in the store, update it's parameters,
117
119
  # otherwise add new object (this is used while pagination sync)
118
120
  if ! @_map[object._id]
@@ -0,0 +1,39 @@
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
+ # RAILS ARRAY STORE
11
+ # -----------------------------------------------------------------------------
12
+ #
13
+ # Dependencies:
14
+ #= require ./rails-form-object-parser
15
+ #
16
+ # -----------------------------------------------------------------------------
17
+ class @RailsArrayStore extends RestArrayStore
18
+
19
+ # PRIVATE ===============================================
20
+
21
+ _configure_store: ->
22
+ @ajaxConfig =
23
+ processData: false
24
+ contentType: false
25
+
26
+
27
+ _resource_url: (type, id) ->
28
+ objectPath = if id then "/#{ id }" else ''
29
+ "#{ @config.path }#{ objectPath }.json"
30
+
31
+
32
+ include(RailsArrayStore, railsFormObjectParser)
33
+
34
+
35
+
36
+
37
+
38
+
39
+
@@ -7,25 +7,20 @@
7
7
  # -----------------------------------------------------------------------------
8
8
 
9
9
  # -----------------------------------------------------------------------------
10
- # RAILS OBJECT STORE
10
+ # RAILS FORM OBJECT PARSER
11
+ # -----------------------------------------------------------------------------
12
+ # Get form data object from serialized form object, it uses special format for
13
+ # object names for support of:
14
+ # - files
15
+ # - lists
16
+ # - nested objects
17
+ #
11
18
  # -----------------------------------------------------------------------------
12
- class @MongosteenObjectStore extends RestObjectStore
13
-
14
- # PRIVATE ===============================================
15
-
16
- _configure_store: ->
17
- @ajaxConfig =
18
- processData: false
19
- contentType: false
20
-
21
19
 
22
- # generate rest url for resource
23
- _resource_url: -> "#{ @config.path }.json"
20
+ @railsFormObjectParser =
24
21
 
22
+ # PRIVATE ===============================================
25
23
 
26
- # get form data object from serialized form object,
27
- # it uses special format for object names for support of:
28
- # files, lists, nested objects
29
24
  _parse_form_object: (serializedFormObject) ->
30
25
  formDataObject = new FormData()
31
26
 
@@ -46,8 +41,4 @@ class @MongosteenObjectStore extends RestObjectStore
46
41
 
47
42
  formDataObject.append("#{ @config.resource }#{ attr_name }", attr_value)
48
43
 
49
- return formDataObject
50
-
51
-
52
-
53
-
44
+ return formDataObject
@@ -0,0 +1,35 @@
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
+ # RAILS OBJECT STORE
11
+ # -----------------------------------------------------------------------------
12
+ #
13
+ # Dependencies:
14
+ #= require ./rails-form-object-parser
15
+ #
16
+ # -----------------------------------------------------------------------------
17
+ class @RailsObjectStore extends RestObjectStore
18
+
19
+ # PRIVATE ===============================================
20
+
21
+ _configure_store: ->
22
+ @ajaxConfig =
23
+ processData: false
24
+ contentType: false
25
+
26
+
27
+ _resource_url: ->
28
+ "#{ @config.path }.json"
29
+
30
+
31
+ include(RailsObjectStore, railsFormObjectParser)
32
+
33
+
34
+
35
+
@@ -14,8 +14,6 @@
14
14
  # pagination - enable pagination for resource index, default `true`
15
15
  # searchable - enable resource search, default `false`
16
16
  # urlParams - additional parameter to be included into request
17
- # sortBy - sort objects by field
18
- # sortReverse - reverse sorted objects
19
17
  #
20
18
  # Public methods:
21
19
  # loadObject
@@ -142,8 +140,9 @@ class @RestArrayStore extends ArrayStore
142
140
  callbacks.onSuccess ?= $.noop
143
141
  callbacks.onError ?= $.noop
144
142
 
145
- @_ajax 'GET', id, {}, ((data) =>
146
- callbacks.onSuccess(data)
143
+ @_ajax 'GET', id, null, ((data) =>
144
+ object = @_normalize_object_id(data)
145
+ callbacks.onSuccess(object)
147
146
  ), callbacks.onError
148
147
 
149
148
 
@@ -251,4 +250,3 @@ class @RestArrayStore extends ArrayStore
251
250
 
252
251
 
253
252
 
254
-
@@ -66,7 +66,7 @@ class @RestObjectStore extends ObjectStore
66
66
  callbacks.onSuccess ?= $.noop
67
67
  callbacks.onError ?= $.noop
68
68
 
69
- @_ajax 'GET', {}, ((data) =>
69
+ @_ajax 'GET', null, ((data) =>
70
70
  callbacks.onSuccess(data)
71
71
  ), callbacks.onError
72
72
 
@@ -0,0 +1,30 @@
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
+
@@ -9,6 +9,7 @@
9
9
  # -----------------------------------------------------------------------------
10
10
  # FORM
11
11
  # -----------------------------------------------------------------------------
12
+ #
12
13
  # Generates form based on provided configuration schema. If schema is not
13
14
  # provided generates default form based on object keys. This uses Rails
14
15
  # conventions for managing names for attributes, arrays, hashs and nested
@@ -20,7 +21,7 @@ class @Form
20
21
  constructor: (@object, @config) ->
21
22
  @groups = []
22
23
  @inputs = {}
23
- @$el = $(@config.rootEl || '<form>')
24
+ @$el = $(@config.rootEl || "<form class='form'>")
24
25
  @schema = @_get_schema()
25
26
  @isRemoved = false
26
27
 
@@ -68,6 +69,7 @@ class @Form
68
69
 
69
70
  _build_schema: (schema, $el) ->
70
71
  for fieldName, config of schema
72
+ config.fieldName = fieldName
71
73
  if config.type == 'group'
72
74
  group = @_generate_inputs_group(fieldName, config)
73
75
  $el.append group.$el
@@ -21,7 +21,7 @@ class @InputCheckbox extends InputString
21
21
  # PRIVATE ===============================================
22
22
 
23
23
  _create_el: ->
24
- @$el =$ "<label for='#{ @name }' class='input-#{ @config.type } input-#{ @config.klass } #{ @config.klassName }'>"
24
+ @$el =$ "<label for='#{ @name }' class='input-#{ @config.type } input-#{ @config.klass } input-#{ @config.klassName }'>"
25
25
 
26
26
 
27
27
  _safe_value: ->
@@ -32,6 +32,8 @@ class @InputColor extends InputString
32
32
  # PUBLIC ================================================
33
33
 
34
34
  initialize: ->
35
+ @config.beforeInitialize?(this)
36
+
35
37
  @$input.attr('placeholder', @config.placeholder || 'e.g. #eee')
36
38
 
37
39
  @_add_color_preview()
@@ -9,6 +9,9 @@
9
9
  # -----------------------------------------------------------------------------
10
10
  # INPUT FILE
11
11
  # -----------------------------------------------------------------------------
12
+ # @TODO: add clear button when file is picked for the first time and you want
13
+ # to cancel that pick
14
+ # -----------------------------------------------------------------------------
12
15
  class @InputFile extends InputString
13
16
  constructor: (@name, @value, @config, @object) ->
14
17
  @_create_el()
@@ -16,6 +19,7 @@ class @InputFile extends InputString
16
19
  @_add_label()
17
20
  @_add_input()
18
21
  @_update_state()
22
+ @_add_required()
19
23
 
20
24
  return this
21
25
 
@@ -23,7 +27,7 @@ class @InputFile extends InputString
23
27
  # PRIVATE ===============================================
24
28
 
25
29
  _create_el: ->
26
- @$el =$ "<div class='input-#{ @config.type } input-#{ @config.klass } #{ @config.klassName }'>"
30
+ @$el =$ "<div class='input-#{ @config.type } input-#{ @config.klass } input-#{ @config.klassName }'>"
27
31
 
28
32
 
29
33
  _add_input: ->
@@ -33,9 +37,26 @@ class @InputFile extends InputString
33
37
  @$input =$ "<input type='file' name='#{ @name }' id='#{ @name }'>"
34
38
  @$el.append @$input
35
39
 
40
+ @_add_clear_button()
36
41
  @_add_remove_checkbox()
37
42
 
38
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
+
39
60
  _add_remove_checkbox: ->
40
61
  removeInputName = @removeName()
41
62
  @$removeLabel =$ "<label for='#{ removeInputName }'>Remove</label>"
@@ -81,6 +102,11 @@ class @InputFile extends InputString
81
102
  @_update_state()
82
103
 
83
104
 
105
+ hash: (hash={})->
106
+ # @TODO: file input type does not support caching and versioning as of now
107
+ return hash
108
+
109
+
84
110
  chr.formInputs['file'] = InputFile
85
111
 
86
112
 
@@ -101,6 +127,7 @@ class @InputFileImage extends InputFile
101
127
  @$input =$ "<input type='file' name='#{ @name }' id='#{ @name }' />"
102
128
  @$el.append @$input
103
129
 
130
+ @_add_clear_button()
104
131
  @_add_remove_checkbox()
105
132
 
106
133
 
@@ -45,7 +45,7 @@ class @InputForm
45
45
  # PRIVATE ===============================================
46
46
 
47
47
  _create_el: ->
48
- @$el =$ "<div class='input-stacked nested-forms #{ @config.klassName }'>"
48
+ @$el =$ "<div class='input-stacked nested-forms input-#{ @config.klassName }'>"
49
49
 
50
50
 
51
51
  _add_label: ->
@@ -102,15 +102,17 @@ class @InputForm
102
102
  # PUBLIC ================================================
103
103
 
104
104
  initialize: ->
105
+ @config.beforeInitialize?(this)
106
+
105
107
  for nestedForm in @forms
106
108
  nestedForm.initializePlugins()
107
109
  @config.onInitialize?(this)
108
110
 
109
111
 
110
- hash: (hash={})->
111
- hash[@config.klassName] = []
112
- for form in @forms
113
- hash[@config.klassName].push form.hash()
112
+ hash: (hash={}) ->
113
+ objects = []
114
+ objects.push(form.hash()) for form in @forms
115
+ hash[@config.fieldName] = objects
114
116
  return hash
115
117
 
116
118
 
@@ -137,6 +139,13 @@ class @InputForm
137
139
  @_add_form_reorder_button(form)
138
140
  prevForm = _last(@forms)
139
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
+
140
149
  form.inputs[@config.sortBy].updateValue(position)
141
150
 
142
151
  @forms.push(form)
@@ -24,19 +24,21 @@ class @InputHidden
24
24
 
25
25
  _safe_value: ->
26
26
  if typeof(@value) == 'object'
27
- JSON.stringify(@value)
27
+ return JSON.stringify(@value)
28
28
  else
29
29
  _escapeHtml(@value)
30
30
 
31
31
 
32
32
  # PUBLIC ================================================
33
33
 
34
- initialize: ->
35
- @config.onInitialize?(this)
34
+ showErrorMessage: (message) -> ;
36
35
 
37
36
 
38
- updateValue: (@value) ->
39
- @$el.val(@_safe_value())
37
+ hideErrorMessage: -> ;
38
+
39
+
40
+ initialize: ->
41
+ @config.onInitialize?(this)
40
42
 
41
43
 
42
44
  hash: (hash={}) ->
@@ -44,10 +46,8 @@ class @InputHidden
44
46
  return hash
45
47
 
46
48
 
47
- showErrorMessage: (message) -> ;
48
-
49
-
50
- hideErrorMessage: -> ;
49
+ updateValue: (@value) ->
50
+ @$el.val(@value)
51
51
 
52
52
 
53
53
  chr.formInputs['hidden'] = InputHidden