luca 0.9.4 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +41 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/README.md +5 -0
- data/Rakefile +4 -0
- data/assets/javascripts/dependencies/underscore-min.js +5 -31
- data/assets/javascripts/luca-templates.js +1 -0
- data/assets/javascripts/luca-ui-base.coffee +1 -1
- data/assets/javascripts/luca-ui-development-tools.coffee +1 -1
- data/assets/javascripts/luca-ui-full.js +1 -1
- data/assets/javascripts/luca-ui-spec.coffee +1 -1
- data/assets/javascripts/luca-ui.js +3 -0
- data/assets/javascripts/luca/index.coffee +1 -0
- data/lib/generators/luca/application/application_generator.rb +71 -0
- data/lib/generators/luca/application/templates/controller.rb +6 -0
- data/lib/generators/luca/application/templates/index.html.erb +7 -0
- data/lib/generators/luca/application/templates/index.html.haml +6 -0
- data/lib/generators/luca/application/templates/javascripts/application.js +28 -0
- data/lib/generators/luca/application/templates/javascripts/application.js.coffee +20 -0
- data/lib/generators/luca/application/templates/javascripts/config.js +15 -0
- data/lib/generators/luca/application/templates/javascripts/config.js.coffee +9 -0
- data/lib/generators/luca/application/templates/javascripts/dependencies.js +5 -0
- data/lib/generators/luca/application/templates/javascripts/dependencies.js.coffee +5 -0
- data/lib/generators/luca/application/templates/javascripts/index.js +9 -0
- data/lib/generators/luca/application/templates/javascripts/index.js.coffee +9 -0
- data/lib/generators/luca/application/templates/javascripts/main.js +8 -0
- data/lib/generators/luca/application/templates/javascripts/main.js.coffee +3 -0
- data/lib/generators/luca/application/templates/javascripts/main.jst.ejs +1 -0
- data/lib/generators/luca/application/templates/javascripts/router.js +12 -0
- data/lib/generators/luca/application/templates/javascripts/router.js.coffee +7 -0
- data/lib/luca/rails/version.rb +1 -1
- data/lib/luca/template.rb +1 -1
- data/spec/components/collection_view_spec.coffee +37 -0
- data/spec/components/multi_collection_view_spec.coffee +5 -0
- data/spec/components/table_view_spec.coffee +17 -0
- data/spec/core/container_spec.coffee +112 -5
- data/spec/core/model_spec.coffee +21 -3
- data/spec/define_spec.coffee +19 -0
- data/spec/mixin_spec.coffee +49 -0
- data/src/components/application.coffee +33 -19
- data/src/components/collection_view.coffee +109 -38
- data/src/components/fields/checkbox_field.coffee +2 -2
- data/src/components/fields/file_upload_field.coffee +0 -3
- data/src/components/fields/hidden_field.coffee +0 -3
- data/src/components/fields/label_field.coffee +1 -4
- data/src/components/fields/select_field.coffee +6 -6
- data/src/components/fields/text_area_field.coffee +1 -0
- data/src/components/fields/text_field.coffee +4 -0
- data/src/components/fields/type_ahead_field.coffee +5 -9
- data/src/components/form_view.coffee +2 -0
- data/src/components/index.coffee +1 -0
- data/src/components/multi_collection_view.coffee +94 -0
- data/src/components/pagination_control.coffee +100 -0
- data/src/components/table_view.coffee +62 -0
- data/src/containers/card_view.coffee +44 -11
- data/src/containers/panel_toolbar.coffee +88 -82
- data/src/containers/tab_view.coffee +3 -3
- data/src/containers/viewport.coffee +10 -4
- data/src/core/collection.coffee +11 -4
- data/src/core/container.coffee +189 -113
- data/src/core/field.coffee +13 -10
- data/src/core/model.coffee +23 -27
- data/src/core/registry.coffee +48 -35
- data/src/core/view.coffee +60 -140
- data/src/define.coffee +91 -19
- data/src/framework.coffee +10 -8
- data/src/index.coffee +23 -0
- data/src/managers/collection_manager.coffee +24 -8
- data/src/modules/application_event_bindings.coffee +19 -0
- data/src/modules/collection_event_bindings.coffee +26 -0
- data/src/modules/deferrable.coffee +3 -1
- data/src/modules/dom_helpers.coffee +49 -0
- data/src/modules/enhanced_properties.coffee +23 -0
- data/src/modules/filterable.coffee +60 -0
- data/src/modules/grid_layout.coffee +15 -0
- data/src/modules/{load_mask.coffee → loadmaskable.coffee} +10 -4
- data/src/modules/modal_view.coffee +38 -0
- data/src/modules/paginatable.coffee +79 -0
- data/src/modules/state_model.coffee +16 -0
- data/src/modules/templating.coffee +8 -0
- data/src/plugins/events.coffee +30 -2
- data/src/templates/components/bootstrap_form_controls.jst.ejs +10 -0
- data/src/templates/components/collection_loader_view.jst.ejs +6 -0
- data/src/templates/components/form_alert.jst.ejs +4 -0
- data/src/templates/components/grid_view.jst.ejs +11 -0
- data/src/templates/components/grid_view_empty_text.jst.ejs +3 -0
- data/src/templates/components/load_mask.jst.ejs +5 -0
- data/src/templates/components/nav_bar.jst.ejs +4 -0
- data/src/templates/components/pagination.jst.ejs +10 -0
- data/src/templates/containers/basic.jst.ejs +1 -0
- data/src/templates/containers/tab_selector_container.jst.ejs +12 -0
- data/src/templates/containers/tab_view.jst.ejs +2 -0
- data/src/templates/containers/toolbar_wrapper.jst.ejs +1 -0
- data/src/templates/fields/button_field.jst.ejs +2 -0
- data/src/templates/fields/button_field_link.jst.ejs +6 -0
- data/src/templates/fields/checkbox_array.jst.ejs +4 -0
- data/src/templates/fields/checkbox_array_item.jst.ejs +3 -0
- data/src/templates/fields/checkbox_field.jst.ejs +10 -0
- data/src/templates/fields/file_upload_field.jst.ejs +10 -0
- data/src/templates/fields/hidden_field.jst.ejs +1 -0
- data/src/templates/fields/select_field.jst.ejs +11 -0
- data/src/templates/fields/text_area_field.jst.ejs +11 -0
- data/src/templates/fields/text_field.jst.ejs +16 -0
- data/src/templates/table_view.jst.ejs +4 -0
- data/src/tools/console.coffee +51 -21
- data/src/util.coffee +17 -4
- data/vendor/assets/javascripts/luca-ui-base.js +3288 -613
- data/vendor/assets/javascripts/luca-ui-development-tools.js +49 -21
- data/vendor/assets/javascripts/luca-ui-development-tools.min.js +1 -1
- data/vendor/assets/javascripts/luca-ui-full.js +1704 -554
- data/vendor/assets/javascripts/luca-ui-full.min.js +7 -6
- data/vendor/assets/javascripts/luca-ui-spec.js +1783 -830
- data/vendor/assets/javascripts/luca-ui-templates.js +92 -0
- data/vendor/assets/javascripts/luca-ui.js +1694 -523
- data/vendor/assets/javascripts/luca-ui.min.js +4 -4
- metadata +69 -31
- data/assets/javascripts/luca-ui.coffee +0 -3
- data/src/luca.coffee +0 -22
- data/src/templates/components/bootstrap_form_controls.luca +0 -7
- data/src/templates/components/collection_loader_view.luca +0 -5
- data/src/templates/components/form_alert +0 -0
- data/src/templates/components/form_alert.luca +0 -3
- data/src/templates/components/grid_view.luca +0 -7
- data/src/templates/components/grid_view_empty_text.luca +0 -3
- data/src/templates/components/load_mask.luca +0 -3
- data/src/templates/components/nav_bar.luca +0 -2
- data/src/templates/containers/basic.luca +0 -1
- data/src/templates/containers/tab_selector_container.luca +0 -8
- data/src/templates/containers/tab_view.luca +0 -2
- data/src/templates/containers/toolbar_wrapper.luca +0 -1
- data/src/templates/fields/button_field.luca +0 -2
- data/src/templates/fields/button_field_link.luca +0 -5
- data/src/templates/fields/checkbox_array.luca +0 -4
- data/src/templates/fields/checkbox_array_item.luca +0 -4
- data/src/templates/fields/checkbox_field.luca +0 -9
- data/src/templates/fields/file_upload_field.luca +0 -8
- data/src/templates/fields/hidden_field.luca +0 -1
- data/src/templates/fields/select_field.luca +0 -8
- data/src/templates/fields/text_area_field.luca +0 -8
- data/src/templates/fields/text_field.luca +0 -17
- data/src/templates/sample/contents.luca +0 -1
- data/src/templates/sample/welcome.luca +0 -1
- data/vendor/assets/javascripts/luca-spec-dependencies.js +0 -6135
- data/vendor/assets/javascripts/luca-ui-development-dependencies.js +0 -12845
data/src/core/field.coffee
CHANGED
@@ -27,15 +27,21 @@ _.def('Luca.core.Field').extends('Luca.View').with
|
|
27
27
|
@input_id ||= _.uniqueId('field')
|
28
28
|
@input_name ||= @name
|
29
29
|
@input_class ||= ""
|
30
|
+
@input_type ||= ""
|
30
31
|
@helperText ||= ""
|
31
32
|
@label ||= "*#{ @label }" if @required and not @label?.match(/^\*/)
|
32
33
|
@inputStyles ||= ""
|
34
|
+
@input_value ||= @value || ""
|
33
35
|
|
34
36
|
@disable() if @disabled
|
35
37
|
|
36
38
|
@updateState( @state )
|
37
39
|
@placeHolder ||= ""
|
38
40
|
|
41
|
+
# In order to support using Luca.View template properties everywhere.
|
42
|
+
|
43
|
+
# Will need to work around how the field classes
|
44
|
+
# apply templates to themselves.
|
39
45
|
Luca.View::initialize.apply(@, arguments)
|
40
46
|
|
41
47
|
beforeRender: ()->
|
@@ -44,20 +50,17 @@ _.def('Luca.core.Field').extends('Luca.View').with
|
|
44
50
|
|
45
51
|
@$el.addClass('required') if @required
|
46
52
|
|
47
|
-
@$el.html Luca.template(@template, @)
|
48
|
-
@input = $('input', @el)
|
49
|
-
|
50
53
|
change_handler: (e)->
|
51
54
|
@trigger "on:change", @, e
|
52
55
|
|
53
56
|
disable: ()->
|
54
|
-
|
57
|
+
@getInputElement().attr('disabled', true)
|
55
58
|
|
56
59
|
enable: ()->
|
57
|
-
|
60
|
+
@getInputElement().attr('disabled', false)
|
58
61
|
|
59
62
|
getValue: ()->
|
60
|
-
raw = @
|
63
|
+
raw = @getInputElement()?.attr('value')
|
61
64
|
|
62
65
|
return raw if _.str.isBlank( raw )
|
63
66
|
|
@@ -67,11 +70,11 @@ _.def('Luca.core.Field').extends('Luca.View').with
|
|
67
70
|
when "float" then parseFloat(raw)
|
68
71
|
else raw
|
69
72
|
|
70
|
-
render: ()->
|
71
|
-
$( @container ).append( @$el )
|
72
|
-
|
73
73
|
setValue: (value)->
|
74
|
-
@
|
74
|
+
@getInputElement()?.attr('value', value)
|
75
|
+
|
76
|
+
getInputElement: ()->
|
77
|
+
@input ||= @$('input').eq(0)
|
75
78
|
|
76
79
|
updateState: (state)->
|
77
80
|
_( @statuses ).each (cls)=>
|
data/src/core/model.coffee
CHANGED
@@ -1,16 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
model = Luca.define 'Luca.Model'
|
2
|
+
|
3
|
+
model.extends 'Backbone.Model'
|
4
|
+
|
5
|
+
model.includes 'Luca.Events'
|
6
|
+
|
7
|
+
model.defines
|
8
|
+
initialize: ()->
|
9
|
+
Backbone.Model::initialize(@, arguments)
|
10
|
+
setupComputedProperties.call(@)
|
11
|
+
|
12
|
+
read: (attr)->
|
13
|
+
if _.isFunction(@[attr])
|
14
|
+
@[attr].call(@)
|
15
|
+
else
|
16
|
+
@get(attr)
|
17
|
+
|
18
|
+
get: (attr)->
|
19
|
+
if @computed?.hasOwnProperty(attr)
|
20
|
+
@_computed[attr]
|
21
|
+
else
|
22
|
+
Backbone.Model::get.call @, attr
|
23
|
+
|
14
24
|
setupComputedProperties = ()->
|
15
25
|
return if _.isUndefined(@computed)
|
16
26
|
|
@@ -27,17 +37,3 @@ setupComputedProperties = ()->
|
|
27
37
|
@trigger "change:#{attr}"
|
28
38
|
|
29
39
|
@trigger "change:#{attr}" if @has(dep)
|
30
|
-
|
31
|
-
|
32
|
-
_.def('Luca.Model').extends('Backbone.Model').with
|
33
|
-
include: ['Luca.Events']
|
34
|
-
|
35
|
-
initialize: ()->
|
36
|
-
Backbone.Model::initialize @, arguments
|
37
|
-
setupComputedProperties.call(@)
|
38
|
-
|
39
|
-
get: (attr)->
|
40
|
-
if @computed?.hasOwnProperty(attr)
|
41
|
-
@_computed[attr]
|
42
|
-
else
|
43
|
-
Backbone.Model::get.call @, attr
|
data/src/core/registry.coffee
CHANGED
@@ -4,26 +4,41 @@ registry =
|
|
4
4
|
collection_classes: {}
|
5
5
|
namespaces:['Luca.containers','Luca.components']
|
6
6
|
|
7
|
-
|
7
|
+
componentCacheStore =
|
8
8
|
cid_index: {}
|
9
9
|
name_index: {}
|
10
10
|
|
11
11
|
# For container views, if a component is defined with no ctype
|
12
12
|
# then we will pick this one when using
|
13
|
-
Luca.
|
13
|
+
Luca.config.defaultComponentClass = Luca.defaultComponentClass = 'Luca.View'
|
14
|
+
Luca.config.defaultComponentType = Luca.defaultComponentType = 'view'
|
15
|
+
|
16
|
+
Luca.registry.aliases =
|
17
|
+
grid: "grid_view"
|
18
|
+
form: "form_view"
|
19
|
+
text: "text_field"
|
20
|
+
button: "button_field"
|
21
|
+
select: "select_field"
|
22
|
+
card: "card_view"
|
23
|
+
paged: "card_view"
|
24
|
+
wizard: "card_view"
|
25
|
+
collection: "collection_view"
|
26
|
+
list: "collection_view"
|
27
|
+
multi: "collection_multi_view"
|
28
|
+
table: "table_view"
|
14
29
|
|
15
30
|
|
16
31
|
# When you use _.def to define a component, you say
|
17
32
|
# which class it extends() from, and with() which enhancements.
|
18
33
|
# We register that component class for you:
|
19
|
-
Luca.
|
34
|
+
Luca.registerComponent = (component, prototypeName, componentType="view")->
|
20
35
|
Luca.trigger "component:registered", component, prototypeName
|
21
36
|
|
22
37
|
switch componentType
|
23
38
|
when "model"
|
24
39
|
registry.model_classes[ component ] = prototypeName
|
25
40
|
when "collection"
|
26
|
-
registry.
|
41
|
+
registry.collection_classes[ component ] = prototypeName
|
27
42
|
else
|
28
43
|
registry.classes[ component ] = prototypeName
|
29
44
|
|
@@ -38,7 +53,7 @@ Luca.development_mode_register = (component, prototypeName)->
|
|
38
53
|
_( liveInstances ).each (instance)->
|
39
54
|
instance?.refreshCode?.call(instance, prototypeDefinition)
|
40
55
|
|
41
|
-
Luca.
|
56
|
+
Luca.registerComponent( component, prototypeName )
|
42
57
|
|
43
58
|
# We create a @ctype alias for this component definition, and register
|
44
59
|
# the class in a registry.
|
@@ -46,7 +61,7 @@ Luca.development_mode_register = (component, prototypeName)->
|
|
46
61
|
# If you use a custom namespace like MyApp.views.ListView,
|
47
62
|
# then we will register MyApp.views as a namespace. You can
|
48
63
|
# do this yourself too.
|
49
|
-
Luca.registry.addNamespace = (identifier)->
|
64
|
+
Luca.registry.addNamespace = Luca.registry.namespace = (identifier)->
|
50
65
|
registry.namespaces.push( identifier )
|
51
66
|
registry.namespaces = _( registry.namespaces ).uniq()
|
52
67
|
|
@@ -61,16 +76,7 @@ Luca.registry.namespaces = (resolve=true)->
|
|
61
76
|
_( registry.namespaces ).map (namespace)->
|
62
77
|
if resolve then Luca.util.resolve( namespace ) else namespace
|
63
78
|
|
64
|
-
|
65
|
-
grid: "grid_view"
|
66
|
-
form: "form_view"
|
67
|
-
text: "text_field"
|
68
|
-
button: "button_field"
|
69
|
-
select: "select_field"
|
70
|
-
card: "card_view"
|
71
|
-
paged: "card_view"
|
72
|
-
wizard: "card_view"
|
73
|
-
collection: "collection_view"
|
79
|
+
|
74
80
|
|
75
81
|
# Lookup a component in the Luca component registry
|
76
82
|
# by it's ctype identifier. If it doesn't exist,
|
@@ -87,15 +93,22 @@ Luca.registry.lookup = (ctype)->
|
|
87
93
|
|
88
94
|
parents = Luca.registry.namespaces()
|
89
95
|
|
90
|
-
fullPath = _( parents ).chain().map(
|
91
|
-
parent[className]
|
96
|
+
fullPath = _( parents ).chain().map (parent)->
|
97
|
+
parent[className]
|
98
|
+
.compact().value()?[0]
|
92
99
|
|
93
100
|
Luca.registry.instances = ()->
|
94
|
-
_(
|
95
|
-
|
101
|
+
_( componentCacheStore.cid_index ).values()
|
102
|
+
|
103
|
+
Luca.registry.findInstancesByClass = (componentClass)->
|
104
|
+
Luca.registry.findInstancesByClassName( componentClass.displayName )
|
105
|
+
|
96
106
|
Luca.registry.findInstancesByClassName = (className)->
|
107
|
+
className = className.displayName if not _.isString( className )
|
97
108
|
instances = Luca.registry.instances()
|
98
109
|
_( instances ).select (instance)->
|
110
|
+
isClass = instance.displayName is className
|
111
|
+
|
99
112
|
instance.displayName is className or instance._superClass?()?.displayName is className
|
100
113
|
|
101
114
|
Luca.registry.classes = (toString=false)->
|
@@ -106,24 +119,24 @@ Luca.registry.classes = (toString=false)->
|
|
106
119
|
className: className
|
107
120
|
ctype: ctype
|
108
121
|
|
109
|
-
Luca.cache = (
|
110
|
-
|
122
|
+
Luca.cache = Luca.cacheInstance = (cacheKey, object)->
|
123
|
+
return unless cacheKey?
|
124
|
+
return object if object?.doNotCache is true
|
111
125
|
|
112
|
-
|
126
|
+
if object?
|
127
|
+
componentCacheStore.cid_index[ cacheKey ] = object
|
113
128
|
|
114
|
-
|
115
|
-
if component?.component_name?
|
116
|
-
Luca.trigger "component:created:#{ component.component_name }", component
|
117
|
-
component_cache.name_index[ component.component_name ] = component.cid
|
118
|
-
else if component?.name?
|
119
|
-
Luca.trigger "component:created:#{ component.component_name }", component
|
120
|
-
component_cache.name_index[ component.name ] = component.cid
|
129
|
+
object = componentCacheStore.cid_index[ cacheKey ]
|
121
130
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
131
|
+
# optionally, cache it by tying its name to its cid for easier lookups
|
132
|
+
if object?.component_name?
|
133
|
+
componentCacheStore.name_index[ object.component_name ] = object.cid
|
134
|
+
else if object?.name?
|
135
|
+
componentCacheStore.name_index[ object.name ] = object.cid
|
126
136
|
|
127
|
-
|
137
|
+
return object if object?
|
128
138
|
|
139
|
+
# perform a lookup by name if the cid lookup didn't turn anything
|
140
|
+
lookup_id = componentCacheStore.name_index[ cacheKey ]
|
129
141
|
|
142
|
+
componentCacheStore.cid_index[ lookup_id ]
|
data/src/core/view.coffee
CHANGED
@@ -1,100 +1,61 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
view = Luca.register "Luca.View"
|
2
|
+
|
3
|
+
view.extends "Backbone.View"
|
4
|
+
|
5
|
+
# includes are extensions to the prototype, and have no special behavior
|
6
|
+
view.includes "Luca.Events",
|
7
|
+
"Luca.modules.DomHelpers"
|
8
|
+
|
9
|
+
# mixins are includes with special property / method conventions
|
10
|
+
# which customize the components through the use of __initializer and
|
11
|
+
# __included method names. These will be called every time an instance
|
12
|
+
# is created, and the first time the mixin is used to enhance a component.
|
13
|
+
view.mixesIn "DomHelpers",
|
14
|
+
"Templating",
|
15
|
+
"EnhancedProperties",
|
16
|
+
"CollectionEventBindings",
|
17
|
+
"ApplicationEventBindings",
|
18
|
+
"StateModel"
|
19
|
+
|
20
|
+
# Luca.View classes have the concept of special events called hooks
|
21
|
+
# which allow you to tap into the lifecycle events of your view to
|
22
|
+
# customize their behavior. This is especially useful in subclasses.
|
23
|
+
#
|
24
|
+
# You can utilize a @hook method by camelcasing the triggers defined below:
|
25
|
+
view.triggers "before:initialize",
|
26
|
+
"after:initialize",
|
27
|
+
"before:render",
|
28
|
+
"after:render",
|
29
|
+
"first:activation",
|
30
|
+
"activation",
|
31
|
+
"deactivation"
|
32
|
+
|
33
|
+
# Luca.View decorates Backbone.View with some patterns and conventions.
|
34
|
+
view.defines
|
15
35
|
initialize: (@options={})->
|
16
36
|
@trigger "before:initialize", @, @options
|
17
37
|
|
18
38
|
_.extend @, @options
|
19
39
|
|
20
|
-
@
|
40
|
+
if @autoBindEventHandlers is true or @bindAllEvents is true
|
41
|
+
bindAllEventHandlers.call(@)
|
21
42
|
|
22
|
-
|
23
|
-
@bodyTemplateVars.call(@)
|
24
|
-
else
|
25
|
-
@
|
26
|
-
|
27
|
-
if template = @bodyTemplate
|
28
|
-
@$el.empty()
|
29
|
-
Luca.View::$html.call(@, Luca.template(template, templateVars ) )
|
43
|
+
@cid = _.uniqueId(@name) if @name?
|
30
44
|
|
31
|
-
|
45
|
+
@$el.attr("data-luca-id", @name || @cid)
|
46
|
+
|
47
|
+
Luca.cacheInstance( @cid, @ )
|
32
48
|
|
33
49
|
@setupHooks _( Luca.View::hooks.concat( @hooks ) ).uniq()
|
34
50
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@additionalClassNames = @additionalClassNames.split(" ") if _.isString(@additionalClassNames)
|
39
|
-
|
40
|
-
if @gridSpan
|
41
|
-
@additionalClassNames.push "span#{ @gridSpan }"
|
42
|
-
|
43
|
-
if @gridOffset
|
44
|
-
@additionalClassNames.push "offset#{ @gridOffset }"
|
45
|
-
|
46
|
-
if @gridRowFluid
|
47
|
-
@additionalClassNames.push "row-fluid"
|
48
|
-
|
49
|
-
if @gridRow
|
50
|
-
@additionalClassNames.push "row"
|
51
|
-
|
52
|
-
if @additionalClassNames?.length > 0
|
53
|
-
@$el.addClass( additional ) for additional in @additionalClassNames
|
54
|
-
|
55
|
-
@$wrap( @wrapperClass ) if @wrapperClass?
|
56
|
-
|
57
|
-
registerCollectionEvents.call(@)
|
58
|
-
registerApplicationEvents.call( @)
|
51
|
+
if @mixins?.length > 0
|
52
|
+
for module in @mixins
|
53
|
+
Luca.mixin(module)?.__initializer?.call(@, @, module)
|
59
54
|
|
60
55
|
@delegateEvents()
|
61
56
|
|
62
|
-
if @stateful is true and not @state?
|
63
|
-
@state = new Backbone.Model(@defaultState || {})
|
64
|
-
unless @set?
|
65
|
-
@set = _.bind @, @state.set
|
66
|
-
@get = _.bind @, @state.get
|
67
|
-
|
68
|
-
if @mixins?.length > 0
|
69
|
-
for module in @mixins
|
70
|
-
Luca.modules[ module ]._included.call(@, @, module)
|
71
|
-
|
72
57
|
@trigger "after:initialize", @
|
73
58
|
|
74
|
-
$wrap: (wrapper)->
|
75
|
-
if _.isString(wrapper) and not wrapper.match(/[<>]/)
|
76
|
-
wrapper = @make("div",class:wrapper)
|
77
|
-
|
78
|
-
@$el.wrap( wrapper )
|
79
|
-
|
80
|
-
$template: (template, variables={})->
|
81
|
-
@$el.html( Luca.template(template,variables) )
|
82
|
-
|
83
|
-
$html: (content)->
|
84
|
-
@$el.html( content )
|
85
|
-
|
86
|
-
$append: (content)->
|
87
|
-
@$el.append( content )
|
88
|
-
|
89
|
-
$attach: ()->
|
90
|
-
@$container().append( @el )
|
91
|
-
|
92
|
-
$bodyEl: ()->
|
93
|
-
@$el
|
94
|
-
|
95
|
-
$container: ()->
|
96
|
-
$(@container)
|
97
|
-
|
98
59
|
#### Hooks or Auto Event Binding
|
99
60
|
#
|
100
61
|
# views which inherit from Luca.View can define hooks
|
@@ -114,12 +75,12 @@ _.def("Luca.View").extends("Backbone.View").with
|
|
114
75
|
_(set).each (eventId)=>
|
115
76
|
fn = Luca.util.hook( eventId )
|
116
77
|
|
117
|
-
callback = ()
|
78
|
+
callback = ()->
|
118
79
|
@[fn]?.apply @, arguments
|
119
80
|
|
120
81
|
callback = _.once(callback) if eventId?.match(/once:/)
|
121
82
|
|
122
|
-
@
|
83
|
+
@on eventId, callback, @
|
123
84
|
|
124
85
|
registerEvent: (selector, handler)->
|
125
86
|
@events ||= {}
|
@@ -146,9 +107,9 @@ _.def("Luca.View").extends("Backbone.View").with
|
|
146
107
|
Backbone.View.prototype.trigger.apply @, arguments
|
147
108
|
|
148
109
|
|
149
|
-
|
110
|
+
Luca.View._originalExtend = Backbone.View.extend
|
150
111
|
|
151
|
-
|
112
|
+
Luca.View.renderWrapper = (definition)->
|
152
113
|
_base = definition.render
|
153
114
|
|
154
115
|
_base ||= Luca.View::$attach
|
@@ -164,7 +125,7 @@ customizeRender = (definition)->
|
|
164
125
|
@deferrable = @collection
|
165
126
|
|
166
127
|
target ||= @deferrable
|
167
|
-
trigger = if @deferrable_event then @deferrable_event else
|
128
|
+
trigger = if @deferrable_event then @deferrable_event else Luca.View.deferrableEvent
|
168
129
|
|
169
130
|
deferred = ()->
|
170
131
|
_base.call(view)
|
@@ -194,63 +155,22 @@ customizeRender = (definition)->
|
|
194
155
|
definition
|
195
156
|
|
196
157
|
bindAllEventHandlers = ()->
|
197
|
-
|
198
|
-
|
199
|
-
_.bindAll @, handler
|
200
|
-
|
201
|
-
registerApplicationEvents = ()->
|
202
|
-
return if _.isEmpty(@applicationEvents)
|
203
|
-
|
204
|
-
app = @app
|
205
|
-
|
206
|
-
if _.isString( app ) or _.isUndefined( app )
|
207
|
-
app = Luca.Application?.get?(app)
|
208
|
-
|
209
|
-
unless Luca.supportsEvents( app )
|
210
|
-
throw "Error binding to the application object on #{ @name || @cid }"
|
211
|
-
|
212
|
-
for eventTrigger, handler in @applicationEvents
|
213
|
-
handler = @[handler] if _.isString(handler)
|
214
|
-
|
215
|
-
unless _.isFunction(handler)
|
216
|
-
throw "Error registering application event #{ eventTrigger } on #{ @name || @cid }"
|
217
|
-
|
218
|
-
app.on(eventTrigger, handler)
|
219
|
-
|
220
|
-
registerCollectionEvents = ()->
|
221
|
-
return if _.isEmpty( @collectionEvents )
|
222
|
-
|
223
|
-
manager = @collectionManager
|
224
|
-
|
225
|
-
if _.isString( manager ) or _.isUndefined( manager )
|
226
|
-
manager = Luca.CollectionManager.get( manager )
|
227
|
-
|
228
|
-
for signature, handler of @collectionEvents
|
229
|
-
console.log "Sig", signature, "Handler", handler
|
230
|
-
[key,eventTrigger] = signature.split(" ")
|
231
|
-
|
232
|
-
collection = manager.getOrCreate( key )
|
233
|
-
|
234
|
-
if !collection
|
235
|
-
throw "Could not find collection specified by #{ key }"
|
158
|
+
for config in [@events, @componentEvents, @collectionEvents, @applicationEvents] when not _.isEmpty(config)
|
159
|
+
bindEventHandlers.call(@, config)
|
236
160
|
|
161
|
+
bindEventHandlers = (events={})->
|
162
|
+
for eventSignature, handler of events
|
237
163
|
if _.isString(handler)
|
238
|
-
|
239
|
-
|
240
|
-
unless _.isFunction(handler)
|
241
|
-
throw "invalid collectionEvents configuration"
|
242
|
-
|
243
|
-
try
|
244
|
-
collection.bind(eventTrigger, handler)
|
245
|
-
catch e
|
246
|
-
console.log "Error Binding To Collection in registerCollectionEvents", @
|
247
|
-
throw e
|
248
|
-
|
164
|
+
_.bindAll @, handler
|
249
165
|
|
250
166
|
Luca.View.extend = (definition)->
|
251
|
-
definition =
|
167
|
+
definition = Luca.View.renderWrapper( definition )
|
252
168
|
|
253
169
|
if definition.mixins? and _.isArray( definition.mixins )
|
254
|
-
|
170
|
+
for module in definition.mixins
|
171
|
+
Luca.decorate( definition ).with( module )
|
172
|
+
|
173
|
+
Luca.View._originalExtend.call(@, definition)
|
174
|
+
|
255
175
|
|
256
|
-
|
176
|
+
Luca.View.deferrableEvent = "reset"
|