Sha256: 5e5b6b36bbb070a6c0bdb92e78c7f6b5ebbb0fcba08314806ba4dbc8fb7e60aa

Contents?: true

Size: 1.79 KB

Versions: 18

Compression:

Stored size: 1.79 KB

Contents

window.CoalescingPanda or= {}

window.CoalescingPanda.CanvasBatchProgress = class CanvasBatchProgress
  constructor: (successCallback, errorCallback, messages)  ->
    window.messages = messages if messages != undefined
    setFlashMessages()
    batch = $('#batch-progress').data('batch')
    url = $('#batch-progress').data('url')
    window.clearPath = $('#batch-progress').data('clear-path')
    if batch && batch.status != "Completed" || batch.status != "Error"
      window.batchInterval = setInterval(getBatchStatus, 3000, batch.id, url, successCallback, errorCallback)

  getBatchStatus = (id, url, successCallback, errorCallback) ->
    $.ajax
      url: url
      success: (data) ->
        $('#batch-progress').html(data)
        setFlashMessages()
        batch = $('#batch-info').data('batch')
        if batch.status == "Completed"
          clearIntervalAndBatch(data, batch)
          successCallback() if successCallback != undefined
        else if batch.status == 'Error'
          clearIntervalAndBatch(data, batch)
          errorCallback() if errorCallback != undefined

      error: (message) ->
        $('#batch-progress').html('Batch status request failed')
        clearInterval(window.batchInterval)

  clearBatchFromSession = (id) ->
    $.ajax
      url: window.clearPath
      type: 'POST'
      success: (data) ->
        # Don't need to do anything

  clearIntervalAndBatch = (data, batch) ->
    clearInterval(window.batchInterval)
    $('#batch-progress').html(data)
    setFlashMessages()
    clearBatchFromSession(batch.id)

  setFlashMessages = ->
    if window.messages != undefined
      for key of window.messages
        $(".batch-message-#{key}").text("#{window.messages[key]}")

$ ->
  $("#batch-container").unbind().bind "batchStarted", (event, data) ->
    new CanvasBatchProgress()

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
coalescing_panda-4.1.4 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.1.3 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.1.2 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.1.1 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.1.0 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.0.4 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.0.3 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.0.2 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.0.1 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-4.0.0 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-3.2.3 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-3.2.2 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-3.2.1 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-3.2.0 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-3.1.14 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-3.1.13 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-3.1.12 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-3.1.11 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee