Sha256: 13c591cd41b2ed71a3451beee4752520da41b52625828306b15ad25cd6ef9469

Contents?: true

Size: 1.71 KB

Versions: 7

Compression:

Stored size: 1.71 KB

Contents

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

class AutoErrorApp.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

7 entries across 7 versions & 1 rubygems

Version Path
auto_error-0.0.18 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.16 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.15 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.14 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.13 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.12 app/assets/javascripts/auto_error/app_errors/views/base.coffee
auto_error-0.0.10 app/assets/javascripts/auto_error/app_errors/views/base.coffee