vendor/assets/javascripts/brainstem/brainstem-collection.coffee in brainstem-js-0.2.1 vs vendor/assets/javascripts/brainstem/brainstem-collection.coffee in brainstem-js-0.3.0

- old
+ new

@@ -16,25 +16,35 @@ else @add backboneModel else Brainstem.Utils.warn "Unable to update collection with invalid model", model - loadNextPage: (options) => + loadNextPage: (options) -> oldLength = @length + pageSize = 0 + paginationOptions = {} + + if @lastFetchOptions.perPage + paginationOptions.page = @lastFetchOptions.page + 1 + pageSize = @lastFetchOptions.perPage + else + paginationOptions.offset = @lastFetchOptions.offset + @lastFetchOptions.limit + pageSize = @lastFetchOptions.limit + success = (collection) => - options.success(collection, collection.length == oldLength + @lastFetchOptions.perPage) if options.success? - base.data.loadCollection @lastFetchOptions.name, _.extend({}, @lastFetchOptions, options, page: @lastFetchOptions.page + 1, collection: this, success: success) + options.success(collection, collection.length == oldLength + pageSize) if options.success? + base.data.loadCollection @lastFetchOptions.name, _.extend({}, @lastFetchOptions, options, paginationOptions, collection: this, success: success) - reload: (options) => + reload: (options) -> base.data.reset() @reset [], silent: true @setLoaded false base.data.loadCollection @lastFetchOptions.name, _.extend({}, @lastFetchOptions, options, page: 1, collection: this) - getWithAssocation: (id) => + getWithAssocation: (id) -> @get(id) - toServerJSON: (method) => + toServerJSON: (method) -> @toJSON() @getComparatorWithIdFailover: (order) -> [field, direction] = order.split(":") comp = @getComparator(field) \ No newline at end of file