From 8e2364966a022cd75cb4e7c641a40c1879d4f77a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 21 Aug 2013 14:47:39 -0700 Subject: [PATCH] Less model pollution --- UI/Calendar/CalendarView.js | 5 ++++- UI/Cells/EpisodeStatusCell.js | 6 +++--- UI/Cells/EpisodeTitleCell.js | 4 +++- UI/Episode/Layout.js | 15 +++++++++++++-- UI/Episode/LayoutTemplate.html | 1 + UI/Series/Details/SeasonLayout.js | 5 +---- UI/Series/EpisodeModel.js | 19 ------------------- UI/Shared/Modal/Controller.js | 2 +- 8 files changed, 26 insertions(+), 31 deletions(-) diff --git a/UI/Calendar/CalendarView.js b/UI/Calendar/CalendarView.js index 042960ca1..4c85e7325 100644 --- a/UI/Calendar/CalendarView.js +++ b/UI/Calendar/CalendarView.js @@ -57,14 +57,17 @@ define( success: function (calendarCollection) { _.each(calendarCollection.models, function (element) { var episodeTitle = element.get('title'); - var seriesTitle = element.get('series').get('title'); + var seriesTitle = element.get('series').title; var start = element.get('airDateUtc'); var statusLevel = _instance.getStatusLevel(element); + var runtime = element.get('series').runtime; + var end = Moment(start).add('minutes', runtime); element.set({ title : seriesTitle, episodeTitle: episodeTitle, start : start, + end : end, allDay : false, statusLevel : statusLevel }); diff --git a/UI/Cells/EpisodeStatusCell.js b/UI/Cells/EpisodeStatusCell.js index 3f335cefa..36ab0b72d 100644 --- a/UI/Cells/EpisodeStatusCell.js +++ b/UI/Cells/EpisodeStatusCell.js @@ -2,11 +2,11 @@ define( [ - 'backgrid', + 'Cells/NzbDroneCell', 'moment', 'Shared/FormatHelpers' - ], function (Backgrid, Moment, FormatHelpers) { - return Backgrid.Cell.extend({ + ], function (NzbDroneCell, Moment, FormatHelpers) { + return NzbDroneCell.extend({ className: 'episode-status-cell', diff --git a/UI/Cells/EpisodeTitleCell.js b/UI/Cells/EpisodeTitleCell.js index 578952623..f5e2651c9 100644 --- a/UI/Cells/EpisodeTitleCell.js +++ b/UI/Cells/EpisodeTitleCell.js @@ -25,7 +25,9 @@ define( }, _showDetails: function () { - App.vent.trigger(App.Commands.ShowEpisodeDetails, {episode: this.cellValue}); + var hideSeriesLink = this.column.get('hideSeriesLink'); + + App.vent.trigger(App.Commands.ShowEpisodeDetails, {episode: this.cellValue, hideSeriesLink: hideSeriesLink }); } }); }); diff --git a/UI/Episode/Layout.js b/UI/Episode/Layout.js index bfb75aca9..15f819a48 100644 --- a/UI/Episode/Layout.js +++ b/UI/Episode/Layout.js @@ -3,8 +3,9 @@ define( [ 'marionette', 'Episode/Summary/Layout', - 'Episode/Search/Layout' - ], function (Marionette, SummaryLayout, SearchLayout) { + 'Episode/Search/Layout', + 'Series/SeriesCollection' + ], function (Marionette, SummaryLayout, SearchLayout, SeriesCollection) { return Marionette.Layout.extend({ template: 'Episode/LayoutTemplate', @@ -30,6 +31,16 @@ define( 'click .x-episode-monitored': '_toggleMonitored' }, + templateHelpers: {}, + + initialize: function (options) { + this.templateHelpers.hideSeriesLink = options.hideSeriesLink; + + var series = SeriesCollection.find({ id: this.model.get('seriesId') }); + this.templateHelpers.series = series.toJSON(); + var test = 1; + }, + onShow: function () { this._showSummary(); this.searchLayout = new SearchLayout({ model: this.model }); diff --git a/UI/Episode/LayoutTemplate.html b/UI/Episode/LayoutTemplate.html index 982110d6a..c93e1f98c 100644 --- a/UI/Episode/LayoutTemplate.html +++ b/UI/Episode/LayoutTemplate.html @@ -3,6 +3,7 @@

+ {{debug}} {{#if episodeTitle}} {{title}} - {{EpisodeNumber}} - {{episodeTitle}} diff --git a/UI/Series/Details/SeasonLayout.js b/UI/Series/Details/SeasonLayout.js index 8fc7464a1..1244050e8 100644 --- a/UI/Series/Details/SeasonLayout.js +++ b/UI/Series/Details/SeasonLayout.js @@ -50,6 +50,7 @@ define( { name : 'this', label : 'Title', + hideSeriesLink : true, cell : EpisodeTitleCell, sortable: false }, @@ -74,10 +75,6 @@ define( this.episodeCollection = options.episodeCollection.bySeason(this.model.get('seasonNumber')); - _.each(this.episodeCollection.models, function (episode) { - episode.set({ hideSeriesLink: true, series: options.series }); - }); - this.listenTo(this.model, 'sync', function () { this._afterSeasonMonitored(); }, this); diff --git a/UI/Series/EpisodeModel.js b/UI/Series/EpisodeModel.js index 713ded3ee..d5f4a19d7 100644 --- a/UI/Series/EpisodeModel.js +++ b/UI/Series/EpisodeModel.js @@ -8,17 +8,7 @@ define( ], function (Backbone, Moment, SeriesModel, EpisodeFileModel) { return Backbone.Model.extend({ - initialize: function () { - if (this.has('series')) { - var start = Moment(this.get('airDateUtc')); - var runtime = this.get('series').get('runtime'); - - this.set('end', start.add('minutes', runtime)); - } - }, - parse: function (model) { - model.series = new SeriesModel(model.series); if (model.episodeFile) { model.episodeFile = new EpisodeFileModel(model.episodeFile); @@ -27,15 +17,6 @@ define( return model; }, - toJSON: function () { - var json = _.clone(this.attributes); - - if (this.has('series')) { - json.series = this.get('series').toJSON(); - } - return json; - }, - defaults: { seasonNumber: 0, status : 0 diff --git a/UI/Shared/Modal/Controller.js b/UI/Shared/Modal/Controller.js index 535a39b5e..eaa475b1a 100644 --- a/UI/Shared/Modal/Controller.js +++ b/UI/Shared/Modal/Controller.js @@ -33,7 +33,7 @@ define( }, _showEpisode: function (options) { - var view = new EpisodeLayout({ model: options.episode }); + var view = new EpisodeLayout({ model: options.episode, hideSeriesLink: options.hideSeriesLink }); App.modalRegion.show(view); } });