Removed mutators from EpisodeModel

pull/24/head
Mark McDowall 11 years ago
parent 83fe07524a
commit e164df217d

@ -60,12 +60,14 @@ define(
var episodeTitle = element.get('title');
var seriesTitle = element.get('series').get('title');
var start = element.get('airDate');
var statusLevel = _instance.getStatusLevel(element);
element.set({
'title': seriesTitle,
title : seriesTitle,
episodeTitle: episodeTitle,
start : start,
allDay: false
allDay : false,
statusLevel : statusLevel
});
element.set('model', element);
@ -74,6 +76,27 @@ define(
callback(calendarCollection.toJSON());
}
});
},
getStatusLevel: function (element) {
var hasFile = element.get('hasFile');
var currentTime = Date.create();
var start = Date.create(element.get('airDate'));
var end = Date.create(element.get('end'));
if (currentTime.isBetween(start, end)) {
return 'warning';
}
if (start.isBefore(currentTime) && !hasFile) {
return 'danger';
}
if (hasFile) {
return 'success';
}
return 'primary';
}
});
});

@ -1,11 +1,11 @@
<div class="event">
<div class="date {{statusLevel}}">
<h1>{{day}}</h1>
<h4>{{month}}</h4>
<div class="date {{StatusLevel}}">
<h1>{{Day airDate}}</h1>
<h4>{{Month airDate}}</h4>
</div>
<a href="{{series.route}}">
<h4>{{series.title}}</h4>
</a>
<p>{{startTime}} {{ShortDate airDate}}<span class="pull-right">{{seasonNumber}}x{{paddedEpisodeNumber}}</span><br>{{episodeTitle}}</p>
<p>{{StartTime airDate}} {{ShortDate airDate}}<span class="pull-right">{{seasonNumber}}x{{Pad2 episodeNumber}}</span><br>{{episodeTitle}}</p>
<p class="episode-title x-episode-title">{{title}}</p>
</div>

@ -3,9 +3,9 @@
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
{{#if episodeTitle}}
<h3>{{episodeTitle}} - {{episodeNumberHelper}}</h3>
<h3>{{episodeTitle}} - {{EpisodeNumber}}</h3>
{{else}}
<h3>{{title}} - {{episodeNumberHelper}}</h3>
<h3>{{title}} - {{EpisodeNumber}}</h3>
{{/if}}
</div>
<div class="modal-body">

@ -14,4 +14,33 @@ define(
return new Handlebars.SafeString(result);
});
Handlebars.registerHelper('Day', function (input) {
if (!input) {
return '';
}
return Date.create(input).format('{dd}');
});
Handlebars.registerHelper('Month', function (input) {
if (!input) {
return '';
}
return Date.create(input).format('{Mon}');
});
Handlebars.registerHelper('StartTime', function (input) {
if (!input) {
return '';
}
var date = Date.create(input);
if (date.format('{mm}') === '00') {
return date.format('{h}{tt}');
}
return date.format('{h}.{mm}{tt}');
});
});

@ -4,15 +4,38 @@ define(
'handlebars',
'Shared/FormatHelpers'
], function (Handlebars, FormatHelpers) {
Handlebars.registerHelper('episodeNumberHelper', function () {
Handlebars.registerHelper('EpisodeNumber', function () {
if (this.series.seriesType === 'daily') {
return FormatHelpers.DateHelper(this.airDate);
}
else {
return '{0}x{1}'.format(this.seasonNumber, this.paddedEpisodeNumber);
return '{0}x{1}'.format(this.seasonNumber, this.episodeNumber.pad(2));
}
});
Handlebars.registerHelper('StatusLevel', function () {
var hasFile = this.hasFile;
var currentTime = Date.create();
var start = Date.create(this.airDate);
var end = Date.create(this.end);
if (currentTime.isBetween(start, end)) {
return 'warning';
}
if (start.isBefore(currentTime) && !hasFile) {
return 'danger';
}
if (hasFile) {
return 'success';
}
return 'primary';
});
});

@ -7,4 +7,8 @@ define(
Handlebars.registerHelper('Bytes', function (size) {
return new Handlebars.SafeString(FormatHelpers.Bytes(size));
});
Handlebars.registerHelper('Pad2', function (input) {
return input.pad(2);
});
});

@ -11,7 +11,7 @@ define(
var profile = QualityProfileCollection.get(profileId);
if (profile) {
return new Handlebars.SafeString('<span class="label quality-profile-lable">' + profile.get("name") + '</span>');
return new Handlebars.SafeString('<span class="label quality-profile-label">' + profile.get("name") + '</span>');
}
return undefined;

@ -6,59 +6,15 @@ define(
], 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'));
if (start.format('{mm}') === '00') {
return start.format('{h}{tt}');
}
return start.format('{h}.{mm}{tt}');
},
end : function () {
initialize: function () {
if (this.has('series')) {
var start = Date.create(this.get('airDate'));
var runtime = this.get('series').get('runtime');
return start.addMinutes(runtime);
}
return undefined;
},
statusLevel : function () {
var hasFile = this.get('hasFile');
var currentTime = Date.create();
var start = Date.create(this.get('airDate'));
var end = Date.create(this.get('end'));
if (currentTime.isBetween(start, end)) {
return 'warning';
}
if (start.isBefore(currentTime) && !hasFile) {
return 'danger';
}
if (hasFile) {
return 'success';
}
return 'primary';
this.set('end', start.addMinutes(runtime));
}
},
parse: function (model) {
model.series = new SeriesModel(model.series);
@ -68,16 +24,6 @@ define(
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();
}

Loading…
Cancel
Save