1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 02:07:41 +00:00
Sonarr/UI/Series/EpisodeModel.js

99 lines
3.2 KiB
JavaScript
Raw Normal View History

2013-06-22 06:24:24 +00:00
'use strict';
define(
[
'backbone',
'Series/SeriesModel'
], function (Backbone, SeriesModel) {
return Backbone.Model.extend({
mutators: {
paddedEpisodeNumber: function () {
return this.get('episodeNumber').pad(2);
},
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'));
2013-03-02 19:13:23 +00:00
if (start.format('{mm}') === '00') {
return start.format('{h}{tt}');
}
2013-05-01 01:54:15 +00:00
return start.format('{h}.{mm}{tt}');
},
end : function () {
2013-05-01 01:54:15 +00:00
if (this.has('series')) {
var start = Date.create(this.get('airDate'));
2013-07-08 06:39:19 +00:00
var runtime = this.get('series').get('runtime');
2013-06-05 01:04:34 +00:00
return start.addMinutes(runtime);
}
return undefined;
},
statusLevel : function () {
2013-07-08 06:39:19 +00:00
var hasFile = this.get('hasFile');
var currentTime = Date.create();
2013-06-05 01:04:34 +00:00
var start = Date.create(this.get('airDate'));
var end = Date.create(this.get('end'));
2013-06-04 06:10:41 +00:00
2013-07-08 06:39:19 +00:00
console.log(this.get('end'));
if (currentTime.isBetween(start, end)) {
return 'warning';
}
2013-05-01 01:54:15 +00:00
2013-07-08 06:39:19 +00:00
if (start.isBefore(currentTime) && !hasFile) {
return 'danger';
}
2013-05-01 01:54:15 +00:00
2013-07-08 06:39:19 +00:00
if (hasFile) {
return 'success';
}
2013-05-01 01:54:15 +00:00
return 'primary';
},
hasAired : function () {
return Date.create(this.get('airDate')).isBefore(Date.create());
}
2013-05-20 21:06:01 +00:00
},
2013-03-02 19:13:23 +00:00
parse: function (model) {
model.series = new SeriesModel(model.series);
return model;
},
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));
if (this.has('series')) {
json.series = this.get('series').toJSON();
}
return json;
},
2013-06-10 02:10:15 +00:00
defaults: {
seasonNumber: 0,
status : 0
}
});
2013-03-02 19:13:23 +00:00
});