Sha256: 2050c3ae780e2372b1bbd4ecb52ce24affffb6a2e151340a2fba428e442de3b9

Contents?: true

Size: 1.8 KB

Versions: 82

Compression:

Stored size: 1.8 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 && batch.status == "Completed"
          clearIntervalAndBatch(data, batch)
          successCallback() if successCallback != undefined
        else if batch && batch.status == 'Error'
          clearIntervalAndBatch(data, batch)
          errorCallback() if errorCallback != undefined
        else if batch && batch.status == "Canceled"
          clearIntervalAndBatch(data, batch)

      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]}")

Version data entries

82 entries across 82 versions & 1 rubygems

Version Path
coalescing_panda-5.3.0 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.2.2 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.2.2.beta1 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.2.1 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.2.0 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.2.0.beta2 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.2.0.beta1 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.13 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.12 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.11 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.10 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.9 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.8 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.7 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.6 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.5 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.4 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.3.beta.2 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.3.beta.1 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee
coalescing_panda-5.1.3 app/assets/javascripts/coalescing_panda/canvas_batch.js.coffee