From 8d03850de71eaf23fa4940a9663146b61ebad4e1 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Sat, 7 Feb 2015 10:25:38 -0800 Subject: [PATCH] Added back version check on ajaxSuccess --- src/UI/Instrumentation/ErrorHandler.js | 1 + src/UI/Mixins/AsFilteredCollection.js | 9 +++++++++ src/UI/Shared/NzbDroneController.js | 18 +++++++++++++++++- src/UI/Shared/VersionChangeMonitor.js | 13 +++++++++++++ src/UI/jQuery/jquery.ajax.js | 25 +------------------------ src/UI/main.js | 1 + 6 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 src/UI/Shared/VersionChangeMonitor.js diff --git a/src/UI/Instrumentation/ErrorHandler.js b/src/UI/Instrumentation/ErrorHandler.js index 779218380..06a6e495f 100644 --- a/src/UI/Instrumentation/ErrorHandler.js +++ b/src/UI/Instrumentation/ErrorHandler.js @@ -34,6 +34,7 @@ module.exports = (function(){ } return false; }; + $(document).ajaxError(function(event, xmlHttpRequest, ajaxOptions){ if(xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) { return undefined; diff --git a/src/UI/Mixins/AsFilteredCollection.js b/src/UI/Mixins/AsFilteredCollection.js index e0150c4b6..d68eb9fc1 100644 --- a/src/UI/Mixins/AsFilteredCollection.js +++ b/src/UI/Mixins/AsFilteredCollection.js @@ -2,6 +2,7 @@ var _ = require('underscore'); var Backbone = require('backbone'); module.exports = function(){ + this.prototype.setFilter = function(filter, options){ options = _.extend({reset : true}, options || {}); this.state.filterKey = filter[0]; @@ -15,10 +16,13 @@ module.exports = function(){ } } }; + this.prototype.setFilterMode = function(mode, options){ return this.setFilter(this.filterModes[mode], options); }; + var originalMakeFullCollection = this.prototype._makeFullCollection; + this.prototype._makeFullCollection = function(models, options){ var self = this; self.shadowCollection = originalMakeFullCollection.call(this, models, options); @@ -30,18 +34,23 @@ module.exports = function(){ return model.get(self.state.filterKey) === self.state.filterValue; } }; + self.shadowCollection.filtered = function(){ return this.filter(filterModel); }; + var filteredModels = self.shadowCollection.filtered(); var fullCollection = originalMakeFullCollection.call(this, filteredModels, options); + fullCollection.resetFiltered = function(options){ Backbone.Collection.prototype.reset.call(this, self.shadowCollection.filtered(), options); }; + fullCollection.reset = function(models, options){ self.shadowCollection.reset(models, options); self.fullCollection.resetFiltered(); }; + return fullCollection; }; _.extend(this.prototype.state, { diff --git a/src/UI/Shared/NzbDroneController.js b/src/UI/Shared/NzbDroneController.js index c353166a9..9c9c58441 100644 --- a/src/UI/Shared/NzbDroneController.js +++ b/src/UI/Shared/NzbDroneController.js @@ -1,7 +1,9 @@ -var vent = require('../vent'); +var vent = require('../vent'); var AppLayout = require('../AppLayout'); var Marionette = require('marionette'); var NotFoundView = require('./NotFoundView'); +var Messenger = require('messenger'); + module.exports = Marionette.AppRouter.extend({ initialize : function(){ @@ -34,6 +36,20 @@ module.exports = Marionette.AppRouter.extend({ } }, _onServerUpdated : function(){ + Messenger.show({ + message : 'Sonarr has been updated', + hideAfter : 0, + id : 'droneUpdated', + actions : { + viewChanges : { + label : 'View Changes', + action : function(){ + window.location = window.NzbDrone.UrlBase + '/system/updates'; + } + } + } + }); + this.pendingUpdate = true; }, showMainRegion : function(view){ diff --git a/src/UI/Shared/VersionChangeMonitor.js b/src/UI/Shared/VersionChangeMonitor.js new file mode 100644 index 000000000..cf915b10d --- /dev/null +++ b/src/UI/Shared/VersionChangeMonitor.js @@ -0,0 +1,13 @@ +var $ = require('jquery'); +var vent = require('vent'); + +$(document).ajaxSuccess(function(event, xhr){ + var version = xhr.getResponseHeader('X-ApplicationVersion'); + if(!version || !window.NzbDrone || !window.NzbDrone.Version) { + return; + } + + if(version !== window.NzbDrone.Version) { + vent.trigger(vent.Events.ServerUpdated); + } +}); \ No newline at end of file diff --git a/src/UI/jQuery/jquery.ajax.js b/src/UI/jQuery/jquery.ajax.js index 24eded7e9..fb622707b 100644 --- a/src/UI/jQuery/jquery.ajax.js +++ b/src/UI/jQuery/jquery.ajax.js @@ -20,28 +20,5 @@ module.exports = function(){ xhr.headers['X-Api-Key'] = window.NzbDrone.ApiKey; } return original.apply(this, arguments); - /* .done(function (response, status, xhr) { - var version = xhr.getResponseHeader('X-ApplicationVersion'); - if (!window.NzbDrone || !window.NzbDrone.Version) { - return; - } - if (version !== window.NzbDrone.Version) { - var vent = require('../vent'); - var messenger = require('../Shared/Messenger'); - if (!vent || !messenger) { - return; - } - messenger.show({ - message : 'Sonarr has been updated', hideAfter : 0, id : 'droneUpdated', actions : { - viewChanges : { - label : 'View Changes', action : function () { - window.location = window.NzbDrone.UrlBase + '/system/updates'; - } - } - } - }); - vent.trigger(vent.Events.ServerUpdated); - } - });*/ }; -}; \ No newline at end of file +}; diff --git a/src/UI/main.js b/src/UI/main.js index 42342bf7a..1748c6110 100644 --- a/src/UI/main.js +++ b/src/UI/main.js @@ -17,6 +17,7 @@ require('./Instrumentation/StringFormat'); require('./LifeCycle'); require('./Hotkeys/Hotkeys'); require('./Shared/piwikCheck'); +require('./Shared/VersionChangeMonitor'); new SeriesController(); new ModalController();