This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
App.albums = new App.Collections.Albums | |
App.albumsListView = new App.Views.AlbumsListView(collection: App.albums) | |
App.albums.fetch | |
success: -> | |
App.albumsListView.setPlaceholder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumsListView = Backbone.View.extend | |
… | |
initialize: -> | |
@listenTo @collection, 'sync', @render | |
@on 'handlePlaceholder', @setPlaceholder, @ | |
@setPlaceholder() | |
… | |
setPlaceholder: -> | |
if @$el.children('li').length is 0 | |
$('.featured-albums').append('<p>No featured albums</p>') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumsListView = Backbone.View.extend | |
el: '#featured' | |
initialize: -> | |
@listenTo @collection, 'sync', @render | |
@on 'handlePlaceholder', @setPlaceholder, @ | |
@setPlaceholder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumsListView = Backbone.View.extend | |
el: '#featured' | |
initialize: -> | |
@listenTo @collection, 'sync', @render | |
@on 'handlePlaceholder', @setPlaceholder, @ | |
render: -> | |
for model in @collection.featured() | |
itemView = new App.Views.AlbumItemView(model: model, listView: this) | |
@$el.append itemView.render().el | |
setPlaceholder: -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumsListView = Backbone.View.extend | |
el: '#featured' | |
initialize: -> | |
@listenTo @collection, 'sync', @render | |
@on 'handlePlaceholder', @setPlaceholder, @ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumsListView = Backbone.View.extend | |
… | |
render: -> | |
for model in @collection.featured() | |
itemView = new App.Views.AlbumItemView(model: model, listView: this) | |
@$el.append itemView.render().el |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unfeature: -> | |
@model.save(featured: false) | |
@remove() | |
@listView.trigger 'handlePlaceholder' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumsListView = Backbone.View.extend | |
… | |
initialize: -> | |
@listenTo @collection, 'sync', @render |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumItemView = Backbone.View.extend | |
… | |
setPlaceholder: -> | |
if $('#featured').children('li').length is 0 then $('.featured-albums').append('<p>No featured albums</p>') | |
events: | |
'click .unfeature': 'unfeature' | |
unfeature: -> | |
@model.save(featured: false) | |
@remove() | |
@setPlaceholder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumsListView = Backbone.View.extend | |
… | |
unfeature: -> | |
@model.save(featured: false) | |
@remove() | |
if $('#featured').children('li').length is 0 then $('.featured-albums').append('<p>No featured albums</p>') |