chr 0.2.1 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gruntfile.coffee +50 -16
- data/app/assets/javascripts/chr.coffee +9 -16
- data/app/assets/javascripts/chr/core/chr.coffee +38 -20
- data/app/assets/javascripts/chr/core/item.coffee +30 -24
- data/app/assets/javascripts/chr/core/list.coffee +30 -60
- data/app/assets/javascripts/chr/core/list_config.coffee +65 -0
- data/app/assets/javascripts/chr/core/list_pagination.coffee +27 -0
- data/app/assets/javascripts/chr/core/list_reorder.coffee +75 -0
- data/app/assets/javascripts/chr/core/list_search.coffee +41 -0
- data/app/assets/javascripts/chr/core/module.coffee +55 -32
- data/app/assets/javascripts/chr/core/utils.coffee +34 -13
- data/app/assets/javascripts/chr/core/view.coffee +70 -97
- data/app/assets/javascripts/chr/form/form.coffee +63 -49
- data/app/assets/javascripts/chr/form/input-checkbox.coffee +40 -27
- data/app/assets/javascripts/chr/form/input-color.coffee +26 -8
- data/app/assets/javascripts/chr/form/input-date.coffee +0 -0
- data/app/assets/javascripts/chr/form/input-file.coffee +81 -46
- data/app/assets/javascripts/chr/form/input-form.coffee +162 -0
- data/app/assets/javascripts/chr/form/input-form_reorder.coffee +67 -0
- data/app/assets/javascripts/chr/form/input-hidden.coffee +27 -11
- data/app/assets/javascripts/chr/form/input-list.coffee +60 -56
- data/app/assets/javascripts/chr/form/input-list_reorder.coffee +37 -0
- data/app/assets/javascripts/chr/form/input-password.coffee +31 -0
- data/app/assets/javascripts/chr/form/input-select.coffee +61 -35
- data/app/assets/javascripts/chr/form/input-string.coffee +55 -25
- data/app/assets/javascripts/chr/form/input-text.coffee +22 -5
- data/app/assets/javascripts/chr/store/mongosteen-array-store.coffee +1 -1
- data/app/assets/javascripts/chr/vendor/ace.js +18280 -0
- data/app/assets/javascripts/chr/vendor/marked.js +1272 -0
- data/app/assets/javascripts/chr/vendor/mode-html.js +2436 -0
- data/app/assets/javascripts/chr/vendor/mode-markdown.js +2820 -0
- data/app/assets/javascripts/chr/vendor/redactor.fixedtoolbar.js +110 -0
- data/app/assets/javascripts/input-html.coffee +78 -0
- data/app/assets/javascripts/input-markdown.coffee +88 -0
- data/app/assets/javascripts/input-redactor.coffee +66 -0
- data/app/assets/stylesheets/_chr.scss +6 -6
- data/app/assets/stylesheets/_input-redactor.scss +34 -0
- data/app/assets/stylesheets/core/_mixins.scss +75 -0
- data/app/assets/stylesheets/form/_input-checkbox.scss +18 -0
- data/app/assets/stylesheets/form/{_input_color.scss → _input-color.scss} +0 -0
- data/app/assets/stylesheets/form/{_input_file.scss → _input-file.scss} +1 -0
- data/app/assets/stylesheets/form/{_nested_form.scss → _input-form.scss} +0 -0
- data/app/assets/stylesheets/form/{_input_list.scss → _input-list.scss} +0 -0
- data/app/assets/stylesheets/form/_input-string.scss +8 -0
- data/bower.json +3 -2
- data/{app/assets/javascripts/chr-dist.js → dist/chr.js} +1472 -1337
- data/dist/input-ace.js +24936 -0
- data/dist/input-redactor.js +156 -0
- data/lib/chr/version.rb +1 -1
- data/package.json +2 -2
- metadata +29 -13
- data/app/assets/javascripts/chr/core/list-pagination.coffee +0 -26
- data/app/assets/javascripts/chr/core/list-reorder.coffee +0 -70
- data/app/assets/javascripts/chr/core/list-search.coffee +0 -37
- data/app/assets/javascripts/chr/form/nested-form.coffee +0 -164
- data/app/assets/stylesheets/form/_input_checkbox.scss +0 -91
- data/app/assets/stylesheets/form/_input_string.scss +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e8a41bc74d5c9663f0f5d10ac550ada054fe57
|
4
|
+
data.tar.gz: cf8bb324690c3c73033768e2683cb2270fed88f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15adb4c217afc3aeb3c8af54f251fb7d7e358490607c2cd67643a2f67b9221001caef951abf4541d3df7621fc85eaeed4d7ec6d987c43a9e8a4a11fc99a10bdd
|
7
|
+
data.tar.gz: 58ce4a8966c8c7408f57fe5f0fb9f7df2a9898e21f5c120014cb4e4bfea1f0b4d9cb5832ef249ee72f07b9ebf0ba62982e4926485f515755ec30071358da2c03
|
data/.gitignore
CHANGED
data/Gruntfile.coffee
CHANGED
@@ -8,39 +8,52 @@ module.exports = (grunt) ->
|
|
8
8
|
bare: true
|
9
9
|
files:
|
10
10
|
'build/chr.js': [
|
11
|
-
#
|
12
|
-
'app/assets/javascripts/chr/core/
|
11
|
+
# core
|
12
|
+
'app/assets/javascripts/chr/core/utils.coffee'
|
13
|
+
'app/assets/javascripts/chr/core/chr.coffee'
|
14
|
+
'app/assets/javascripts/chr/core/module.coffee'
|
15
|
+
'app/assets/javascripts/chr/core/list_config.coffee'
|
16
|
+
'app/assets/javascripts/chr/core/list_pagination.coffee'
|
17
|
+
'app/assets/javascripts/chr/core/list_reorder.coffee'
|
18
|
+
'app/assets/javascripts/chr/core/list_search.coffee'
|
13
19
|
'app/assets/javascripts/chr/core/list.coffee'
|
14
|
-
'app/assets/javascripts/chr/core/
|
15
|
-
'app/assets/javascripts/chr/core/list-scroll.coffee'
|
16
|
-
'app/assets/javascripts/chr/core/list-reorder.coffee'
|
20
|
+
'app/assets/javascripts/chr/core/item.coffee'
|
17
21
|
'app/assets/javascripts/chr/core/view.coffee'
|
18
|
-
|
19
|
-
#
|
22
|
+
# form
|
20
23
|
'app/assets/javascripts/chr/form/form.coffee'
|
24
|
+
'app/assets/javascripts/chr/form/input-form_reorder.coffee'
|
25
|
+
'app/assets/javascripts/chr/form/input-form.coffee'
|
21
26
|
'app/assets/javascripts/chr/form/input-string.coffee'
|
27
|
+
'app/assets/javascripts/chr/form/input-hidden.coffee'
|
22
28
|
'app/assets/javascripts/chr/form/input-checkbox.coffee'
|
23
29
|
'app/assets/javascripts/chr/form/input-color.coffee'
|
30
|
+
'app/assets/javascripts/chr/form/input-date.coffee'
|
24
31
|
'app/assets/javascripts/chr/form/input-file.coffee'
|
25
|
-
'app/assets/javascripts/chr/form/input-
|
32
|
+
'app/assets/javascripts/chr/form/input-list_reorder.coffee'
|
26
33
|
'app/assets/javascripts/chr/form/input-list.coffee'
|
34
|
+
'app/assets/javascripts/chr/form/input-password.coffee'
|
27
35
|
'app/assets/javascripts/chr/form/input-select.coffee'
|
28
36
|
'app/assets/javascripts/chr/form/input-text.coffee'
|
29
|
-
|
30
|
-
#
|
37
|
+
# stores
|
31
38
|
'app/assets/javascripts/chr/store/_array-store.coffee'
|
32
39
|
'app/assets/javascripts/chr/store/_object-store.coffee'
|
33
40
|
'app/assets/javascripts/chr/store/rest-array-store.coffee'
|
34
41
|
'app/assets/javascripts/chr/store/rest-object-store.coffee'
|
35
42
|
'app/assets/javascripts/chr/store/mongosteen-array-store.coffee'
|
36
43
|
'app/assets/javascripts/chr/store/mongosteen-object-store.coffee'
|
37
|
-
|
38
|
-
|
39
|
-
|
44
|
+
]
|
45
|
+
|
46
|
+
'build/input-ace.js': [
|
47
|
+
'app/assets/javascripts/input-html.coffee'
|
48
|
+
'app/assets/javascripts/input-markdown.coffee'
|
49
|
+
]
|
50
|
+
|
51
|
+
'build/input-redactor.js': [
|
52
|
+
'app/assets/javascripts/input-redactor.coffee'
|
40
53
|
]
|
41
54
|
|
42
55
|
concat:
|
43
|
-
|
56
|
+
chr:
|
44
57
|
src: [
|
45
58
|
'app/assets/javascripts/chr/vendor/slip.js'
|
46
59
|
'app/assets/javascripts/chr/vendor/jquery.scrollparent.js'
|
@@ -48,7 +61,24 @@ module.exports = (grunt) ->
|
|
48
61
|
'app/assets/javascripts/chr/vendor/jquery.typeahead.js'
|
49
62
|
'build/chr.js'
|
50
63
|
]
|
51
|
-
dest: '
|
64
|
+
dest: 'dist/chr.js'
|
65
|
+
|
66
|
+
ace:
|
67
|
+
src: [
|
68
|
+
'app/assets/javascripts/chr/vendor/ace.js'
|
69
|
+
'app/assets/javascripts/chr/vendor/mode-html.js'
|
70
|
+
'app/assets/javascripts/chr/vendor/mode-markdown.js'
|
71
|
+
'app/assets/javascripts/chr/vendor/marked.js'
|
72
|
+
'build/input-ace.js'
|
73
|
+
]
|
74
|
+
dest: 'dist/input-ace.js'
|
75
|
+
|
76
|
+
redactor:
|
77
|
+
src: [
|
78
|
+
'app/assets/javascripts/chr/vendor/redactor.fixedtoolbar.js'
|
79
|
+
'build/input-redactor.js'
|
80
|
+
]
|
81
|
+
dest: 'dist/input-redactor.js'
|
52
82
|
|
53
83
|
clean: [
|
54
84
|
'build'
|
@@ -58,4 +88,8 @@ module.exports = (grunt) ->
|
|
58
88
|
grunt.loadNpmTasks('grunt-contrib-concat')
|
59
89
|
grunt.loadNpmTasks('grunt-contrib-clean')
|
60
90
|
|
61
|
-
grunt.registerTask('default', ['coffee', 'concat', 'clean'])
|
91
|
+
grunt.registerTask('default', ['coffee', 'concat', 'clean'])
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
@@ -1,33 +1,26 @@
|
|
1
|
-
#= require ./chr/
|
2
|
-
#= require ./chr/
|
3
|
-
#= require ./chr/vendor/jquery.typeahead
|
4
|
-
#= require ./chr/vendor/slip
|
1
|
+
#= require ./chr/core/utils
|
2
|
+
#= require ./chr/core/chr
|
5
3
|
|
6
|
-
#= require ./chr/core/
|
4
|
+
#= require ./chr/core/module
|
7
5
|
#= require ./chr/core/list
|
8
|
-
#= require ./chr/core/
|
9
|
-
#= require ./chr/core/list-pagination
|
10
|
-
#= require ./chr/core/list-reorder
|
6
|
+
#= require ./chr/core/item
|
11
7
|
#= require ./chr/core/view
|
12
|
-
#= require ./chr/core/module
|
13
8
|
|
14
9
|
#= require ./chr/form/form
|
10
|
+
#= require ./chr/form/input-form
|
11
|
+
#= require ./chr/form/input-hidden
|
15
12
|
#= require ./chr/form/input-string
|
13
|
+
#= require ./chr/form/input-text
|
16
14
|
#= require ./chr/form/input-checkbox
|
15
|
+
#= require ./chr/form/input-password
|
17
16
|
#= require ./chr/form/input-color
|
18
17
|
#= require ./chr/form/input-file
|
19
|
-
#= require ./chr/form/input-hidden
|
20
18
|
#= require ./chr/form/input-list
|
21
19
|
#= require ./chr/form/input-select
|
22
|
-
#= require ./chr/form/input-text
|
23
|
-
#= require ./chr/form/nested-form
|
24
20
|
|
25
21
|
#= require ./chr/store/_object-store
|
26
22
|
#= require ./chr/store/_array-store
|
27
23
|
#= require ./chr/store/rest-object-store
|
28
24
|
#= require ./chr/store/rest-array-store
|
29
25
|
#= require ./chr/store/mongosteen-object-store
|
30
|
-
#= require ./chr/store/mongosteen-array-store
|
31
|
-
|
32
|
-
#= require ./chr/core/utils
|
33
|
-
#= require ./chr/core/chr
|
26
|
+
#= require ./chr/store/mongosteen-array-store
|
@@ -8,25 +8,34 @@
|
|
8
8
|
|
9
9
|
# -----------------------------------------------------------------------------
|
10
10
|
# CHARACTER
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# Public attributes:
|
13
|
+
# modules
|
14
|
+
# formInputs
|
15
|
+
# itemsPerPageRequest
|
11
16
|
#
|
12
|
-
#
|
17
|
+
# Public methods:
|
13
18
|
# start(@config) - start the character app with configuration
|
14
19
|
# addMenuItem(moduleName, title) - add item to main menu
|
15
20
|
# showAlert(message) - show alert notification
|
16
21
|
# showError(message) - show error message
|
22
|
+
# isMobile() - check if running on mobile
|
23
|
+
# unsetActiveListItems() - clear selection from all list items
|
24
|
+
# updateHash(hash, skipHashChange=false)
|
17
25
|
#
|
18
26
|
# -----------------------------------------------------------------------------
|
19
27
|
class @Chr
|
20
28
|
constructor: ->
|
21
|
-
@
|
29
|
+
@formInputs = {}
|
30
|
+
@modules = {}
|
22
31
|
|
32
|
+
@itemsPerPageRequest = Math.ceil($(window).height() / 60) * 2
|
23
33
|
|
24
|
-
_unset_active_menu_items: ->
|
25
|
-
$('.sidebar .menu a.active').removeClass('active')
|
26
34
|
|
35
|
+
# PRIVATE ===============================================
|
27
36
|
|
28
|
-
|
29
|
-
$('.
|
37
|
+
_unset_active_menu_items: ->
|
38
|
+
$('.sidebar .menu a.active').removeClass('active')
|
30
39
|
|
31
40
|
|
32
41
|
_set_active_menu_item: ->
|
@@ -37,8 +46,6 @@ class @Chr
|
|
37
46
|
return $(a).addClass('active')
|
38
47
|
|
39
48
|
|
40
|
-
# TODO: this piece of navigation code isn't clear, need to refactor to make
|
41
|
-
# it more readable
|
42
49
|
_navigate: (path) -> #/<module>[/<list>][/new]OR[/view/<objectId>]
|
43
50
|
crumbs = path.split('/')
|
44
51
|
|
@@ -57,7 +64,6 @@ class @Chr
|
|
57
64
|
if crumbs.length > 0
|
58
65
|
for crumb in crumbs
|
59
66
|
if crumb == 'new'
|
60
|
-
# TODO: reset list data — why?
|
61
67
|
return @module.showView(null, config, 'New')
|
62
68
|
|
63
69
|
if crumb == 'view'
|
@@ -72,10 +78,22 @@ class @Chr
|
|
72
78
|
else
|
73
79
|
@module.showNestedList(crumb)
|
74
80
|
else
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
81
|
+
@module.showRootList()
|
82
|
+
|
83
|
+
|
84
|
+
# PUBLIC ================================================
|
85
|
+
|
86
|
+
unsetActiveListItems: ->
|
87
|
+
$('.list .items .item.active').removeClass('active')
|
88
|
+
|
89
|
+
|
90
|
+
isMobile: ->
|
91
|
+
$(window).width() < 760
|
92
|
+
|
93
|
+
|
94
|
+
updateHash: (hash, skipHashChange=false) ->
|
95
|
+
window._skipHashchange = skipHashChange
|
96
|
+
location.hash = hash
|
79
97
|
|
80
98
|
|
81
99
|
start: (@config) ->
|
@@ -94,8 +112,8 @@ class @Chr
|
|
94
112
|
@_unset_active_menu_items()
|
95
113
|
@unsetActiveListItems()
|
96
114
|
|
97
|
-
# this
|
98
|
-
#
|
115
|
+
# this allows to skip chr _navigate method for silent hashchanges,
|
116
|
+
# e.g. close view event
|
99
117
|
if not window._skipHashchange then @_navigate(location.hash)
|
100
118
|
window._skipHashchange = false
|
101
119
|
|
@@ -109,11 +127,11 @@ class @Chr
|
|
109
127
|
# if not mobile navigate on first page load or page refresh
|
110
128
|
window._skipHashchange = false
|
111
129
|
|
112
|
-
# if hash is not empty go to
|
130
|
+
# if hash is not empty go to module
|
113
131
|
if location.hash != ''
|
114
132
|
@_navigate(location.hash)
|
115
|
-
$(this).trigger
|
116
|
-
else if !
|
133
|
+
$(this).trigger('hashchange')
|
134
|
+
else if ! @isMobile()
|
117
135
|
# if on desktop/tablet while hash is empty go to first module in the list
|
118
136
|
location.hash = '#/' + Object.keys(@modules)[0]
|
119
137
|
|
@@ -127,11 +145,11 @@ class @Chr
|
|
127
145
|
|
128
146
|
|
129
147
|
showError: (message) ->
|
130
|
-
|
148
|
+
alert 'Error: ' + message
|
131
149
|
|
132
150
|
|
133
151
|
# -----------------------------------------------------------------------------
|
134
|
-
#
|
152
|
+
# Initialize `chr` object in global scope
|
135
153
|
# -----------------------------------------------------------------------------
|
136
154
|
window.chr = new Chr()
|
137
155
|
|
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
# -----------------------------------------------------------------------------
|
10
10
|
# LIST ITEM
|
11
|
-
#
|
11
|
+
# -----------------------------------------------------------------------------
|
12
12
|
# public methods:
|
13
13
|
# render()
|
14
14
|
# destroy()
|
@@ -18,29 +18,11 @@
|
|
18
18
|
class @Item
|
19
19
|
constructor: (@module, @path, @object, @config) ->
|
20
20
|
@$el =$ """<a class='item' href='#{ @path }' data-id='#{ @object._id }' data-title=''></a>"""
|
21
|
-
@$el.on 'click', (e) => @
|
21
|
+
@$el.on 'click', (e) => @_click(e)
|
22
22
|
@render()
|
23
23
|
|
24
24
|
|
25
|
-
|
26
|
-
if @.$el.hasClass('active') then e.preventDefault() ; return
|
27
|
-
|
28
|
-
window._skipHashchange = true
|
29
|
-
location.hash = $(e.currentTarget).attr('href')
|
30
|
-
|
31
|
-
title = $(e.currentTarget).attr('data-title')
|
32
|
-
id = $(e.currentTarget).attr('data-id')
|
33
|
-
crumbs = location.href.split('/')
|
34
|
-
|
35
|
-
# view for a arrayStore item
|
36
|
-
if crumbs[crumbs.length - 2] == 'view'
|
37
|
-
return @module.showViewByObjectId(id, @config, title, true)
|
38
|
-
|
39
|
-
if @config.objectStore
|
40
|
-
return @module.showViewByObjectId('', @config, title, true)
|
41
|
-
|
42
|
-
@module.showNestedList(_last(crumbs), true)
|
43
|
-
|
25
|
+
# PRIVATE ===============================================
|
44
26
|
|
45
27
|
_is_folder: ->
|
46
28
|
# update this logic as it's not reliable
|
@@ -52,11 +34,11 @@ class @Item
|
|
52
34
|
title ?= @object[@config.itemTitleField] # based on config
|
53
35
|
title ?= _firstNonEmptyValue(@object) # auto-generated: first non empty value
|
54
36
|
title ?= "No Title"
|
55
|
-
title =
|
37
|
+
title = title.plainText()
|
56
38
|
|
57
|
-
@$title =$ "<div class='item-title'>#{title}</div>"
|
39
|
+
@$title =$ "<div class='item-title'>#{ title }</div>"
|
58
40
|
@$el.append(@$title)
|
59
|
-
@$el.attr
|
41
|
+
@$el.attr('data-title', title)
|
60
42
|
|
61
43
|
|
62
44
|
_render_subtitle: ->
|
@@ -78,6 +60,30 @@ class @Item
|
|
78
60
|
@$el.addClass 'has-thumbnail'
|
79
61
|
|
80
62
|
|
63
|
+
# EVENTS ================================================
|
64
|
+
|
65
|
+
_click: (e) ->
|
66
|
+
if @.$el.hasClass('active') then e.preventDefault() ; return
|
67
|
+
|
68
|
+
hash = $(e.currentTarget).attr('href')
|
69
|
+
crumbs = hash.split('/')
|
70
|
+
title = $(e.currentTarget).attr('data-title')
|
71
|
+
id = $(e.currentTarget).attr('data-id')
|
72
|
+
|
73
|
+
chr.updateHash(hash, true)
|
74
|
+
|
75
|
+
# show view for a arrayStore item
|
76
|
+
if crumbs[crumbs.length - 2] == 'view'
|
77
|
+
return @module.showViewByObjectId(id, @config, title, true)
|
78
|
+
# show objectStore item view
|
79
|
+
if @config.objectStore
|
80
|
+
return @module.showViewByObjectId('', @config, title, true)
|
81
|
+
# show nested list
|
82
|
+
@module.showNestedList(_last(crumbs), true)
|
83
|
+
|
84
|
+
|
85
|
+
# PUBLIC ================================================
|
86
|
+
|
81
87
|
render: ->
|
82
88
|
@$el.html('').removeClass('item-folder has-subtitle has-thumbnail')
|
83
89
|
@_render_title()
|
@@ -8,8 +8,9 @@
|
|
8
8
|
|
9
9
|
# -----------------------------------------------------------------------------
|
10
10
|
# LIST
|
11
|
+
# -----------------------------------------------------------------------------
|
11
12
|
#
|
12
|
-
#
|
13
|
+
# Configuration options:
|
13
14
|
# itemClass - item class to be used instead of default one
|
14
15
|
# itemTitleField - object attributes name for list item title
|
15
16
|
# itemSubtitleField - object attributes name for list item subtitle
|
@@ -19,13 +20,20 @@
|
|
19
20
|
# onListShow - callback on list is shown
|
20
21
|
# objects - objects array to be added to the store on start
|
21
22
|
#
|
22
|
-
#
|
23
|
+
# Public methods:
|
23
24
|
# hide() - hide list
|
24
25
|
# show() - show list
|
25
26
|
# updateItems() - update list items (sync through store with backend)
|
26
27
|
# isVisible() - check if list is visible
|
27
28
|
#
|
29
|
+
# Dependencies:
|
30
|
+
#= require ./list_config
|
31
|
+
#= require ./list_pagination
|
32
|
+
#= require ./list_reorder
|
33
|
+
#= require ./list_search
|
34
|
+
#
|
28
35
|
# -----------------------------------------------------------------------------
|
36
|
+
|
29
37
|
class @List
|
30
38
|
constructor: (@module, @name, @config, @parentList) ->
|
31
39
|
@configItemsCount = 0
|
@@ -33,6 +41,7 @@ class @List
|
|
33
41
|
@items = {}
|
34
42
|
@title = @config.title ? @name.titleize()
|
35
43
|
@itemClass = @config.itemClass ? Item
|
44
|
+
|
36
45
|
@showWithParent = false
|
37
46
|
if @parentList
|
38
47
|
@showWithParent = @parentList.config.showNestedListsAside || false
|
@@ -56,7 +65,7 @@ class @List
|
|
56
65
|
# back button
|
57
66
|
if @parentList
|
58
67
|
@$backBtn =$ "<a href='#/#{ @parentList.path }' class='back silent'></a>"
|
59
|
-
@$backBtn.on 'click', (e) => @
|
68
|
+
@$backBtn.on 'click', (e) => @_back(e)
|
60
69
|
else
|
61
70
|
@$backBtn =$ "<a href='#/' class='back'></a>"
|
62
71
|
@$header.prepend @$backBtn
|
@@ -68,7 +77,7 @@ class @List
|
|
68
77
|
# new item button
|
69
78
|
if not @config.disableNewItems and @config.formSchema
|
70
79
|
@$newBtn =$ "<a href='#/#{ @path }/new' class='new silent'></a>"
|
71
|
-
@$newBtn.on 'click', (e) => @
|
80
|
+
@$newBtn.on 'click', (e) => @_new(e)
|
72
81
|
@$header.append @$newBtn
|
73
82
|
|
74
83
|
# search
|
@@ -88,6 +97,8 @@ class @List
|
|
88
97
|
@config.onListInit?(@)
|
89
98
|
|
90
99
|
|
100
|
+
# PRIVATE ===============================================
|
101
|
+
|
91
102
|
_bind_hashchange: ->
|
92
103
|
$(chr).on 'hashchange', => @_set_active_item()
|
93
104
|
|
@@ -108,56 +119,6 @@ class @List
|
|
108
119
|
@module.name + ( if crumbs.length > 0 then '/' + crumbs.reverse().join('/') else '' )
|
109
120
|
|
110
121
|
|
111
|
-
_process_config_items: ->
|
112
|
-
for slug, config of @config.items
|
113
|
-
object = { _id: slug, _title: config.title ? slug.titleize() }
|
114
|
-
|
115
|
-
#if config.objectStore
|
116
|
-
# $.extend(object, config.objectStore.get())
|
117
|
-
|
118
|
-
if config.items or config.arrayStore
|
119
|
-
@module.addNestedList(slug, config, this)
|
120
|
-
|
121
|
-
@_add_item("#/#{ @path }/#{ slug }", object, 0, config)
|
122
|
-
@configItemsCount += 1
|
123
|
-
|
124
|
-
|
125
|
-
_bind_config_object_store: ->
|
126
|
-
|
127
|
-
|
128
|
-
_bind_config_array_store: ->
|
129
|
-
# item added
|
130
|
-
@config.arrayStore.on 'object_added', (e, data) =>
|
131
|
-
@_add_item("#/#{ @path }/view/#{ data.object._id }", data.object, data.position, @config)
|
132
|
-
|
133
|
-
if @config.objects
|
134
|
-
@config.arrayStore.addObjects(@config.objects)
|
135
|
-
|
136
|
-
# item updated
|
137
|
-
@config.arrayStore.on 'object_changed', (e, data) =>
|
138
|
-
item = @items[data.object._id]
|
139
|
-
if item then item.render() ; @_update_item_position(item, data.position)
|
140
|
-
|
141
|
-
# item removed
|
142
|
-
@config.arrayStore.on 'object_removed', (e, data) =>
|
143
|
-
item = @items[data.object_id]
|
144
|
-
if item then item.destroy() ; delete @items[data.object_id]
|
145
|
-
|
146
|
-
# items loaded
|
147
|
-
@config.arrayStore.on 'objects_added', (e, data) =>
|
148
|
-
@_hide_spinner()
|
149
|
-
@_set_active_item()
|
150
|
-
|
151
|
-
if @config.arrayStore.pagination
|
152
|
-
_listBindPagination(this)
|
153
|
-
|
154
|
-
if @config.arrayStore.searchable
|
155
|
-
_listBindSearch(this)
|
156
|
-
|
157
|
-
if @config.arrayStore.reorderable
|
158
|
-
_listBindReorder(this)
|
159
|
-
|
160
|
-
|
161
122
|
_add_item: (path, object, position, config) ->
|
162
123
|
item = new @itemClass(@module, path, object, config)
|
163
124
|
@items[object._id] = item
|
@@ -174,14 +135,16 @@ class @List
|
|
174
135
|
|
175
136
|
|
176
137
|
_show_spinner: ->
|
177
|
-
@$el.addClass
|
138
|
+
@$el.addClass('show-spinner')
|
178
139
|
|
179
140
|
|
180
141
|
_hide_spinner: ->
|
181
|
-
@$el.removeClass
|
142
|
+
@$el.removeClass('show-spinner')
|
143
|
+
|
182
144
|
|
145
|
+
# EVENTS ================================================
|
183
146
|
|
184
|
-
|
147
|
+
_back: (e) ->
|
185
148
|
@module.chr.unsetActiveListItems()
|
186
149
|
@module.destroyView()
|
187
150
|
|
@@ -191,12 +154,13 @@ class @List
|
|
191
154
|
@module.hideActiveList(true)
|
192
155
|
|
193
156
|
|
194
|
-
|
195
|
-
|
196
|
-
location.hash = $(e.currentTarget).attr('href')
|
157
|
+
_new: (e) ->
|
158
|
+
chr.updateHash($(e.currentTarget).attr('href'), true)
|
197
159
|
@module.showView(null, @config, 'New', true)
|
198
160
|
|
199
161
|
|
162
|
+
# PUBLIC ================================================
|
163
|
+
|
200
164
|
hide: (animate) ->
|
201
165
|
if animate then @$el.fadeOut() else @$el.hide()
|
202
166
|
|
@@ -226,5 +190,11 @@ class @List
|
|
226
190
|
@$el.is(':visible')
|
227
191
|
|
228
192
|
|
193
|
+
include(List, listConfig)
|
194
|
+
include(List, listPagination)
|
195
|
+
include(List, listReorder)
|
196
|
+
include(List, listSearch)
|
197
|
+
|
198
|
+
|
229
199
|
|
230
200
|
|