ChangeList.coffee 685 B

123456789101112131415161718192021222324252627282930313233
  1. define [
  2. "track-changes/models/Change"
  3. "libs/backbone"
  4. ], (Change)->
  5. ChangeList = Backbone.Collection.extend
  6. model: Change
  7. batchSize: 10
  8. initialize: (models, @options) ->
  9. @ide = @options.ide
  10. @atEnd = false
  11. url: () ->
  12. url = "/project/#{@options.project_id}/updates?min_count=#{@batchSize}"
  13. if @nextBeforeTimestamp?
  14. url += "&before=#{@nextBeforeTimestamp}"
  15. return url
  16. isAtEnd: () -> @atEnd
  17. parse: (json) ->
  18. @nextBeforeTimestamp = json.nextBeforeTimestamp
  19. @atEnd = !@nextBeforeTimestamp
  20. return json.updates
  21. fetchNextBatch: (options = {}) ->
  22. if @isAtEnd()
  23. options.success?(@)
  24. return
  25. options.add = true
  26. @fetch options