From 3a3a4fb1f3973ac275a4080ad8ca5c80656db822 Mon Sep 17 00:00:00 2001 From: Ruud Date: Tue, 25 Sep 2012 23:11:27 +0200 Subject: [PATCH] Cleanup javascript events on movie delete --- couchpotato/core/plugins/movie/static/list.js | 12 +++++++----- couchpotato/core/plugins/movie/static/movie.js | 23 +++++++++++++++++++++-- couchpotato/core/plugins/movie/static/search.js | 2 +- couchpotato/static/scripts/page/wanted.js | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/couchpotato/core/plugins/movie/static/list.js b/couchpotato/core/plugins/movie/static/list.js index 38fc710..0aff0bd 100644 --- a/couchpotato/core/plugins/movie/static/list.js +++ b/couchpotato/core/plugins/movie/static/list.js @@ -86,18 +86,18 @@ var MovieList = new Class({ Object.each(movies, function(movie){ self.createMovie(movie); }); - + self.setCounter(total); }, - + setCounter: function(count){ var self = this; - + if(!self.navigation_counter) return; - + self.navigation_counter.set('text', (count || 0)); - + }, createMovie: function(movie, inject_at){ @@ -309,6 +309,8 @@ var MovieList = new Class({ erase_movies.each(function(movie){ self.movies.erase(movie); + + movie.destroy() }); self.calculateSelected(); diff --git a/couchpotato/core/plugins/movie/static/movie.js b/couchpotato/core/plugins/movie/static/movie.js index abaea65..f5cd41e 100644 --- a/couchpotato/core/plugins/movie/static/movie.js +++ b/couchpotato/core/plugins/movie/static/movie.js @@ -16,16 +16,35 @@ var Movie = new Class({ self.profile = Quality.getProfile(data.profile_id) || {}; self.parent(self, options); - App.addEvent('movie.update.'+data.id, self.update.bind(self)); + self.addEvents(); + }, + + addEvents: function(){ + var self = this; + + App.addEvent('movie.update.'+self.data.id, self.update.bind(self)); ['movie.busy', 'searcher.started'].each(function(listener){ - App.addEvent(listener+'.'+data.id, function(notification){ + App.addEvent(listener+'.'+self.data.id, function(notification){ if(notification.data) self.busy(true) }); }) }, + destroy: function(){ + var self = this; + + self.el.destroy(); + delete self.list.movies_added[self.get('id')]; + + // Remove events + App.removeEvents('movie.update.'+self.data.id); + ['movie.busy', 'searcher.started'].each(function(listener){ + App.removeEvents(listener+'.'+self.data.id); + }) + }, + busy: function(set_busy){ var self = this; diff --git a/couchpotato/core/plugins/movie/static/search.js b/couchpotato/core/plugins/movie/static/search.js index 6c6c94e..63cab34 100644 --- a/couchpotato/core/plugins/movie/static/search.js +++ b/couchpotato/core/plugins/movie/static/search.js @@ -324,7 +324,7 @@ Block.Search.Item = new Class({ var self = this; if(!self.options.hasClass('set')){ - + if(self.info.in_library){ var in_library = []; self.info.in_library.releases.each(function(release){ diff --git a/couchpotato/static/scripts/page/wanted.js b/couchpotato/static/scripts/page/wanted.js index 3ef10d7..a50b1bd 100644 --- a/couchpotato/static/scripts/page/wanted.js +++ b/couchpotato/static/scripts/page/wanted.js @@ -222,7 +222,7 @@ window.addEvent('domready', function(){ movie.set('tween', { 'duration': 300, 'onComplete': function(){ - movie.destroy(); + self.movie.destroy() } }); movie.tween('height', 0);