src/components/multi_collection_view.coffee in luca-0.9.6 vs src/components/multi_collection_view.coffee in luca-0.9.7
- old
+ new
@@ -1,6 +1,6 @@
-multiView = Luca.define "Luca.components.MultiCollectionView"
+multiView = Luca.register "Luca.components.MultiCollectionView"
# The CollectionMultiView is a collection view with multiple renderings
# of the list. ( e.g. Icons, Table, List ). It works by maintaining
# a current view, and rendering that view. It refreshes the views
# whenever they are activated.
@@ -22,13 +22,13 @@
# reader: "attribute"
# ]
# ]
multiView.extends "Luca.containers.CardView"
-multiView.behavesAs "LoadMaskable",
- "Filterable",
- "Paginatable"
+multiView.mixesIn "LoadMaskable",
+ "Filterable",
+ "Paginatable"
multiView.triggers "before:refresh",
"after:refresh",
"refresh",
"empty:results"
@@ -46,43 +46,70 @@
initialize: (@options={})->
@components ||= @views
validateComponent( view ) for view in @components
- @on "collection:change", @refresh, @
+ @on "refresh", @refresh, @
@on "after:card:switch", @refresh, @
- @on "before:components", propagateCollectionComponents, @
- @on "after:components", bubbleCollectionEvents, @
+ @on "after:components", propagateCollectionComponents, @
+ @debug("multi collection , proto initialize")
+
Luca.containers.CardView::initialize.apply(@, arguments)
+ relayAfterRefresh: (models,query,options)->
+ @trigger "after:refresh", models, query, options
+
refresh: ()->
@activeComponent()?.trigger("refresh")
- getQuery: Luca.components.CollectionView::getQuery
- getQueryOptions: Luca.components.CollectionView::getQueryOptions
- getCollection: Luca.components.CollectionView::getCollection
-
-#### Private Helpers
+ getCollection: ()->
+ @collection
-bubbleCollectionEvents = ()->
- container = @
- container.eachComponent (component)->
- for eventId in ['refresh','before:refresh','after:refresh','empty:results']
- component.on eventId, ()->
- if component is container.activeComponent()
- container.trigger(eventId)
+ applyQuery: (query={},queryOptions={})->
+ @query = query
+ @queryOptions = queryOptions
+ @
+ # Private: returns the query that is applied to the underlying collection.
+ # accepts the same options as Luca.Collection.query's initial query option.
+ getQuery: ()->
+ @debug("Get Query")
+ query = @query ||= {}
+ for querySource in @querySources
+ query = _.extend(query, (querySource()||{}) )
+ query
+
+ # Private: returns the query that is applied to the underlying collection.
+ # accepts the same options as Luca.Collection.query's initial query option.
+ getQueryOptions: ()->
+ @debug("Get Query Options")
+ options = @queryOptions ||= {}
+
+ for optionSource in @optionsSources
+ options = _.extend(options, (optionSource()||{}) )
+
+ options
+
propagateCollectionComponents = ()->
container = @
# in the multi view will share the same
# collection, filter state, pagination options, etc
for component in @components
+
+ component.on "after:refresh", (models,query,options)=>
+ @debug "collection member after refresh"
+ @trigger("after:refresh",models,query,options)
+
_.extend component,
- collection: container.getCollection?() || @collection
- getQuery: container.getQuery
- getQueryOptions: container.getQueryOptions
+ collection: container.getCollection()
+
+ getQuery: ()->
+ container.getQuery.call(container)
+
+ getQueryOptions: ()->
+ container.getQueryOptions.call(container)
validateComponent = (component)->
type = (component.type || component.ctype)
return if type is "collection" or