Skip to content

Instantly share code, notes, and snippets.

@nnarhinen
Created January 14, 2014 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nnarhinen/8415597 to your computer and use it in GitHub Desktop.
Save nnarhinen/8415597 to your computer and use it in GitHub Desktop.
class BaseVideoListView extends Backbone.View
initialize: (opts) ->
@collection.selectedCount.assign @subNav.find('.selected_count'), 'text'
@collection.selectedCount.onValue (val) =>
@subNav.find('.library-nav').toggleClass 'singular-selection', val == 1
this.$el.toggleClass 'multiple-selection', val > 1
@collection.hasSelected.assign @subNav.find('.visible-selected'), 'toggle'
@collection.hasSelected.not().assign @subNav.find('.hidden-selected'), 'toggle'
@collection.hasPlayableSelected.assign @subNav.find('.visible-playable-selected,.visible-unpublishable-selected'), 'toggle'
@collection.hasDebrandableSelected.assign @subNav.find('.visible-debrandable-selected'), 'toggle'
@collection.hasPublishableSelected.assign @subNav.find('.visible-publishable-selected'), 'toggle'
@collection
.selected.map((c) -> c.filter((m) -> !!m.get('public') || !!m.get('free')))
.map((c) -> c.length > 0).toProperty()
.assign @subNav.find('.visible-playable-debrandabĺe-selected'), 'toggle'
class VideoCollection extends Backbone.Collection
url: '/videos'
model: VideoModel
initialize: ->
@changed = @asEventStream("add remove reset change select").map(this)
@selected = @changed.map => @filter (t) -> t.selected
@debrandableSelected = @selected.map (c) -> c.filter (t) -> !!t.get('free')
@playableSelected = @selected.map (c) -> c.filter (t) -> !!t.get('public')
@publishableSelected = @selected.map (c) -> c.filter (t) -> !t.get('public')
@selectedCount = @selected.map((c) -> c.length).toProperty()
@hasSelected = @selected.map((c) -> c.length > 0).toProperty()
@hasPlayableSelected = @playableSelected.map((c) -> c.length > 0).toProperty()
@hasPublishableSelected = @publishableSelected.map((c) -> c.length > 0).toProperty()
@hasDebrandableSelected = @debrandableSelected.map((c) -> c.length > 0).toProperty()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment