 
     @currentModels = @fullCollection.models.slice()
     @state = _.defaults(_.clone(@state) ? {},
-      pageSize: 10
-      currentPage: 0
-      sorting: null
-      filter: null
-      filterQuery: ""
+      pageSize : 10
+      currentPage : 0
+      sorting : null
+      filter : null
+      filterQuery : ""
     )
 
     @length = Math.min(@state.pageSize, @fullCollection.length)

    return


  getPaginationInfo: ->
    return {
      firstPage: 0
      lastPage: @_lastPageIndex()
      currentPage: @state.currentPage
      pageSize: @state.pageSize
    }


  getPreviousPage: ->
    @getPage(@state.currentPage - 1)
    return


  getNextPage: ->
    @getPage(@state.currentPage + 1)
    return


  getFirstPage: ->
    @getPage(0)
    return


  getLastPage: ->
    @getPage(@_lastPageIndex())
    return


  getPage: (pageIndex) ->
    if 0 <= pageIndex < Math.ceil(@currentModels.length / @state.pageSize)
      @state.currentPage = pageIndex
      @_reset()
    return

  toJSON: ->
    @models.map((model) -> model.toJSON())


module.exports = PaginationCollection

    @listenTo(@fullCollection, "sync", @_passthroughEvent("sync"))


  add : ->
    @fullCollection.add.apply(@fullCollection, arguments)

  remove : ->
    @fullCollection.remove.apply(@fullCollection, arguments)

  set : ->
    @fullCollection.set.apply(@fullCollection, arguments)

  fetch : ->
    @fullCollection.fetch.apply(@fullCollection, arguments)

  create : ->
    @fullCollection.create.apply(@fullCollection, arguments)

  reset : ->
    @fullCollection.reset.apply(@fullCollection, arguments)


  setPageSize : (pageSize) ->
    @state.pageSize = pageSize
    @_reset()
    return


  setSorting : (field, order) ->
    @setSort(field, order)
    return


  setSort : (field, order) ->

    if order == "asc"
      order = 1
