chr 0.1.4 → 0.1.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/Gruntfile.coffee +22 -21
- data/app/assets/javascripts/chr-dist.js +307 -262
- data/app/assets/javascripts/chr.coffee +22 -21
- data/app/assets/javascripts/chr/core/{_chr.coffee → chr.coffee} +0 -0
- data/app/assets/javascripts/chr/core/{_item.coffee → item.coffee} +2 -2
- data/app/assets/javascripts/chr/core/{_listReorder.coffee → list-reorder.coffee} +1 -1
- data/app/assets/javascripts/chr/core/{_listScroll.coffee → list-scroll.coffee} +1 -1
- data/app/assets/javascripts/chr/core/{_listSearch.coffee → list-search.coffee} +0 -0
- data/app/assets/javascripts/chr/core/{_list.coffee → list.coffee} +2 -0
- 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} +2 -2
- data/app/assets/javascripts/chr/form/{_form.coffee → form.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputCheckbox.coffee → input-checkbox.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputColor.coffee → input-color.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputFile.coffee → input-file.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputHidden.coffee → input-hidden.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputList.coffee → input-list.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputSelect.coffee → input-select.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputString.coffee → input-string.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_inputText.coffee → input-text.coffee} +0 -0
- data/app/assets/javascripts/chr/form/{_nestedForm.coffee → nested-form.coffee} +0 -0
- data/app/assets/javascripts/chr/store/store-mongosteen.coffee +111 -0
- data/app/assets/javascripts/chr/store/store-rest.coffee +90 -0
- data/app/assets/javascripts/chr/store/store.coffee +274 -0
- data/chr.gemspec +2 -2
- data/lib/chr/version.rb +1 -1
- data/package.json +1 -1
- metadata +26 -25
- data/app/assets/javascripts/chr/store/_store.coffee +0 -104
- data/app/assets/javascripts/chr/store/_storeRails.coffee +0 -167
data/chr.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.summary = 'A simple and lightweight library for building data management web apps'
|
14
14
|
s.description = <<-DESC
|
15
15
|
Character is a library written in CoffeeScript with a help of jQuery that allows to
|
16
|
-
build data management web applications
|
17
|
-
|
16
|
+
build data management web applications in a fast and flexible way, e.g. CMS, news reader,
|
17
|
+
email client etc. It's responsive by default and designed to be data source independent.
|
18
18
|
DESC
|
19
19
|
|
20
20
|
s.rubyforge_project = 'chr'
|
data/lib/chr/version.rb
CHANGED
data/package.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kravets
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bourbon
|
@@ -54,8 +54,8 @@ dependencies:
|
|
54
54
|
version: '3.0'
|
55
55
|
description: |
|
56
56
|
Character is a library written in CoffeeScript with a help of jQuery that allows to
|
57
|
-
build data management web applications
|
58
|
-
|
57
|
+
build data management web applications in a fast and flexible way, e.g. CMS, news reader,
|
58
|
+
email client etc. It's responsive by default and designed to be data source independent.
|
59
59
|
email: alex@slatestudio.com
|
60
60
|
executables: []
|
61
61
|
extensions: []
|
@@ -70,27 +70,28 @@ files:
|
|
70
70
|
- Rakefile
|
71
71
|
- app/assets/javascripts/chr-dist.js
|
72
72
|
- app/assets/javascripts/chr.coffee
|
73
|
-
- app/assets/javascripts/chr/core/
|
74
|
-
- app/assets/javascripts/chr/core/
|
75
|
-
- app/assets/javascripts/chr/core/
|
76
|
-
- app/assets/javascripts/chr/core/
|
77
|
-
- app/assets/javascripts/chr/core/
|
78
|
-
- app/assets/javascripts/chr/core/
|
79
|
-
- app/assets/javascripts/chr/core/
|
80
|
-
- app/assets/javascripts/chr/core/
|
81
|
-
- app/assets/javascripts/chr/core/
|
82
|
-
- app/assets/javascripts/chr/form/
|
83
|
-
- app/assets/javascripts/chr/form/
|
84
|
-
- app/assets/javascripts/chr/form/
|
85
|
-
- app/assets/javascripts/chr/form/
|
86
|
-
- app/assets/javascripts/chr/form/
|
87
|
-
- app/assets/javascripts/chr/form/
|
88
|
-
- app/assets/javascripts/chr/form/
|
89
|
-
- app/assets/javascripts/chr/form/
|
90
|
-
- app/assets/javascripts/chr/form/
|
91
|
-
- app/assets/javascripts/chr/form/
|
92
|
-
- app/assets/javascripts/chr/store/
|
93
|
-
- app/assets/javascripts/chr/store/
|
73
|
+
- app/assets/javascripts/chr/core/chr.coffee
|
74
|
+
- app/assets/javascripts/chr/core/item.coffee
|
75
|
+
- app/assets/javascripts/chr/core/list-reorder.coffee
|
76
|
+
- app/assets/javascripts/chr/core/list-scroll.coffee
|
77
|
+
- app/assets/javascripts/chr/core/list-search.coffee
|
78
|
+
- app/assets/javascripts/chr/core/list.coffee
|
79
|
+
- app/assets/javascripts/chr/core/module.coffee
|
80
|
+
- app/assets/javascripts/chr/core/utils.coffee
|
81
|
+
- app/assets/javascripts/chr/core/view.coffee
|
82
|
+
- app/assets/javascripts/chr/form/form.coffee
|
83
|
+
- app/assets/javascripts/chr/form/input-checkbox.coffee
|
84
|
+
- app/assets/javascripts/chr/form/input-color.coffee
|
85
|
+
- app/assets/javascripts/chr/form/input-file.coffee
|
86
|
+
- app/assets/javascripts/chr/form/input-hidden.coffee
|
87
|
+
- app/assets/javascripts/chr/form/input-list.coffee
|
88
|
+
- app/assets/javascripts/chr/form/input-select.coffee
|
89
|
+
- app/assets/javascripts/chr/form/input-string.coffee
|
90
|
+
- app/assets/javascripts/chr/form/input-text.coffee
|
91
|
+
- app/assets/javascripts/chr/form/nested-form.coffee
|
92
|
+
- app/assets/javascripts/chr/store/store-mongosteen.coffee
|
93
|
+
- app/assets/javascripts/chr/store/store-rest.coffee
|
94
|
+
- app/assets/javascripts/chr/store/store.coffee
|
94
95
|
- app/assets/javascripts/chr/vendor/jquery.scrollparent.js
|
95
96
|
- app/assets/javascripts/chr/vendor/jquery.textarea_autosize.js
|
96
97
|
- app/assets/javascripts/chr/vendor/jquery.typeahead.js
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
# OBJECT STORE
|
3
|
-
# -----------------------------------------------------------------------------
|
4
|
-
class @ObjectStore
|
5
|
-
constructor: (@config={}) ->
|
6
|
-
@_initializeDatabase()
|
7
|
-
|
8
|
-
_fetchData: ->
|
9
|
-
@_data = @config.data
|
10
|
-
|
11
|
-
_initializeDatabase: ->
|
12
|
-
@_fetchData()
|
13
|
-
|
14
|
-
get: ->
|
15
|
-
@_data
|
16
|
-
|
17
|
-
_updateDataObject: (value, callback) ->
|
18
|
-
callback?($.extend(@_data, value))
|
19
|
-
|
20
|
-
update: (id, value, callback) ->
|
21
|
-
@_updateDataObject(value, callback)
|
22
|
-
|
23
|
-
|
24
|
-
# -----------------------------------------------------------------------------
|
25
|
-
# ARRAY STORE
|
26
|
-
# -----------------------------------------------------------------------------
|
27
|
-
class @ArrayStore
|
28
|
-
_sortData: ->
|
29
|
-
# http://stackoverflow.com/questions/9796764/how-do-i-sort-an-array-with-coffeescript
|
30
|
-
if @sortBy
|
31
|
-
fieldName = @sortBy
|
32
|
-
direction = if @sortReverse then 1 else -1
|
33
|
-
|
34
|
-
sortBy = (key, a, b, dir) ->
|
35
|
-
if a[key] > b[key] then return -1*dir
|
36
|
-
if a[key] < b[key] then return +1*dir
|
37
|
-
return 0
|
38
|
-
|
39
|
-
@_data = @_data.sort (a, b) -> sortBy(fieldName, a, b, direction)
|
40
|
-
|
41
|
-
_mapData: ->
|
42
|
-
( @_map[o._id] = o for o in @_data )
|
43
|
-
|
44
|
-
_addDataObject: (object, callback)->
|
45
|
-
@_map[object._id] = object
|
46
|
-
@_data.push(object)
|
47
|
-
@_sortData()
|
48
|
-
position = @_getDataObjectPosition(object._id)
|
49
|
-
$(this).trigger('object_added', { object: object, position: position, callback: callback })
|
50
|
-
|
51
|
-
_resetData: ->
|
52
|
-
for id, o of @_map
|
53
|
-
$(this).trigger('object_removed', { object_id: id })
|
54
|
-
@_map = {}
|
55
|
-
@_data = []
|
56
|
-
|
57
|
-
_removeDataObject: (id) ->
|
58
|
-
position = @_getDataObjectPosition(id)
|
59
|
-
if position >= 0
|
60
|
-
delete @_data[position]
|
61
|
-
delete @_map[id]
|
62
|
-
$(this).trigger('object_removed', { object_id: id })
|
63
|
-
|
64
|
-
_updateDataObject: (id, value, callback) ->
|
65
|
-
object = $.extend(@get(id), value)
|
66
|
-
@_sortData()
|
67
|
-
position = @_getDataObjectPosition(id)
|
68
|
-
$(this).trigger('object_changed', { object: object, position: position, callback: callback })
|
69
|
-
|
70
|
-
_getDataObjectPosition: (id) ->
|
71
|
-
ids = []
|
72
|
-
for o in @_data
|
73
|
-
if o then ids.push(o._id)
|
74
|
-
$.inArray id, ids
|
75
|
-
|
76
|
-
constructor: (@config={}) ->
|
77
|
-
@_map = {}
|
78
|
-
@_data = []
|
79
|
-
@_initializeDatabase()
|
80
|
-
|
81
|
-
_initializeDatabase: ->
|
82
|
-
|
83
|
-
off: (eventType) ->
|
84
|
-
if eventType then $(this).off(eventType) else $(this).off()
|
85
|
-
|
86
|
-
on: (eventType, callback) -> # event types: object_added, object_changed, object_removed
|
87
|
-
$(this).on eventType, (e, data) -> callback(e, data)
|
88
|
-
# NOTE: this called once when list subscribes to store updates
|
89
|
-
if eventType == 'object_added' then @_fetchData()
|
90
|
-
|
91
|
-
_fetchData: ->
|
92
|
-
if @config.data
|
93
|
-
@_addDataObject(o) for o in @config.data
|
94
|
-
|
95
|
-
get: (id) -> @_map[id]
|
96
|
-
|
97
|
-
update: (id, value, callback) ->
|
98
|
-
@_updateDataObject(id, value, callback)
|
99
|
-
|
100
|
-
push: (value, callback) ->
|
101
|
-
@_addDataObject($.extend({ _id: Date.now() }, value), callback)
|
102
|
-
|
103
|
-
remove: (id) ->
|
104
|
-
@_removeDataObject(id)
|
@@ -1,167 +0,0 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
# RAILS OBJECT STORE IMPLEMENTATION
|
3
|
-
# -----------------------------------------------------------------------------
|
4
|
-
class @RailsObjectStore extends ObjectStore
|
5
|
-
# _initializeDatabase: ->
|
6
|
-
# @database = new Firebase("https://#{ @config.dbName }.firebaseio.com/")
|
7
|
-
# @dataRef = @database.child(@config.path)
|
8
|
-
# @_fetchData()
|
9
|
-
|
10
|
-
# _fetchData: ->
|
11
|
-
# @dataRef.once 'value', (dataSnapshot) =>
|
12
|
-
# @_data = dataSnapshot.val() ? {}
|
13
|
-
|
14
|
-
# update: (id, value, callback) ->
|
15
|
-
# @dataRef.set value, => @_updateDataObject(value, callback)
|
16
|
-
|
17
|
-
|
18
|
-
# -----------------------------------------------------------------------------
|
19
|
-
# RAILS ARRAY/COLLECTION STORE IMPLEMENTATION
|
20
|
-
# -----------------------------------------------------------------------------
|
21
|
-
class @RailsArrayStore extends ArrayStore
|
22
|
-
_initializeDatabase: ->
|
23
|
-
@resetData = false
|
24
|
-
@searchable = @config.searchable ? false
|
25
|
-
@pagination = @config.pagination ? true
|
26
|
-
@reorderable = @config.reorderable ? false
|
27
|
-
@dataFetchLock = false
|
28
|
-
@pagesCounter = 0
|
29
|
-
@searchQuery = ''
|
30
|
-
|
31
|
-
# if reorderable we need to set proper config for sorting
|
32
|
-
if @reorderable
|
33
|
-
@sortBy = @reorderable.positionFieldName
|
34
|
-
@sortReverse = @reorderable.sortReverse || false
|
35
|
-
|
36
|
-
# bootstraped data provided
|
37
|
-
if @config.data
|
38
|
-
@pagesCounter = 1
|
39
|
-
|
40
|
-
_addDataObjectToTheTop: (object, callback) ->
|
41
|
-
@_map[object._id] = object
|
42
|
-
@_data.unshift(object)
|
43
|
-
position = 0
|
44
|
-
$(this).trigger('object_added', { object: object, position: position, callback: callback })
|
45
|
-
|
46
|
-
_wrapRailsObject: (object) ->
|
47
|
-
# NOTE: generate form data object
|
48
|
-
data = new FormData()
|
49
|
-
for attr_name, attr_value of object
|
50
|
-
# NOTE: special case for LIST inputs, values separated with comma
|
51
|
-
if attr_name.indexOf('[__LIST__') > -1
|
52
|
-
attr_name = attr_name.replace('__LIST__', '')
|
53
|
-
values = attr_value.split(',')
|
54
|
-
for value in values
|
55
|
-
data.append("#{ @config.resource }#{ attr_name }[]", value)
|
56
|
-
else
|
57
|
-
# NOTE: special case for FILE inputs
|
58
|
-
if attr_name.startsWith('__FILE__')
|
59
|
-
attr_name = attr_name.replace('__FILE__', '')
|
60
|
-
|
61
|
-
data.append("#{ @config.resource }#{ attr_name }", attr_value)
|
62
|
-
return data
|
63
|
-
|
64
|
-
_urlWithParams: (url) ->
|
65
|
-
if @config.urlParams
|
66
|
-
extraParamString = $.param(@config.urlParams)
|
67
|
-
if url.indexOf('?') > 0
|
68
|
-
url = "#{ url }&#{ extraParamString }"
|
69
|
-
else
|
70
|
-
url = "#{ url }?#{ extraParamString }"
|
71
|
-
return url
|
72
|
-
|
73
|
-
_delete: (id, success) ->
|
74
|
-
@dataFetchLock = true
|
75
|
-
$.ajax
|
76
|
-
type: 'DELETE'
|
77
|
-
url: @_urlWithParams("#{ @config.path }/#{ id }.json")
|
78
|
-
success: (data, textStatus, jqXHR) =>
|
79
|
-
@dataFetchLock = false
|
80
|
-
success?(data)
|
81
|
-
|
82
|
-
_post: (object, success, error) ->
|
83
|
-
@dataFetchLock = true
|
84
|
-
$.ajax
|
85
|
-
type: 'POST'
|
86
|
-
url: @_urlWithParams("#{ @config.path }.json")
|
87
|
-
data: @_wrapRailsObject(object)
|
88
|
-
processData: false
|
89
|
-
contentType: false
|
90
|
-
success: (data, textStatus, jqXHR) =>
|
91
|
-
@dataFetchLock = false
|
92
|
-
success?(data)
|
93
|
-
error: (jqXHR, textStatus, errorThrown ) =>
|
94
|
-
@dataFetchLock = false
|
95
|
-
error?(jqXHR.responseJSON)
|
96
|
-
|
97
|
-
_put: (id, object, success, error) ->
|
98
|
-
@dataFetchLock = true
|
99
|
-
$.ajax
|
100
|
-
type: 'PUT'
|
101
|
-
url: @_urlWithParams("#{ @config.path }/#{ id }.json")
|
102
|
-
data: @_wrapRailsObject(object)
|
103
|
-
processData: false
|
104
|
-
contentType: false
|
105
|
-
success: (data, textStatus, jqXHR) =>
|
106
|
-
@dataFetchLock = false
|
107
|
-
success?(data)
|
108
|
-
error: (jqXHR, textStatus, errorThrown ) =>
|
109
|
-
@dataFetchLock = false
|
110
|
-
error?(jqXHR.responseJSON)
|
111
|
-
|
112
|
-
_get: (params, success) ->
|
113
|
-
@dataFetchLock = true
|
114
|
-
$.get @_urlWithParams("#{ @config.path }.json"), params, (data) =>
|
115
|
-
if data.length > 0
|
116
|
-
@pagesCounter = @pagesCounter + 1
|
117
|
-
for o in data
|
118
|
-
@_addDataObject(o)
|
119
|
-
|
120
|
-
@dataFetchLock = false
|
121
|
-
success?()
|
122
|
-
$(this).trigger('objects_added')
|
123
|
-
|
124
|
-
#
|
125
|
-
# PUBLIC
|
126
|
-
#
|
127
|
-
|
128
|
-
fetchNextPage: (callback) ->
|
129
|
-
params = {}
|
130
|
-
if @pagination
|
131
|
-
params.page = @pagesCounter + 1
|
132
|
-
params.perPage = _itemsPerPageRequest
|
133
|
-
if @searchQuery.length > 0
|
134
|
-
params.search = @searchQuery
|
135
|
-
@_get(params)
|
136
|
-
|
137
|
-
search: (@searchQuery, callback) ->
|
138
|
-
@pagesCounter = 0
|
139
|
-
@_resetData()
|
140
|
-
@fetchNextPage(callback)
|
141
|
-
|
142
|
-
reset: (callback) ->
|
143
|
-
@searchQuery = ''
|
144
|
-
@pagesCounter = 0
|
145
|
-
@_resetData()
|
146
|
-
@fetchNextPage(callback)
|
147
|
-
|
148
|
-
update: (id, object, callbacks) ->
|
149
|
-
@_put id, object, ((data) =>
|
150
|
-
@_updateDataObject(id, data, callbacks.onSuccess)
|
151
|
-
), callbacks.onError
|
152
|
-
|
153
|
-
push: (object, callbacks) ->
|
154
|
-
@_post object, ((data) =>
|
155
|
-
if @config.sortBy
|
156
|
-
@_addDataObject(data, callbacks.onSuccess)
|
157
|
-
else
|
158
|
-
@_addDataObjectToTheTop(data, callbacks.onSuccess)
|
159
|
-
), callbacks.onError
|
160
|
-
|
161
|
-
remove: (id) ->
|
162
|
-
@_delete id, (data) =>
|
163
|
-
@_removeDataObject(id)
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|