1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-07-01 00:45:18 +02:00
Files
Sonarr/UI/Series/EpisodeModel.js

93 lines
2.9 KiB
JavaScript
Raw Normal View History

"use strict";
2013-06-09 19:10:15 -07:00
define(['app', 'Series/SeriesModel'], function () {
2013-03-03 14:42:26 -08:00
NzbDrone.Series.EpisodeModel = Backbone.Model.extend({
2013-03-02 11:13:23 -08:00
mutators: {
2013-04-30 17:25:33 -07:00
paddedEpisodeNumber: function () {
var test = this.get('episodeNumber');
2013-05-10 15:33:04 -07:00
return this.get('episodeNumber').pad(2);
2013-04-30 18:54:15 -07:00
},
day : function () {
return Date.create(this.get('airDate')).format('{dd}');
},
month : function () {
return Date.create(this.get('airDate')).format('{MON}');
},
startTime : function () {
var start = Date.create(this.get('airDate'));
if (start.format('{mm}') === '00') {
return start.format('{h}{tt}');
}
return start.format('{h}.{mm}{tt}');
},
2013-06-04 18:04:34 -07:00
end : function () {
if (this.has('series')) {
var start = Date.create(this.get('airDate'));
var runtime = this.get('series').runtime;
2013-06-03 23:10:41 -07:00
2013-06-04 18:04:34 -07:00
return start.addMinutes(runtime);
}
2013-06-03 23:10:41 -07:00
},
2013-04-30 18:54:15 -07:00
statusLevel : function () {
2013-06-03 23:10:41 -07:00
var episodeFileId = this.get('episodeFileId');
2013-04-30 18:54:15 -07:00
var currentTime = Date.create();
2013-06-03 23:10:41 -07:00
var start = Date.create(this.get('airDate'));
2013-04-30 18:54:15 -07:00
var end = Date.create(this.get('end'));
if (currentTime.isBetween(start, end)) {
return 'warning';
}
2013-06-03 23:10:41 -07:00
if (start.isBefore(currentTime) && episodeFileId === 0) {
2013-04-30 18:54:15 -07:00
return 'danger';
}
if (status === 'Ready') {
return 'success';
}
return 'primary';
2013-05-20 14:06:01 -07:00
},
hasAired : function () {
return Date.create(this.get('airDate')).isBefore(Date.create());
2013-04-30 17:25:33 -07:00
}
2013-03-02 11:13:23 -08:00
},
parse: function (model) {
model.series = new NzbDrone.Series.SeriesModel(model.series);
return model;
},
2013-06-09 19:10:15 -07:00
toJSON: function () {
var json = _.clone(this.attributes);
_.each(this.mutators, _.bind(function (mutator, name) {
// check if we have some getter mutations
if (_.isObject(this.mutators[name]) === true && _.isFunction(this.mutators[name].get)) {
json[name] = _.bind(this.mutators[name].get, this)();
} else {
json[name] = _.bind(this.mutators[name], this)();
}
}, this));
2013-06-09 22:37:41 -07:00
if (this.has('series'))
{
json.series = this.get('series').toJSON();
}
2013-06-09 19:10:15 -07:00
return json;
},
2013-03-02 11:13:23 -08:00
defaults: {
2013-04-30 18:54:15 -07:00
seasonNumber: 0,
2013-05-20 14:06:01 -07:00
status : 0
2013-03-02 11:13:23 -08:00
}
});
2013-06-18 18:02:23 -07:00
return NzbDrone.Series.EpisodeModel;
2013-03-02 11:13:23 -08:00
});