2013-06-25 09:27:09 +03:00
|
|
|
'use strict';
|
2013-06-25 02:41:59 +03:00
|
|
|
define(
|
|
|
|
[
|
|
|
|
'backbone',
|
|
|
|
'Series/EpisodeModel'
|
|
|
|
], function (Backbone, EpisodeModel) {
|
|
|
|
return Backbone.Collection.extend({
|
|
|
|
url : window.ApiRoot + '/episodes',
|
|
|
|
model: EpisodeModel,
|
2013-06-01 22:31:39 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
bySeason: function (season) {
|
|
|
|
var filtered = this.filter(function (episode) {
|
|
|
|
return episode.get('seasonNumber') === season;
|
|
|
|
});
|
2013-06-19 04:02:23 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
var EpisodeCollection = require('Series/EpisodeCollection');
|
2013-06-19 04:02:23 +03:00
|
|
|
|
2013-06-25 02:41:59 +03:00
|
|
|
return new EpisodeCollection(filtered);
|
2013-07-18 18:35:44 +03: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-06-25 02:41:59 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|