2013-06-25 08:27:09 +02:00
|
|
|
|
'use strict';
|
2013-06-25 01:41:59 +02:00
|
|
|
|
define(
|
|
|
|
|
[
|
|
|
|
|
'backbone',
|
|
|
|
|
'Series/EpisodeModel'
|
|
|
|
|
], function (Backbone, EpisodeModel) {
|
|
|
|
|
return Backbone.Collection.extend({
|
|
|
|
|
url : window.ApiRoot + '/episodes',
|
|
|
|
|
model: EpisodeModel,
|
2013-06-01 21:31:39 +02:00
|
|
|
|
|
2013-08-10 20:38:01 +02:00
|
|
|
|
state: {
|
|
|
|
|
sortKey: 'episodeNumber',
|
|
|
|
|
order : -1
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
originalFetch: Backbone.Collection.prototype.fetch,
|
|
|
|
|
|
|
|
|
|
initialize: function (options) {
|
|
|
|
|
this.seriesId = options.seriesId;
|
|
|
|
|
},
|
|
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
|
bySeason: function (season) {
|
|
|
|
|
var filtered = this.filter(function (episode) {
|
|
|
|
|
return episode.get('seasonNumber') === season;
|
|
|
|
|
});
|
2013-06-19 03:02:23 +02:00
|
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
|
var EpisodeCollection = require('Series/EpisodeCollection');
|
2013-06-19 03:02:23 +02:00
|
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
|
return new EpisodeCollection(filtered);
|
2013-07-18 17:35:44 +02: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-22 01:46:45 +02:00
|
|
|
|
},
|
|
|
|
|
|
2013-08-10 20:38:01 +02: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-25 01:41:59 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|