We'll start with the models.js
file. There are two types of data we're going to be displaying here: podcasts and episodes. So, we'll have a model and collection for each of these. Let's start with episodes:
var Episode = Backbone.Model.extend({ urlRoot: '/episode', listen: function () { this.save({ listened: true }); } }); var Episodes = Backbone.Collection.extend({ model: Episode, initialize: function (models, options) { this.podcast = options.podcast; }, url: function () { return this.podcast.url() + '/episodes'; }, comparator: function (a, b) { return +new Date(b.get('pubDate')) - +new Date(a.get('pubDate')); } });
Our model class is called Episode
; we give it a root URL and a listen
method. The listen
method will mark the episode as listened to, by setting the listened
property to true and saving the update to the server. You'll recall that, by default, we set listened
to false
for every episode when subscribing to...