Sha256: 56a8ea27b167f7a94cff1bb160fd667f98470459ad42577f0e4fe5c7ff6b3eb4

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

Luca.concerns.QueryCollectionBindings = 
  getCollection: ()->
    @collection

  loadModels: (models=[], options={})->
    @getCollection()?.reset(models, options)

  applyQuery: (query={},queryOptions={})->
    @query = query
    @queryOptions = queryOptions
    @refresh()
    @

  # Private: returns the query that is applied to the underlying collection.
  # accepts the same options as Luca.Collection.query's initial query option.
  getQuery: (options={})-> 
    query = @query ||= {}

    for querySource in _( @querySources || [] ).compact()
      query = _.extend(query, (querySource(options)||{}) ) 
          
    Luca.util.readAll(query)

  getRemoteQuery: (options = {}) ->
    @getQuery(options)

  getLocalQuery: (options = {}) ->
    @getQuery(options)

  # Private: returns the query that is applied to the underlying collection.
  # accepts the same options as Luca.Collection.query's initial query option.
  getQueryOptions: (options={})-> 
    queryOptions = @queryOptions ||= {}

    for optionSource in _( @optionsSources || [] ).compact()
      queryOptions = _.extend(queryOptions, (optionSource(options)||{}) ) 

    queryOptions
  # Private: returns the models to be rendered.  If the underlying collection
  # responds to @query() then it will use that interface. 
  getModels: (query,options)->
    if @collection?.query
      query ||= @getLocalQuery()
      options ||= @getQueryOptions()
      options.prepare ||= @prepareQuery

      # TODO
      # Need to write specs for this  
      @collection.query(query, options)
    else
      @collection.models

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
luca-0.9.91 app/assets/javascripts/luca/concerns/query_collection_bindings.coffee
luca-0.9.9 app/assets/javascripts/luca/concerns/query_collection_bindings.coffee
luca-0.9.899 app/assets/javascripts/luca/concerns/query_collection_bindings.coffee
luca-0.9.89 app/assets/javascripts/luca/concerns/query_collection_bindings.coffee