Sha256: 58b0f44bfec881f1aaa5fac58bc3823e51663a6cfec4259759d8c1dfb9898758

Contents?: true

Size: 1.7 KB

Versions: 6

Compression:

Stored size: 1.7 KB

Contents

class App.Views.PolledItem extends Backbone.View
  tagName: 'tr'
  initialize: ->
    @model.on 'change', @render, @

class App.Views.PollingList extends Backbone.View
  events:
    'click .poller a': 'togglePolling'
  initialize: ->
    @collection = new @options.collectionClass( [] )
    @spinner = @$('tfoot .poller .spinner')
    @polling = false
    @body = @$('tbody')
    @emptyMessage = @body.html().replace(/[\r\n]\s+/g, '')
    @collection.on 'remove', @remove, @
    @collection.on 'add', @render, @
    @collection.fetch( update: true, success: _.bind(@render, @) )
    @views = {}
  remove: ( m ) ->
    @views[m.id] = null
    @render()
  render: ->
    if @collection.isEmpty()
      message = $(@emptyMessage)
      message.find('p.loading_message').text( "No #{@collection.name}!" )
      @body.html( message )
    else
      @body.find('p.loading_message').parents('tr').remove()
      @collection.each (m) =>
        return if @views[m.id]
        v = new @options.viewClass( model: m )
        @views[m.id] = v
        @body.prepend v.render().el
    @$('tfoot p.total strong').text( @collection.length )
  togglePolling: (e) ->
    link = $(e.target)
    if @polling == false
      @polling = true
      @poll()
      link.text( 'stop polling' )
    else
      @polling = false
      link.text( 'start polling' )
      @spinner.hide()
  poll: ->
    if @polling
      startTime = new Date().getTime()
      @spinner.fadeIn()
      args =
        update: true
        success: =>
          setTimeout( _.bind(@poll, @), 2000 ) if @polling
          setTimeout(
            _.bind( @spinner.fadeOut, @spinner )
            Math.max( (new Date().getTime() - startTime), 500 )
          )
      @collection.fetch args

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
auto_error-0.0.9 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.8 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.7 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.6 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.5 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.4 app/assets/javascripts/auto_error/app_errors/views/base.coffee