From 69c680ed8705b70698947ceb9beba478b978c62f Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 21 Aug 2014 00:19:00 -0700 Subject: [PATCH] Clear episode file change event in episode status cell --- src/UI/Cells/EpisodeStatusCell.js | 47 +++++++++++++++++++++---------- src/UI/Mixins/AsEditModalView.js | 4 ++- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/UI/Cells/EpisodeStatusCell.js b/src/UI/Cells/EpisodeStatusCell.js index 34a492b5e..494be0195 100644 --- a/src/UI/Cells/EpisodeStatusCell.js +++ b/src/UI/Cells/EpisodeStatusCell.js @@ -22,6 +22,11 @@ define( }, _renderCell: function () { + + if (this.episodeFile) { + this.stopListening(this.episodeFile, 'change', this._refresh); + } + this.$el.empty(); if (this.model) { @@ -30,23 +35,13 @@ define( var tooltip; var hasAired = moment(this.model.get('airDateUtc')).isBefore(moment()); - var hasFile = this.model.get('hasFile'); + this.episodeFile = this._getFile(); - if (hasFile) { - var episodeFile; + if (this.episodeFile) { + this.listenTo(this.episodeFile, 'change', this._refresh); - if (reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) { - episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, this.model.get('episodeFileId')); - } - - else { - episodeFile = new Backbone.Model(this.model.get('episodeFile')); - } - - this.listenTo(episodeFile, 'change', this._refresh); - - var quality = episodeFile.get('quality'); - var size = FormatHelpers.bytes(episodeFile.get('size')); + var quality = this.episodeFile.get('quality'); + var size = FormatHelpers.bytes(this.episodeFile.get('size')); var title = 'Episode downloaded'; if (quality.proper) { @@ -103,6 +98,28 @@ define( this.$el.html(''.format(icon, tooltip)); } + }, + + _getFile: function () { + var hasFile = this.model.get('hasFile'); + + if (hasFile) { + var episodeFile; + + if (reqres.hasHandler(reqres.Requests.GetEpisodeFileById)) { + episodeFile = reqres.request(reqres.Requests.GetEpisodeFileById, this.model.get('episodeFileId')); + } + + else { + episodeFile = new Backbone.Model(this.model.get('episodeFile')); + } + + if (episodeFile) { + return episodeFile; + } + } + + return undefined; } }); }); diff --git a/src/UI/Mixins/AsEditModalView.js b/src/UI/Mixins/AsEditModalView.js index 97b26be49..bda5d10f1 100644 --- a/src/UI/Mixins/AsEditModalView.js +++ b/src/UI/Mixins/AsEditModalView.js @@ -20,7 +20,9 @@ define( var promise = this.model.save(); promise.always(function () { - self.ui.indicator.hide(); + if (!self.isClosed) { + self.ui.indicator.hide(); + } }); promise.done(function () {