2013-06-25 06:27:09 +00:00
|
|
|
|
'use strict';
|
2013-06-24 23:41:59 +00:00
|
|
|
|
define(
|
|
|
|
|
[
|
|
|
|
|
'backbone',
|
|
|
|
|
'Series/EpisodeModel'
|
|
|
|
|
], function (Backbone, EpisodeModel) {
|
|
|
|
|
return Backbone.Collection.extend({
|
|
|
|
|
url : window.ApiRoot + '/episodes',
|
|
|
|
|
model: EpisodeModel,
|
2013-06-01 19:31:39 +00:00
|
|
|
|
|
2013-08-10 18:38:01 +00:00
|
|
|
|
state: {
|
|
|
|
|
sortKey: 'episodeNumber',
|
|
|
|
|
order : -1
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
originalFetch: Backbone.Collection.prototype.fetch,
|
|
|
|
|
|
|
|
|
|
initialize: function (options) {
|
|
|
|
|
this.seriesId = options.seriesId;
|
|
|
|
|
},
|
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
bySeason: function (season) {
|
|
|
|
|
var filtered = this.filter(function (episode) {
|
|
|
|
|
return episode.get('seasonNumber') === season;
|
|
|
|
|
});
|
2013-06-19 01:02:23 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
var EpisodeCollection = require('Series/EpisodeCollection');
|
2013-06-19 01:02:23 +00:00
|
|
|
|
|
2013-06-24 23:41:59 +00:00
|
|
|
|
return new EpisodeCollection(filtered);
|
2013-07-18 15:35:44 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
comparator: function (model1, model2) {
|
|
|
|
|
var episode1 = model1.get('episodeNumber');
|
|
|
|
|
|
|
|
|
|
var episode2 = model2.get('episodeNumber');
|
|
|
|
|
|
|
|
|
|
if (episode1 < episode2){
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (episode1 > episode2){
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2013-07-21 23:46:45 +00:00
|
|
|
|
},
|
|
|
|
|
|
2013-08-10 18:38:01 +00:00
|
|
|
|
fetch: function (options) {
|
|
|
|
|
if (!this.seriesId) {
|
|
|
|
|
throw 'seriesId is required';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!options) {
|
|
|
|
|
options = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
options['data'] = { seriesId: this.seriesId };
|
|
|
|
|
|
|
|
|
|
return this.originalFetch.call(this, options);
|
2013-06-24 23:41:59 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|