2013-06-22 08:24:24 +02:00
|
|
|
'use strict';
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
define(
|
|
|
|
[
|
2013-07-17 08:23:44 +02:00
|
|
|
'Cells/NzbDroneCell',
|
|
|
|
'Shared/FormatHelpers'
|
|
|
|
], function (NzbDroneCell, FormatHelpers) {
|
2013-06-25 01:41:59 +02:00
|
|
|
return NzbDroneCell.extend({
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
className: 'episode-number-cell',
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
render: function () {
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
this.$el.empty();
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
var airDateField = this.column.get('airDate') || 'airDate';
|
|
|
|
var seasonField = this.column.get('seasonNumber') || 'seasonNumber';
|
|
|
|
var episodeField = this.column.get('episodes') || 'episodeNumber';
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (this.cellValue) {
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
var airDate = this.cellValue.get(airDateField);
|
|
|
|
var seasonNumber = this.cellValue.get(seasonField);
|
|
|
|
var episodes = this.cellValue.get(episodeField);
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
var result = 'Unknown';
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (episodes) {
|
2013-06-10 04:10:15 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
var paddedEpisodes;
|
2013-06-09 22:51:32 +02:00
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
if (episodes.constructor === Array) {
|
|
|
|
paddedEpisodes = _.map(episodes,function (episodeNumber) {
|
2013-07-17 08:23:44 +02:00
|
|
|
return FormatHelpers.pad(episodeNumber, 2);
|
2013-06-25 01:41:59 +02:00
|
|
|
}).join();
|
|
|
|
}
|
|
|
|
else {
|
2013-07-17 08:23:44 +02:00
|
|
|
paddedEpisodes = FormatHelpers.pad(episodes, 2);
|
2013-06-25 01:41:59 +02:00
|
|
|
}
|
|
|
|
|
2013-07-17 08:23:44 +02:00
|
|
|
result = '{0}x{1}'.format(seasonNumber, paddedEpisodes);
|
2013-06-10 04:10:15 +02:00
|
|
|
}
|
2013-06-25 01:41:59 +02:00
|
|
|
else if (airDate) {
|
|
|
|
result = new Date(airDate).toLocaleDateString();
|
2013-06-10 04:10:15 +02:00
|
|
|
}
|
|
|
|
|
2013-06-25 01:41:59 +02:00
|
|
|
this.$el.html(result);
|
2013-06-10 04:10:15 +02:00
|
|
|
}
|
2013-06-25 01:41:59 +02:00
|
|
|
this.delegateEvents();
|
|
|
|
return this;
|
2013-06-10 04:10:15 +02:00
|
|
|
}
|
2013-06-25 01:41:59 +02:00
|
|
|
});
|
2013-06-09 22:51:32 +02:00
|
|
|
});
|