Sha256: cf9e32ec9e85e188eacd65f1ac00ed3775e819fbdfad737bc6a8e030716a9bf0

Contents?: true

Size: 1.04 KB

Versions: 43

Compression:

Stored size: 1.04 KB

Contents

Locomotive.Views.Shared ||= {}

class Locomotive.Views.Shared.ListView extends Backbone.View

  tagName: 'div'

  _item_views = []

  initialize: ->
    _.bindAll(@, 'insert_item', 'remove_item')
    @collection.bind('add', @insert_item)
    @collection.bind('remove', @remove_item)

  template: ->
    # please overide template

  item_view_class: ->
    # please overide item_view_class

  render: ->
    $(@el).html(@template()())

    @render_items()

    return @

  render_items: ->
    if @collection.length == 0
      @$('.no-items').show()
    else
      @collection.each (item) =>
        @insert_item(item)

  insert_item: (item) ->
    klass = @item_view_class()
    view = new klass model: item, parent_view: @

    (@_item_views ||= []).push(view)

    @$('.no-items').hide()
    @$('ul').append(view.render().el)

  remove_item: (item) ->
    @$('.no-items').show() if @collection.length == 0
    view = _.find @_item_views, (tmp) -> tmp.model == item
    view.remove() if view?

  remove: ->
    _.each @_item_views, (view) => view.remove()
    super



Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
locomotive_cms-2.5.7 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.6 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.6.rc2 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.6.rc1 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.5 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.4 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.3 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.2 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.1 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.0 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.0.rc3 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.0.rc2 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.5.0.rc1 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.4.1 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.4.0 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.3.1 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.3.0 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.2.3 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.2.2 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee
locomotive_cms-2.2.1 app/assets/javascripts/locomotive/views/shared/list_view.js.coffee