2013-06-22 08:24:24 +02:00
|
|
|
'use strict';
|
2013-06-25 01:41:59 +02:00
|
|
|
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 20:13:23 +01:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (start.format('{mm}') === '00') {
|
|
|
|
return start.format('{h}{tt}');
|
|
|
|
}
|
2013-05-01 03:54:15 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
return start.format('{h}.{mm}{tt}');
|
|
|
|
},
|
|
|
|
end : function () {
|
2013-05-01 03:54:15 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (this.has('series')) {
|
|
|
|
var start = Date.create(this.get('airDate'));
|
|
|
|
var runtime = this.get('series').runtime;
|
2013-06-05 03:04:34 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
return start.addMinutes(runtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
},
|
|
|
|
statusLevel : function () {
|
|
|
|
var episodeFileId = this.get('episodeFileId');
|
|
|
|
var currentTime = Date.create();
|
2013-06-05 03:04:34 +02:00
|
|
|
var start = Date.create(this.get('airDate'));
|
2013-06-25 01:41:59 +02:00
|
|
|
var end = Date.create(this.get('end'));
|
2013-06-04 08:10:41 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (currentTime.isBetween(start, end)) {
|
|
|
|
return 'warning';
|
|
|
|
}
|
2013-05-01 03:54:15 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (start.isBefore(currentTime) && episodeFileId === 0) {
|
|
|
|
return 'danger';
|
|
|
|
}
|
2013-05-01 03:54:15 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (status === 'Ready') {
|
|
|
|
return 'success';
|
|
|
|
}
|
2013-05-01 03:54:15 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
return 'primary';
|
|
|
|
},
|
|
|
|
hasAired : function () {
|
|
|
|
return Date.create(this.get('airDate')).isBefore(Date.create());
|
|
|
|
}
|
2013-05-20 23:06:01 +02:00
|
|
|
},
|
2013-03-02 20:13:23 +01:00
|
|
|
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
parse: function (model) {
|
|
|
|
model.series = new SeriesModel(model.series);
|
|
|
|
|
|
|
|
return model;
|
|
|
|
},
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
toJSON: function () {
|
|
|
|
var json = _.clone(this.attributes);
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
_.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-10 07:27:20 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (this.has('series')) {
|
|
|
|
json.series = this.get('series').toJSON();
|
2013-06-10 07:27:20 +02:00
|
|
|
}
|
2013-06-25 01:41:59 +02:00
|
|
|
return json;
|
|
|
|
},
|
2013-06-10 04:10:15 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
defaults: {
|
|
|
|
seasonNumber: 0,
|
2013-06-29 00:12:57 +02:00
|
|
|
status : 0,
|
|
|
|
title : 'TBA'
|
2013-06-25 01:41:59 +02:00
|
|
|
}
|
|
|
|
});
|
2013-03-02 20:13:23 +01:00
|
|
|
});
|