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/assets/javascripts/views/albums_list_view.js.coffee | |
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) |
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/assets/javascripts/collections/albums.js.coffee | |
App.Collections.Albums = Backbone.Collection.extend | |
model: App.Models.Album | |
url: -> | |
userId = $('#featured').data('user-id') | |
"/users/#{userId}/albums" | |
featured: -> | |
@where(featured: true) |
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 | |
tagName: 'li' | |
template: JST['templates/album_template'] | |
initialize: (opts) -> | |
@listView = opts.listView | |
render: -> | |
@$el.html @template @model.attributes | |
this | |
events: | |
'click .unfeature': 'unfeature' |
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.AlbumItemView = Backbone.View.extend | |
tagName: 'li' | |
template: JST['templates/album_template'] | |
… |
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
… | |
//= require_tree ./templates | |
… |
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
… | |
//= require_tree ../templates | |
… |
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
%a{ href: "users/#{user_id}/albums/#{id}" } | |
= title | |
%button.unfeature Unfeature × |
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
//= require_self | |
//= require_tree ../templates | |
//= require_tree ./models | |
//= require_tree ./collections | |
//= require_tree ./views | |
//= require_tree ./routers | |
//= require_tree . | |
//= require app | |
// | |
window.App = { |
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
setPlaceholder: -> | |
if @collection.featured().length is 0 | |
$('.featured-albums').append('<p>No featured albums</p>') | |
else | |
$('.featured-albums').find('p').remove() |