Sha256: 46f6075b150e3e09246363118525d4457e50d87fffd21d8515dc4430c16413e0

Contents?: true

Size: 951 Bytes

Versions: 1

Compression:

Stored size: 951 Bytes

Contents

SimpleSubmitter = require "hoarder/submitter/submitters/simple_submitter"

#
# @author - Tim Shelburne <tim@musiconelive.com>
#
# handles executing a delayed
#
class PollingSubmitter extends SimpleSubmitter
  constructor: (@pollUrl, @pollFrequency)->
    super()

  canSubmit: (form)-> form.type is "polling"

  submitSuccess: (form, data)->
    @interval = setInterval( =>
      @queryPoll(form, data.pollId)
    , @pollFrequency)
    @queryPoll(form, data.pollId)

  queryPoll: (form, pollId)=>
    unless @executing
      @executing = true
      $.ajax
        url: @pollUrl
        type: "POST"
        data: "pollId=#{pollId}"
        success: (data)=> @pollSuccess(form, pollId, data)
        error: (xhr, text)=> @submitError(form, xhr, text)

  pollSuccess: (form, pollId, data)=>
    @executing = false
    if data.pollCompleted
      clearInterval(@interval)
      @submittedWithSuccess.dispatch(form, data.pollData)

return PollingSubmitter

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hoarder-js-0.0.1 assets/scripts/coffee/hoarder/submitter/submitters/polling_submitter.coffee