 # All this logic will automatically be available in application.js.
 # You can use CoffeeScript in this file: http://coffeescript.org/
 class @PodsProgressBar
-  update: (chunk_id) ->
-    progress = (chunk_id / (gon.pods_index.length - 1)) * 100
+  update: (factor) ->
+    progress = factor * 100
     $('.progress-bar').css('width', progress + '%')
   start: ->
     $('.progress-container').hide().html($('.progress-tpl').html()).slideDown(1000)

class PodsLoader
  delegate: null
  requests: []
  cancel: ->
    for request in @requests
      request.abort()
    @requests = []
  loadPods: ->
    @cancel()
    for chunk in gon.pods_index

      controller.podsChunkDidLoad(chunk_id, pods)
    xhr.send()
    @requests.push(xhr)
    @running += 1
  podsChunkDidLoad: (chunk_id, pods) ->
    @running -= 1
    @finished += 1
    if @delegate
      if @delegate.didLoad
        @delegate.didLoad(chunk_id, pods)
      if @delegate.didLoadAll
        if @progress() == 1
          @delegate.didLoadAll()
class @PodsController
  delegate: null
