Sha256: 169ff3d949b1055831532c47878541cc13a32ca3412ab6f8b8cb348cae61ae62

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 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)

  # 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 ||= @getQuery()
      options ||= @getQueryOptions()
      options.prepare ||= @prepareQuery

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
luca-0.9.8 app/assets/javascripts/luca/concerns/query_collection_bindings.coffee