From 83fe07524a1939ab6d00afc3db879a60dd701f36 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Tue, 16 Jul 2013 16:54:45 -0700 Subject: [PATCH] removed mutators from series. --- UI/Cells/EpisodeStatusCell.js | 4 +- .../Helpers/{EpisodeNumber.js => Episode.js} | 0 UI/Handlebars/Helpers/Quality.js | 21 +++++++ UI/Handlebars/Helpers/Series.js | 44 +++++++++++++ .../backbone.marionette.templates.js | 4 +- UI/Quality/QualityProfilePartial.html | 1 - UI/Series/Details/SeriesDetailsLayout.js | 18 +++++- UI/Series/Details/SeriesDetailsTemplate.html | 2 +- UI/Series/Edit/EditSeriesView.js | 8 +-- UI/Series/EpisodeModel.js | 3 - UI/Series/Index/List/ItemTemplate.html | 6 +- UI/Series/Index/Posters/ItemTemplate.html | 4 +- UI/Series/SeriesModel.js | 62 +------------------ 13 files changed, 97 insertions(+), 80 deletions(-) rename UI/Handlebars/Helpers/{EpisodeNumber.js => Episode.js} (100%) create mode 100644 UI/Handlebars/Helpers/Quality.js create mode 100644 UI/Handlebars/Helpers/Series.js delete mode 100644 UI/Quality/QualityProfilePartial.html diff --git a/UI/Cells/EpisodeStatusCell.js b/UI/Cells/EpisodeStatusCell.js index 889594717..f2db6ac5d 100644 --- a/UI/Cells/EpisodeStatusCell.js +++ b/UI/Cells/EpisodeStatusCell.js @@ -16,7 +16,9 @@ define( var icon; var tooltip; - if (this.model.get('episodeFile')) { + var hasAired = Date.create(this.model.get('airDate')).isBefore(Date.create()); + + if (hasAired) { icon = 'icon-ok'; tooltip = 'Episode downloaded'; } diff --git a/UI/Handlebars/Helpers/EpisodeNumber.js b/UI/Handlebars/Helpers/Episode.js similarity index 100% rename from UI/Handlebars/Helpers/EpisodeNumber.js rename to UI/Handlebars/Helpers/Episode.js diff --git a/UI/Handlebars/Helpers/Quality.js b/UI/Handlebars/Helpers/Quality.js new file mode 100644 index 000000000..6c13398a3 --- /dev/null +++ b/UI/Handlebars/Helpers/Quality.js @@ -0,0 +1,21 @@ +'use strict'; +define( + [ + 'handlebars', + 'Quality/QualityProfileCollection', + 'underscore' + ], function (Handlebars, QualityProfileCollection, _) { + + Handlebars.registerHelper('qualityProfile', function (profileId) { + + var profile = QualityProfileCollection.get(profileId); + + if (profile) { + return new Handlebars.SafeString('' + profile.get("name") + ''); + } + + return undefined; + + }); + + }); diff --git a/UI/Handlebars/Helpers/Series.js b/UI/Handlebars/Helpers/Series.js new file mode 100644 index 000000000..a47253091 --- /dev/null +++ b/UI/Handlebars/Helpers/Series.js @@ -0,0 +1,44 @@ +'use strict'; +define( + [ + 'handlebars', + 'underscore' + ], function (Handlebars, _) { + Handlebars.registerHelper('poster', function () { + + var poster = _.where(this.images, {coverType: 'poster'}); + + if (poster[0]) { + return poster[0].url; + } + + return undefined; + }); + + Handlebars.registerHelper('traktUrl', function () { + return 'http://trakt.tv/show/' + this.titleSlug; + }); + + Handlebars.registerHelper('imdbUrl', function () { + return 'http://imdb.com/title/' + this.imdbId; + }); + + Handlebars.registerHelper('route', function () { + return '/series/' + this.titleSlug; + }); + + + Handlebars.registerHelper('percentOfEpisodes', function () { + var episodeCount = this.episodeCount; + var episodeFileCount = this.episodeFileCount; + + var percent = 100; + + if (episodeCount > 0) { + percent = episodeFileCount / episodeCount * 100; + } + + return percent; + }); + + }); diff --git a/UI/Handlebars/backbone.marionette.templates.js b/UI/Handlebars/backbone.marionette.templates.js index 697d51d9a..d51fa431e 100644 --- a/UI/Handlebars/backbone.marionette.templates.js +++ b/UI/Handlebars/backbone.marionette.templates.js @@ -6,7 +6,9 @@ define( 'Handlebars/Helpers/DateTime', 'Handlebars/Helpers/Html', 'Handlebars/Helpers/Numbers', - 'Handlebars/Helpers/EpisodeNumber', + 'Handlebars/Helpers/Episode', + 'Handlebars/Helpers/Series', + 'Handlebars/Helpers/Quality', 'Handlebars/Debug' ], function (Templates) { return function () { diff --git a/UI/Quality/QualityProfilePartial.html b/UI/Quality/QualityProfilePartial.html deleted file mode 100644 index 5f622ffad..000000000 --- a/UI/Quality/QualityProfilePartial.html +++ /dev/null @@ -1 +0,0 @@ -{{name}} diff --git a/UI/Series/Details/SeriesDetailsLayout.js b/UI/Series/Details/SeriesDetailsLayout.js index 5ea61d48c..be1f69579 100644 --- a/UI/Series/Details/SeriesDetailsLayout.js +++ b/UI/Series/Details/SeriesDetailsLayout.js @@ -44,8 +44,10 @@ define( onShow: function () { var self = this; - if (this.model.has('fanArt')) { - $.backstretch(this.model.get('fanArt')); + var fanArt = this._getFanArt(); + + if (fanArt) { + $.backstretch(fanArt); } else { $('body').removeClass('backdrop'); @@ -67,6 +69,16 @@ define( this._setMonitoredState(); }, + _getFanArt: function () { + var fanArt = _.where(this.model.get('images'), {coverType: 'fanart'}); + + if(fanArt && fanArt[0]){ + return fanArt[0].url; + } + + return undefined; + }, + onClose: function () { $('.backstretch').remove(); $('body').removeClass('backdrop'); @@ -81,7 +93,7 @@ define( var promise = this.model.save(); - promise.always(function (){ + promise.always(function () { self._setMonitoredState(); }); }, diff --git a/UI/Series/Details/SeriesDetailsTemplate.html b/UI/Series/Details/SeriesDetailsTemplate.html index a506716e3..87a79b6f8 100644 --- a/UI/Series/Details/SeriesDetailsTemplate.html +++ b/UI/Series/Details/SeriesDetailsTemplate.html @@ -14,7 +14,7 @@ {{overview}}
- {{> QualityProfilePartial qualityProfile}} + {{qualityProfile qualityProfileId}} {{network}} {{runtime}} minutes {{path}} diff --git a/UI/Series/Edit/EditSeriesView.js b/UI/Series/Edit/EditSeriesView.js index 4f8e6154e..640c76adb 100644 --- a/UI/Series/Edit/EditSeriesView.js +++ b/UI/Series/Edit/EditSeriesView.js @@ -29,17 +29,15 @@ define( saveSeries: function () { - //Todo: Get qualityProfile - var qualityProfile = this.ui.qualityProfile.val(); - var qualityProfileText = this.ui.qualityProfile.children('option:selected').text(); - this.model.set({ qualityProfileId: qualityProfile, qualityProfileName: qualityProfileText }); + var qualityProfileId = this.ui.qualityProfile.val(); + this.model.set({ qualityProfileId: qualityProfileId}); this.model.save(); this.trigger('saved'); App.modalRegion.closeModal(); - }, + }, onRender: function () { this.ui.path.autoComplete('/directories'); diff --git a/UI/Series/EpisodeModel.js b/UI/Series/EpisodeModel.js index 71580ca68..eb486af9a 100644 --- a/UI/Series/EpisodeModel.js +++ b/UI/Series/EpisodeModel.js @@ -55,9 +55,6 @@ define( } return 'primary'; - }, - hasAired : function () { - return Date.create(this.get('airDate')).isBefore(Date.create()); } }, diff --git a/UI/Series/Index/List/ItemTemplate.html b/UI/Series/Index/List/ItemTemplate.html index ec1f981ea..efef7cd83 100644 --- a/UI/Series/Index/List/ItemTemplate.html +++ b/UI/Series/Index/List/ItemTemplate.html @@ -29,7 +29,7 @@
 
- {{#if isContinuing}} + {{#if_eq status compare="continuing"}} {{#if nextAiring}} {{ShortDate nextAiring}} {{/if}} @@ -37,9 +37,9 @@ {{else}} Ended {{seasonCount}} Seasons - {{/if}} + {{/if_eq}} - {{> QualityProfilePartial qualityProfile}} + {{qualityProfile qualityProfileId}}
diff --git a/UI/Series/Index/Posters/ItemTemplate.html b/UI/Series/Index/Posters/ItemTemplate.html index df56bab8e..8972c56cf 100644 --- a/UI/Series/Index/Posters/ItemTemplate.html +++ b/UI/Series/Index/Posters/ItemTemplate.html @@ -7,9 +7,9 @@
- {{#unless isContinuing}} + {{#unless_eq status compare="continuing"}}
Ended
- {{/unless}} + {{/unless_eq}} diff --git a/UI/Series/SeriesModel.js b/UI/Series/SeriesModel.js index 4af8715a9..075e0fc80 100644 --- a/UI/Series/SeriesModel.js +++ b/UI/Series/SeriesModel.js @@ -2,71 +2,13 @@ define( [ 'backbone', - 'Quality/QualityProfileCollection', + 'underscore' - ], function (Backbone, QualityProfileCollection,_) { + ], function (Backbone, _) { return Backbone.Model.extend({ urlRoot: ApiRoot + '/series', - mutators: { - percentOfEpisodes: function () { - var episodeCount = this.get('episodeCount'); - var episodeFileCount = this.get('episodeFileCount'); - - var percent = 100; - - if (episodeCount > 0) { - percent = episodeFileCount / episodeCount * 100; - } - - return percent; - }, - poster : function () { - var poster = _.find(this.get('images'), function (image) { - return image.coverType === 'poster'; - }); - - if (poster) { - return poster.url; - } - - return undefined; - }, - fanArt : function () { - var poster = _.find(this.get('images'), function (image) { - return image.coverType === 'fanart'; - }); - - if (poster) { - return poster.url; - } - - return undefined; - }, - traktUrl : function () { - return 'http://trakt.tv/show/' + this.get('titleSlug'); - }, - imdbUrl : function () { - return 'http://imdb.com/title/' + this.get('imdbId'); - }, - isContinuing : function () { - return this.get('status') === 'continuing'; - }, - route : function () { - return '/series/' + this.get('titleSlug'); - }, - - qualityProfile: function () { - var profile = QualityProfileCollection.get(this.get('qualityProfileId')); - if (profile) { - return profile.toJSON(); - } - - return undefined; - } - }, - defaults: { episodeFileCount: 0, episodeCount : 0,