App.PaginationModule = Ember.Mixin.create
  #modelClass: ->
    #@modelInfo.class
  modelNameForStore: ->
    #@modelInfo.store
    @get('content.type.typeKey')
  storeMetadata: (k) ->
    #res = @store.typeMapFor(@modelClass()).metadata
    res = @store.metadataFor @get('content.type.typeKey')
    res = res[k] if k
    res
  setStoreMetadata: (k,v) ->
    #res = @store.typeMapFor(@modelClass()).metadata
    res = @store.metadataFor @get('content.type.typeKey')
    res[k] = v

  loadMore: ->
    page = @storeMetadata('page') + 1
    @setStoreMetadata('page',page)
    @store.findQuery(@modelNameForStore(),page: page)
    page

  hasMoreFunc: ->
    page = @storeMetadata('page')
    total = @storeMetadata('total_pages')
    #unfiltered = @storeMetadata('unfiltered_total_pages')
    unfiltered = total

    #console.debug "page #{page} total #{total} unfiltered #{unfiltered}"

    !unfiltered || page < unfiltered
  actions:
    showMore: ->
      page = @loadMore()
      @set 'lastKnownPage', page

  hasMore: (-> @hasMoreFunc()).property('lastKnownPage','firstObject','.[]','filtered.[]')
