From 6f8c73771d979f0057dde40a0046362994728ca4 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Tue, 18 Jun 2013 18:02:23 -0700 Subject: [PATCH] settings is fully moved to required. --- UI/Cells/NzbDroneCell.js | 2 +- UI/Controller.js | 24 ++-- UI/History/EventTypeCell.js | 12 +- UI/Mixins/AsChangeTrackingModel.js | 31 +++++ UI/Mixins/AsModelBoundView.js | 37 ++++++ UI/Mixins/AsNamedView.js | 38 ++++++ UI/Mixins/SaveIfChangedModel.js | 31 ----- UI/Mixins/backbone.modelbinder.mixin.js | 47 -------- UI/Quality/QualitySizeCollection.js | 2 + UI/Series/Delete/DeleteSeriesView.js | 3 + UI/Series/EpisodeCollection.js | 3 + UI/Series/EpisodeModel.js | 2 + UI/Series/Index/EmptySeriesIndexView.js | 2 + UI/Series/Index/EmptyView.js | 2 + UI/Series/Index/List/CollectionView.js | 2 + UI/Series/Index/List/ItemView.js | 3 +- UI/Series/Index/Posters/CollectionView.js | 2 + UI/Series/Index/Posters/ItemView.js | 2 + UI/Series/Index/SeriesIndexLayout.js | 38 ++++-- UI/Series/SeasonCollection.js | 3 + UI/Series/SeasonModel.js | 2 + UI/Series/SeriesCollection.js | 2 + .../DownloadClient/DownloadClientView.js | 10 +- UI/Settings/General/GeneralSettingsModel.js | 9 +- UI/Settings/General/GeneralView.js | 8 +- UI/Settings/Indexers/Collection.js | 8 +- UI/Settings/Indexers/CollectionView.js | 113 +++++++++--------- UI/Settings/Indexers/EditView.js | 17 ++- UI/Settings/Indexers/ItemView.js | 13 +- UI/Settings/Indexers/Model.js | 10 +- UI/Settings/Misc/MiscView.js | 9 +- UI/Settings/Naming/NamingModel.js | 9 +- UI/Settings/Naming/NamingView.js | 24 ++-- UI/Settings/Notifications/AddItemView.js | 27 +++++ UI/Settings/Notifications/AddView.js | 36 ++---- UI/Settings/Notifications/Collection.js | 8 +- UI/Settings/Notifications/CollectionView.js | 22 ++-- UI/Settings/Notifications/DeleteView.js | 11 +- UI/Settings/Notifications/EditView.js | 44 ++++--- UI/Settings/Notifications/ItemView.js | 18 +-- UI/Settings/Notifications/Model.js | 2 +- .../Quality/Profile/EditQualityProfileView.js | 8 +- .../Profile/QualityProfileCollectionView.js | 19 +-- .../Quality/Profile/QualityProfileView.js | 10 +- UI/Settings/Quality/QualityLayout.js | 23 ++-- .../Quality/Size/QualitySizeCollectionView.js | 20 +--- UI/Settings/Quality/Size/QualitySizeView.js | 9 +- UI/Settings/SettingsLayout.js | 72 +++++++---- UI/Settings/SettingsModel.js | 9 +- UI/Settings/SyncNotification.js | 50 ++++---- UI/Shared/LoadingView.js | 4 +- UI/Shared/Messenger.js | 4 +- UI/Shared/Toolbar/ToolbarLayout.js | 9 +- UI/app.js | 59 ++++----- 54 files changed, 539 insertions(+), 445 deletions(-) create mode 100644 UI/Mixins/AsChangeTrackingModel.js create mode 100644 UI/Mixins/AsModelBoundView.js create mode 100644 UI/Mixins/AsNamedView.js delete mode 100644 UI/Mixins/SaveIfChangedModel.js delete mode 100644 UI/Mixins/backbone.modelbinder.mixin.js create mode 100644 UI/Settings/Notifications/AddItemView.js diff --git a/UI/Cells/NzbDroneCell.js b/UI/Cells/NzbDroneCell.js index 3bb5dfe79..f6ea4bb8e 100644 --- a/UI/Cells/NzbDroneCell.js +++ b/UI/Cells/NzbDroneCell.js @@ -10,7 +10,7 @@ define(['app','backgrid'], function () { this._originalInit.apply(this, arguments); this.cellValue = this._getValue(); - this.model.on('change', this._refresh, this); + this.listenTo(this.model, 'change', this._refresh); }, _refresh: function () { diff --git a/UI/Controller.js b/UI/Controller.js index 55343abd1..df2f000af 100644 --- a/UI/Controller.js +++ b/UI/Controller.js @@ -1,5 +1,6 @@ "use strict"; define(['app', + 'Settings/SettingsLayout', 'Form/FormBuilder', 'AddSeries/AddSeriesLayout', 'Series/Index/SeriesIndexLayout', @@ -9,7 +10,6 @@ define(['app', 'MainMenuView', 'Series/Details/SeriesDetailsLayout', 'Series/EpisodeCollection', - 'Settings/SettingsLayout', 'Logs/Layout', 'Release/Layout', 'Missing/MissingLayout', @@ -17,12 +17,12 @@ define(['app', 'Shared/FormatHelpers', 'Shared/TemplateHelpers', 'Shared/Footer/View'], - function () { + function (App, SettingsLayout) { var controller = Backbone.Marionette.Controller.extend({ series : function () { this._setTitle('NzbDrone'); - NzbDrone.mainRegion.show(new NzbDrone.Series.Index.SeriesIndexLayout()); + App.mainRegion.show(new NzbDrone.Series.Index.SeriesIndexLayout()); }, seriesDetails: function (query) { @@ -32,52 +32,52 @@ define(['app', series.fetch({ success: function (seriesModel) { self._setTitle(seriesModel.get('title')); - NzbDrone.mainRegion.show(new NzbDrone.Series.Details.SeriesDetailsLayout({ model: seriesModel })); + App.mainRegion.show(new NzbDrone.Series.Details.SeriesDetailsLayout({ model: seriesModel })); } }); }, addSeries: function (action) { this._setTitle('Add Series'); - NzbDrone.mainRegion.show(new NzbDrone.AddSeries.AddSeriesLayout({action: action})); + App.mainRegion.show(new NzbDrone.AddSeries.AddSeriesLayout({action: action})); }, calendar: function () { this._setTitle('Calendar'); - NzbDrone.mainRegion.show(new NzbDrone.Calendar.CalendarLayout()); + App.mainRegion.show(new NzbDrone.Calendar.CalendarLayout()); }, settings: function (action) { this._setTitle('Settings'); - NzbDrone.mainRegion.show(new NzbDrone.Settings.SettingsLayout({action: action})); + App.mainRegion.show(new SettingsLayout({action: action})); }, missing: function () { this._setTitle('Missing'); - NzbDrone.mainRegion.show(new NzbDrone.Missing.MissingLayout()); + App.mainRegion.show(new NzbDrone.Missing.MissingLayout()); }, history: function () { this._setTitle('History'); - NzbDrone.mainRegion.show(new NzbDrone.History.HistoryLayout()); + App.mainRegion.show(new NzbDrone.History.HistoryLayout()); }, rss: function () { this._setTitle('RSS'); - NzbDrone.mainRegion.show(new NzbDrone.Release.Layout()); + App.mainRegion.show(new NzbDrone.Release.Layout()); }, logs: function () { this._setTitle('logs'); - NzbDrone.mainRegion.show(new NzbDrone.Logs.Layout()); + App.mainRegion.show(new NzbDrone.Logs.Layout()); }, notFound: function () { this._setTitle('Not Found'); - NzbDrone.mainRegion.show(new NzbDrone.Shared.NotFoundView(this)); + App.mainRegion.show(new NzbDrone.Shared.NotFoundView(this)); }, diff --git a/UI/History/EventTypeCell.js b/UI/History/EventTypeCell.js index c6871e330..7a2af47e6 100644 --- a/UI/History/EventTypeCell.js +++ b/UI/History/EventTypeCell.js @@ -10,8 +10,8 @@ define(['app', 'Cells/NzbDroneCell' ], function () { if (this.cellValue) { - var icon = 'icon-question'; - var toolTip = 'unknow event'; + var icon; + var toolTip; switch (this.cellValue) { case 'grabbed': @@ -22,10 +22,14 @@ define(['app', 'Cells/NzbDroneCell' ], function () { icon = 'icon-hdd'; toolTip = 'Existing episode file added to library'; break; - case 'DownloadFolderImported': + case 'downloadFolderImported': icon = 'icon-download-alt'; - toolTip = 'Episode downloaded succesfully and picked up from download client'; + toolTip = 'Episode downloaded successfully and picked up from download client'; break; + default : + icon = 'icon-question'; + toolTip = 'unknown event'; + } this.$el.html(''.format(icon, toolTip)); diff --git a/UI/Mixins/AsChangeTrackingModel.js b/UI/Mixins/AsChangeTrackingModel.js new file mode 100644 index 000000000..4e0d99ff2 --- /dev/null +++ b/UI/Mixins/AsChangeTrackingModel.js @@ -0,0 +1,31 @@ +'use strict'; + +define( + function () { + + return function () { + + var originalInit = this.prototype.initialize; + + this.prototype.initialize = function () { + + this.isSaved = true; + + this.on('change', function () { + this.isSaved = false; + }, this); + + this.on('sync', function () { + this.isSaved = true; + }, this); + + + if (originalInit) { + originalInit.call(this); + } + }; + + return this; + }; + } +); diff --git a/UI/Mixins/AsModelBoundView.js b/UI/Mixins/AsModelBoundView.js new file mode 100644 index 000000000..13814b14a --- /dev/null +++ b/UI/Mixins/AsModelBoundView.js @@ -0,0 +1,37 @@ +'use strict'; + +define( + ['backbone.modelbinder'], + function (ModelBinder) { + + return function () { + + var originalOnRender = this.prototype.onRender, + originalBeforeClose = this.prototype.onBeforeClose; + + this.prototype.onRender = function () { + if (this.model) { + this._modelBinder = new ModelBinder(); + this._modelBinder.bind(this.model, this.el); + } + if (originalOnRender) { + originalOnRender.call(this); + } + }; + + this.prototype.beforeClose = function () { + + if (this._modelBinder) { + this._modelBinder.unbind(); + delete this._modelBinder; + } + + if (originalBeforeClose) { + originalBeforeClose.call(this); + } + }; + + return this; + }; + } +); diff --git a/UI/Mixins/AsNamedView.js b/UI/Mixins/AsNamedView.js new file mode 100644 index 000000000..7e310085e --- /dev/null +++ b/UI/Mixins/AsNamedView.js @@ -0,0 +1,38 @@ +'use strict'; + +define( + function () { + + return function () { + + this.viewName = function () { + if (this.template) { + var regex = new RegExp('\/', 'g'); + + return this.template + .toLocaleLowerCase() + .replace('template', '') + .replace(regex, '-'); + } + + return undefined; + }; + + var originalOnRender = this.onRender; + + this.onRender = function () { + + this.$el.removeClass('iv-' + this.viewName()); + this.$el.addClass('iv-' + this.viewName()); + + if (originalOnRender) { + return originalOnRender.call(this); + } + + return undefined; + }; + + return this; + }; + } +); diff --git a/UI/Mixins/SaveIfChangedModel.js b/UI/Mixins/SaveIfChangedModel.js deleted file mode 100644 index bebff25bd..000000000 --- a/UI/Mixins/SaveIfChangedModel.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; -define(['app'], function () { - - NzbDrone.Mixins.SaveIfChangedModel = { - // originalInitialize: this.initialize, - - initialize: function () { - this.isSaved = true; - - this.on('change', function () { - this.isSaved = false; - }, this); - - this.on('sync', function () { - this.isSaved = true; - }, this); - - // if (originalInitialize) { - // originalInitialize.call(this); - // } - }, - - saveIfChanged: function (options) { - if (!this.isSaved) { - this.save(undefined, options); - } - } - }; - - return NzbDrone.Missing.SaveIfChangedModel; -}); diff --git a/UI/Mixins/backbone.modelbinder.mixin.js b/UI/Mixins/backbone.modelbinder.mixin.js deleted file mode 100644 index 460756e26..000000000 --- a/UI/Mixins/backbone.modelbinder.mixin.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -var oldMarionetteItemViewRender = Marionette.ItemView.prototype.render; -var oldItemCollectionViewRender = Marionette.CollectionView.prototype.render; - - -Marionette.View.prototype.viewName = function () { - if (this.template) { - var regex = new RegExp('\/', 'g'); - - return this.template - .toLocaleLowerCase() - .replace('template', '') - .replace(regex, '-'); - } - - return undefined; -}; - -Marionette.ItemView.prototype.self$ = function (selector) { - return this.$(selector).not("[class*='iv-'] " + selector); -}; - -Marionette.ItemView.prototype.render = function () { - - var result = oldMarionetteItemViewRender.apply(this, arguments); - - this.$el.removeClass('iv-' + this.viewName()); - - //check to see if el has bindings (name attribute) - // any element that has a name attribute and isn't child of another view. - if (this.self$('[name]').length > 0) { - if (!this.model) { - throw 'view ' + this.viewName() + ' has binding attributes but model is not defined'; - } - - if (!this._modelBinder) { - this._modelBinder = new Backbone.ModelBinder(); - } - - this._modelBinder.bind(this.model, this.el); - } - - this.$el.addClass('iv-' + this.viewName()); - - return result; -}; diff --git a/UI/Quality/QualitySizeCollection.js b/UI/Quality/QualitySizeCollection.js index 5c111019c..f329b58e6 100644 --- a/UI/Quality/QualitySizeCollection.js +++ b/UI/Quality/QualitySizeCollection.js @@ -4,4 +4,6 @@ define(['app', 'Quality/QualitySizeModel'], function () { model: NzbDrone.Quality.QualitySizeModel, url : NzbDrone.Constants.ApiRoot + '/qualitysize' }); + + return NzbDrone.Quality.QualitySizeCollection; }); diff --git a/UI/Series/Delete/DeleteSeriesView.js b/UI/Series/Delete/DeleteSeriesView.js index 34ef1a907..6d61a42fe 100644 --- a/UI/Series/Delete/DeleteSeriesView.js +++ b/UI/Series/Delete/DeleteSeriesView.js @@ -28,4 +28,7 @@ define(['app', 'Series/SeriesModel'], function () { } }); + + return NzbDrone.Series.Delete.DeleteSeriesView; + }); diff --git a/UI/Series/EpisodeCollection.js b/UI/Series/EpisodeCollection.js index 636ab6d15..9352e32f7 100644 --- a/UI/Series/EpisodeCollection.js +++ b/UI/Series/EpisodeCollection.js @@ -12,4 +12,7 @@ define(['app', 'Series/EpisodeModel'], function () { return new NzbDrone.Series.EpisodeCollection(filtered); } }); + + + return NzbDrone.Series.EpisodeCollection; }); diff --git a/UI/Series/EpisodeModel.js b/UI/Series/EpisodeModel.js index d98fcbd9f..eef0da6a6 100644 --- a/UI/Series/EpisodeModel.js +++ b/UI/Series/EpisodeModel.js @@ -87,4 +87,6 @@ define(['app', 'Series/SeriesModel'], function () { status : 0 } }); + + return NzbDrone.Series.EpisodeModel; }); diff --git a/UI/Series/Index/EmptySeriesIndexView.js b/UI/Series/Index/EmptySeriesIndexView.js index d6c6154d4..4a8ef4af8 100644 --- a/UI/Series/Index/EmptySeriesIndexView.js +++ b/UI/Series/Index/EmptySeriesIndexView.js @@ -3,4 +3,6 @@ define(['app'], function () { NzbDrone.Series.Index.EmptySeriesCollectionView = Backbone.Marionette.CompositeView.extend({ template: 'Series/Index/EmptySeriesIndexTemplate' }); + + return NzbDrone.Series.Index.EmptySeriesCollectionView; }); diff --git a/UI/Series/Index/EmptyView.js b/UI/Series/Index/EmptyView.js index f3d02eaf7..53e89166a 100644 --- a/UI/Series/Index/EmptyView.js +++ b/UI/Series/Index/EmptyView.js @@ -5,4 +5,6 @@ define(['app'], function () { NzbDrone.Series.Index.EmptyView = Backbone.Marionette.CompositeView.extend({ template: 'Series/Index/EmptyTemplate' }); + + return NzbDrone.Series.Index.EmptyView; }); diff --git a/UI/Series/Index/List/CollectionView.js b/UI/Series/Index/List/CollectionView.js index 364b18f8d..2b81ddcf6 100644 --- a/UI/Series/Index/List/CollectionView.js +++ b/UI/Series/Index/List/CollectionView.js @@ -7,4 +7,6 @@ define(['app', 'Series/Index/List/ItemView', 'Config'], function () { itemViewContainer : '#x-series-list', template : 'Series/Index/List/CollectionTemplate' }); + + return NzbDrone.Series.Index.List.CollectionView; }); diff --git a/UI/Series/Index/List/ItemView.js b/UI/Series/Index/List/ItemView.js index 46eb1c4ea..1cf32b1a6 100644 --- a/UI/Series/Index/List/ItemView.js +++ b/UI/Series/Index/List/ItemView.js @@ -8,7 +8,6 @@ define([ 'Series/Delete/DeleteSeriesView' ], function () { - NzbDrone.Series.Index.List.ItemView = Backbone.Marionette.ItemView.extend({ template: 'Series/Index/List/ItemTemplate', @@ -31,4 +30,6 @@ define([ NzbDrone.modalRegion.show(view); } }); + + return NzbDrone.Series.Index.List.ItemView; }); diff --git a/UI/Series/Index/Posters/CollectionView.js b/UI/Series/Index/Posters/CollectionView.js index ebdfcfccc..b6d188ae4 100644 --- a/UI/Series/Index/Posters/CollectionView.js +++ b/UI/Series/Index/Posters/CollectionView.js @@ -7,4 +7,6 @@ define(['app', 'Series/Index/Posters/ItemView', 'Config'], function () { itemViewContainer : '#x-series-posters', template : 'Series/Index/Posters/CollectionTemplate' }); + + return NzbDrone.Series.Index.Posters.CollectionView; }); diff --git a/UI/Series/Index/Posters/ItemView.js b/UI/Series/Index/Posters/ItemView.js index 1d034d476..5369afbf2 100644 --- a/UI/Series/Index/Posters/ItemView.js +++ b/UI/Series/Index/Posters/ItemView.js @@ -40,4 +40,6 @@ define([ this.ui.controls.slideToggle(); } }); + + return NzbDrone.Series.Index.Posters.ItemView; }); diff --git a/UI/Series/Index/SeriesIndexLayout.js b/UI/Series/Index/SeriesIndexLayout.js index 923156f6b..ef16ecd7d 100644 --- a/UI/Series/Index/SeriesIndexLayout.js +++ b/UI/Series/Index/SeriesIndexLayout.js @@ -4,6 +4,7 @@ define([ 'Series/Index/List/CollectionView', 'Series/Index/Posters/CollectionView', 'Series/Index/EmptyView', + 'Series/SeriesCollection', 'Cells/AirDateCell', 'Cells/SeriesTitleCell', 'Cells/TemplatedCell', @@ -12,7 +13,20 @@ define([ 'Config', 'Shared/LoadingView' ], - function () { + function ( + App, + ListCollectionView, + PosterCollectionView, + EmptyView, + SeriesCollection, + AirDateCell, + SeriesTitleCell, + TemplatedCell, + SeriesStatusCell, + ToolbarLayout, + Config, + LoadingView) + { NzbDrone.Series.Index.SeriesIndexLayout = Backbone.Marionette.Layout.extend({ template: 'Series/Index/SeriesIndexLayoutTemplate', @@ -30,7 +44,7 @@ define([ { name : 'this', label: 'Title', - cell : NzbDrone.Cells.SeriesTitleCell + cell : SeriesTitleCell }, { name : 'seasonCount', @@ -50,21 +64,21 @@ define([ { name : 'nextAiring', label: 'Next Airing', - cell : NzbDrone.Cells.AirDateCell + cell : AirDateCell }, { name : 'this', label : 'Episodes', sortable: false, template: 'Series/EpisodeProgressTemplate', - cell : NzbDrone.Cells.TemplatedCell + cell : TemplatedCell }, { name : 'this', label : '', sortable: false, template: 'Series/Index/Table/ControlsColumnTemplate', - cell : NzbDrone.Cells.TemplatedCell + cell : TemplatedCell } ], @@ -107,24 +121,24 @@ define([ }, _showList: function () { - var view = new NzbDrone.Series.Index.List.CollectionView(); + var view = new ListCollectionView(); this._fetchCollection(view); }, _showPosters: function () { - var view = new NzbDrone.Series.Index.Posters.CollectionView(); + var view = new PosterCollectionView(); this._fetchCollection(view); }, _showEmpty: function () { - this.series.show(new NzbDrone.Series.Index.EmptyView()); + this.series.show(new EmptyView()); }, _fetchCollection: function (view) { var self = this; if (this.seriesCollection.models.length === 0) { - this.series.show(new NzbDrone.Shared.LoadingView()); + this.series.show(new LoadingView()); this.seriesCollection.fetch() .done(function () { @@ -145,7 +159,7 @@ define([ }, initialize: function () { - this.seriesCollection = new NzbDrone.Series.SeriesCollection(); + this.seriesCollection = new SeriesCollection(); }, onShow: function () { @@ -178,11 +192,13 @@ define([ ] }; - this.toolbar.show(new NzbDrone.Shared.Toolbar.ToolbarLayout({ + this.toolbar.show(new ToolbarLayout({ right : [ viewButtons], left : [ this.leftSideButtons], context: this })); } }); + + return NzbDrone.Series.Index.SeriesIndexLayou; }); diff --git a/UI/Series/SeasonCollection.js b/UI/Series/SeasonCollection.js index 12dea609c..87e705421 100644 --- a/UI/Series/SeasonCollection.js +++ b/UI/Series/SeasonCollection.js @@ -17,4 +17,7 @@ define(['app', 'Series/SeasonModel', 'backbone.pageable'], function (App, Season order : null } }); + + + return NzbDrone.Series.SeasonCollection; }); diff --git a/UI/Series/SeasonModel.js b/UI/Series/SeasonModel.js index 7d0fe169d..ca3f26d5e 100644 --- a/UI/Series/SeasonModel.js +++ b/UI/Series/SeasonModel.js @@ -18,5 +18,7 @@ define(['app'], function () { seasonNumber: 0 } }); + + return NzbDrone.Series.SeasonModel; }); diff --git a/UI/Series/SeriesCollection.js b/UI/Series/SeriesCollection.js index cec7fadc0..ba4d9f6d1 100644 --- a/UI/Series/SeriesCollection.js +++ b/UI/Series/SeriesCollection.js @@ -13,4 +13,6 @@ define(['app', 'Series/SeriesModel'], function () { order: -1 } }); + + return NzbDrone.Series.SeriesCollection; }); diff --git a/UI/Settings/DownloadClient/DownloadClientView.js b/UI/Settings/DownloadClient/DownloadClientView.js index 09bf825a6..715b6bef1 100644 --- a/UI/Settings/DownloadClient/DownloadClientView.js +++ b/UI/Settings/DownloadClient/DownloadClientView.js @@ -1,16 +1,16 @@ 'use strict'; define([ - 'app', 'Settings/SettingsModel','bootstrap' + 'app', 'marionette', 'Mixins/AsModelBoundView', 'bootstrap' -], function () { +], function (App, Marionette, AsModelBoundView) { - NzbDrone.Settings.DownloadClient.DownloadClientView = Backbone.Marionette.ItemView.extend({ + var view = Marionette.ItemView.extend({ template : 'Settings/DownloadClient/DownloadClientTemplate', className: 'form-horizontal', ui: { - bsSwitch : '.switch', + bsSwitch : '.switch', tooltip : '.help-inline i', pathInput : '.x-path', sabConfig : '.x-sab-config', @@ -76,4 +76,6 @@ define([ } } }); + + return AsModelBoundView.call(view); }); diff --git a/UI/Settings/General/GeneralSettingsModel.js b/UI/Settings/General/GeneralSettingsModel.js index 3ea5f52c2..70f71dc6e 100644 --- a/UI/Settings/General/GeneralSettingsModel.js +++ b/UI/Settings/General/GeneralSettingsModel.js @@ -1,7 +1,8 @@ "use strict"; -define(['app'], function () { - NzbDrone.Settings.General.GeneralSettingsModel = Backbone.Model.extend({ - url: NzbDrone.Constants.ApiRoot + '/settings/host', +define(['app', 'backbone', 'Mixins/AsChangeTrackingModel'], function (App, Backbone, AsChangeTrackingModel) { + var model = Backbone.Model.extend({ + + url: App.Constants.ApiRoot + '/settings/host', initialize: function () { this.on('change', function () { @@ -13,4 +14,6 @@ define(['app'], function () { }, this); } }); + + return AsChangeTrackingModel.call(model); }); diff --git a/UI/Settings/General/GeneralView.js b/UI/Settings/General/GeneralView.js index 469b7d21b..40ccf8867 100644 --- a/UI/Settings/General/GeneralView.js +++ b/UI/Settings/General/GeneralView.js @@ -1,7 +1,7 @@ 'use strict'; -define(['app', 'Settings/SettingsModel', 'Shared/Messenger'], function () { +define(['app', 'Mixins/AsModelBoundView'], function (App, AsModelBoundView) { - NzbDrone.Settings.General.GeneralView = Backbone.Marionette.ItemView.extend({ + var view = Backbone.Marionette.ItemView.extend({ template: 'Settings/General/GeneralTemplate', initialize: function () { @@ -12,11 +12,13 @@ define(['app', 'Settings/SettingsModel', 'Shared/Messenger'], function () { if (!this.model.isSaved) { this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({ successMessage: 'General Settings saved', - errorMessage: "Failed to save General Settings" + errorMessage : "Failed to save General Settings" })); } } } ); + + return AsModelBoundView.call(view); }); diff --git a/UI/Settings/Indexers/Collection.js b/UI/Settings/Indexers/Collection.js index 730339bde..5e043a01b 100644 --- a/UI/Settings/Indexers/Collection.js +++ b/UI/Settings/Indexers/Collection.js @@ -1,7 +1,7 @@ "use strict"; -define(['app', 'Settings/Indexers/Model'], function () { - NzbDrone.Settings.Indexers.Collection = Backbone.Collection.extend({ - url : NzbDrone.Constants.ApiRoot + '/indexer', - model: NzbDrone.Settings.Indexers.Model +define(['app', 'Settings/Indexers/Model'], function (App, IndexerModel) { + return Backbone.Collection.extend({ + url : App.Constants.ApiRoot + '/indexer', + model: IndexerModel }); }); diff --git a/UI/Settings/Indexers/CollectionView.js b/UI/Settings/Indexers/CollectionView.js index 3820fbe65..72520d3c3 100644 --- a/UI/Settings/Indexers/CollectionView.js +++ b/UI/Settings/Indexers/CollectionView.js @@ -1,60 +1,63 @@ 'use strict'; define(['app', - 'Settings/Indexers/ItemView', - 'Settings/Indexers/EditView', - 'Settings/SyncNotification'], - function () { - NzbDrone.Settings.Indexers.CollectionView = Backbone.Marionette.CompositeView.extend({ - itemView : NzbDrone.Settings.Indexers.ItemView, - itemViewContainer : '#x-indexers', - template : 'Settings/Indexers/CollectionTemplate', - - events: { - 'click .x-add': 'openSchemaModal' - }, - - initialize: function () { - NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this._saveSettings, this); - this.savedCount = 0; - }, - - openSchemaModal: function () { - var self = this; - //TODO: Is there a better way to deal with changing URLs? - var schemaCollection = new NzbDrone.Settings.Indexers.Collection(); - schemaCollection.url = '/api/indexer/schema'; - schemaCollection.fetch({ - success: function (collection) { - collection.url = '/api/indexer'; - var model = _.first(collection.models); - model.set('id', undefined); - model.set('name', ''); - - var view = new NzbDrone.Settings.Indexers.EditView({ model: model, indexerCollection: self.collection}); - NzbDrone.modalRegion.show(view); + 'marionette', + 'Shared/Messenger', + 'Settings/Indexers/ItemView', + 'Settings/Indexers/EditView', + 'Settings/Indexers/Collection'], + function (App, Marionette, Messenger, IndexerItemView, IndexerEditView, IndexerCollection) { + return Marionette.CompositeView.extend({ + itemView : IndexerItemView, + itemViewContainer: '#x-indexers', + template : 'Settings/Indexers/CollectionTemplate', + + events: { + 'click .x-add': 'openSchemaModal' + }, + + initialize: function () { + this.listenTo(App.vent, App.Commands.SaveSettings, this._saveSettings); + this.savedCount = 0; + }, + + openSchemaModal: function () { + var self = this; + //TODO: Is there a better way to deal with changing URLs? + var schemaCollection = new IndexerCollection(); + schemaCollection.url = '/api/indexer/schema'; + schemaCollection.fetch({ + success: function (collection) { + collection.url = '/api/indexer'; + var model = _.first(collection.models); + model.set('id', undefined); + model.set('name', ''); + + var view = new IndexerEditView({ model: model, indexerCollection: self.collection}); + App.modalRegion.show(view); + } + }); + }, + + _saveSettings: function () { + var self = this; + + _.each(this.collection.models, function (model, index, list) { + model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({ + errorMessage : 'Failed to save indexer: ' + model.get('name'), + successCallback: self._saveSuccessful, + context : self + })); + }); + + if (self.savedCount > 0) { + Messenger.show({message: 'Indexer settings saved'}); } - }); - }, - - _saveSettings: function () { - var self = this; - - _.each(this.collection.models, function (model, index, list) { - model.saveIfChanged(NzbDrone.Settings.SyncNotificaiton.callback({ - errorMessage: 'Failed to save indexer: ' + model.get('name'), - successCallback: self._saveSuccessful, - context: self - })); - }); - - if (self.savedCount > 0) { - NzbDrone.Shared.Messenger.show({message: 'Indexer settings saved'}); - } - this.savedCount = 0; - }, - _saveSuccessful: function () { - this.savedCount++; - } + this.savedCount = 0; + }, + + _saveSuccessful: function () { + this.savedCount++; + } + }); }); -}); diff --git a/UI/Settings/Indexers/EditView.js b/UI/Settings/Indexers/EditView.js index f188b37b9..29cb641a2 100644 --- a/UI/Settings/Indexers/EditView.js +++ b/UI/Settings/Indexers/EditView.js @@ -2,12 +2,14 @@ define([ 'app', - 'Settings/Indexers/Model' + 'marionette', + 'Shared/Messenger', + 'Mixins/AsModelBoundView' -], function () { +], function (App, Marionette, Messenger, AsModelBoundView) { - NzbDrone.Settings.Indexers.EditView = Backbone.Marionette.ItemView.extend({ - template : 'Settings/Indexers/EditTemplate', + var view = Marionette.ItemView.extend({ + template: 'Settings/Indexers/EditTemplate', events: { 'click .x-save': 'save' @@ -24,12 +26,12 @@ define([ syncNotification: function (success, error, context) { return { success: function () { - NzbDrone.Shared.Messenger.show({ + Messenger.show({ message: success }); context.indexerCollection.add(context.model); - NzbDrone.modalRegion.closeModal(); + App.modalRegion.closeModal(); }, error: function () { @@ -38,4 +40,7 @@ define([ }; } }); + + return AsModelBoundView.call(view); + }); diff --git a/UI/Settings/Indexers/ItemView.js b/UI/Settings/Indexers/ItemView.js index 49e334135..75ffd721b 100644 --- a/UI/Settings/Indexers/ItemView.js +++ b/UI/Settings/Indexers/ItemView.js @@ -1,13 +1,10 @@ "use strict"; -define([ - 'app', - 'Settings/Indexers/Collection' +define(['marionette'], function () { -], function () { - - NzbDrone.Settings.Indexers.ItemView = Backbone.Marionette.ItemView.extend({ - template : 'Settings/Indexers/ItemTemplate', - tagName : 'li' + return Marionette.ItemView.extend({ + template: 'Settings/Indexers/ItemTemplate', + tagName : 'li' }); + }); diff --git a/UI/Settings/Indexers/Model.js b/UI/Settings/Indexers/Model.js index 1d80214fa..1eab3e345 100644 --- a/UI/Settings/Indexers/Model.js +++ b/UI/Settings/Indexers/Model.js @@ -1,9 +1,9 @@ "use strict"; -define(['app', - 'Mixins/SaveIfChangedModel', - 'backbone.deepmodel'], function (App, SaveIfChangedModel, DeepModel) { - NzbDrone.Settings.Indexers.Model = DeepModel.DeepModel.extend({ +define([ + 'backbone.deepmodel', 'Mixins/AsChangeTrackingModel'], function (DeepModel, AsChangeTrackingModel) { + var model = DeepModel.DeepModel.extend({ + }); - _.extend(NzbDrone.Settings.Indexers.Model.prototype, NzbDrone.Mixins.SaveIfChangedModel); + return AsChangeTrackingModel.call(model); }); diff --git a/UI/Settings/Misc/MiscView.js b/UI/Settings/Misc/MiscView.js index 215d5738e..c8d2ccdd4 100644 --- a/UI/Settings/Misc/MiscView.js +++ b/UI/Settings/Misc/MiscView.js @@ -1,11 +1,8 @@ 'use strict'; -define([ - 'app', 'Settings/SettingsModel' +define(['marionette', 'Mixins/AsModelBoundview', 'bootstrap'], function (Marionette, AsModelBoundView) { -], function () { - - NzbDrone.Settings.Misc.MiscView = Backbone.Marionette.ItemView.extend({ + var view = Marionette.ItemView.extend({ template : 'Settings/Misc/MiscTemplate', className: 'form-horizontal', @@ -17,4 +14,6 @@ define([ this.ui.tooltip.tooltip({ placement: 'right', html: true }); } }); + + return AsModelBoundView.call(view); }); diff --git a/UI/Settings/Naming/NamingModel.js b/UI/Settings/Naming/NamingModel.js index 1ab8c691e..0f9962c17 100644 --- a/UI/Settings/Naming/NamingModel.js +++ b/UI/Settings/Naming/NamingModel.js @@ -1,9 +1,10 @@ "use strict"; define(['app', - 'Mixins/SaveIfChangedModel'], function () { - NzbDrone.Settings.Naming.NamingModel = Backbone.Model.extend({ - url: NzbDrone.Constants.ApiRoot + '/config/naming' + 'Mixins/AsChangeTrackingModel'], function (App, AsChangeTrackingModel) { + var model = Backbone.Model.extend({ + url: App.Constants.ApiRoot + '/config/naming' }); - _.extend(NzbDrone.Settings.Naming.NamingModel.prototype, NzbDrone.Mixins.SaveIfChangedModel); + return AsChangeTrackingModel.call(model); + }); diff --git a/UI/Settings/Naming/NamingView.js b/UI/Settings/Naming/NamingView.js index fa2de8b49..93ab4bfed 100644 --- a/UI/Settings/Naming/NamingView.js +++ b/UI/Settings/Naming/NamingView.js @@ -1,24 +1,28 @@ 'use strict'; define(['app', - 'Settings/Naming/NamingModel', - 'Settings/SyncNotification'], function () { + 'marionette', + 'Settings/Naming/NamingModel', + 'Settings/SyncNotification', + 'Mixins/AsModelBoundView'], function (App, Marionette, NamingModel, SyncNotification, AsModelBoundView) { - NzbDrone.Settings.Naming.NamingView = Backbone.Marionette.ItemView.extend({ - template : 'Settings/Naming/NamingTemplate', + var view = Marionette.ItemView.extend({ + template: 'Settings/Naming/NamingTemplate', initialize: function () { - this.model = new NzbDrone.Settings.Naming.NamingModel(); + this.model = new NamingModel(); this.model.fetch(); - NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this); + this.listenTo(App.vent, App.Commands.SaveSettings, this.saveSettings); + }, saveSettings: function () { - this.model.saveIfChanged(undefined, NzbDrone.Settings.SyncNotificaiton.callback({ + this.model.saveIfChanged(undefined, SyncNotification.callback({ successMessage: 'Naming Settings saved', - errorMessage: "Failed to save Naming Settings" + errorMessage : "Failed to save Naming Settings" })); } }); -}) -; + + return AsModelBoundView.call(view); +}); diff --git a/UI/Settings/Notifications/AddItemView.js b/UI/Settings/Notifications/AddItemView.js new file mode 100644 index 000000000..65704842c --- /dev/null +++ b/UI/Settings/Notifications/AddItemView.js @@ -0,0 +1,27 @@ +"use strict"; + +define([ + 'app', + 'marionette', + 'Settings/Notifications/EditView' +], function (App, Marionette, EditView) { + + return Marionette.ItemView.extend({ + template: 'Settings/Notifications/AddItemTemplate', + tagName : 'li', + + events: { + 'click': 'addNotification' + }, + + initialize: function (options) { + this.notificationCollection = options.notificationCollection; + }, + + addNotification: function () { + this.model.set('id', undefined); + var editView = new EditView({ model: this.model, notificationCollection: this.notificationCollection }); + App.modalRegion.show(editView); + } + }); +}); diff --git a/UI/Settings/Notifications/AddView.js b/UI/Settings/Notifications/AddView.js index dbfc83f00..38f53715c 100644 --- a/UI/Settings/Notifications/AddView.js +++ b/UI/Settings/Notifications/AddView.js @@ -1,34 +1,14 @@ "use strict"; define([ - 'app', - 'Settings/Notifications/Model' - -], function () { - - NzbDrone.Settings.Notifications.AddItemView = Backbone.Marionette.ItemView.extend({ - template : 'Settings/Notifications/AddItemTemplate', - tagName : 'li', - - events: { - 'click': 'addNotification' - }, - - initialize: function (options) { - this.notificationCollection = options.notificationCollection; - }, - - addNotification: function () { - this.model.set('id', undefined); - var view = new NzbDrone.Settings.Notifications.EditView({ model: this.model, notificationCollection: this.notificationCollection }); - NzbDrone.modalRegion.show(view); - } - }); - - NzbDrone.Settings.Notifications.AddView = Backbone.Marionette.CompositeView.extend({ - itemView : NzbDrone.Settings.Notifications.AddItemView, - itemViewContainer : '.notifications .items', - template : 'Settings/Notifications/AddTemplate', + 'marionette', + 'Settings/Notifications/AddItemView' +], function (Marionette, AddItemView) { + + return Marionette.CompositeView.extend({ + itemView : AddItemView, + itemViewContainer: '.notifications .items', + template : 'Settings/Notifications/AddTemplate', itemViewOptions: function () { return { diff --git a/UI/Settings/Notifications/Collection.js b/UI/Settings/Notifications/Collection.js index 57944089e..6e0eb508d 100644 --- a/UI/Settings/Notifications/Collection.js +++ b/UI/Settings/Notifications/Collection.js @@ -1,7 +1,7 @@ "use strict"; -define(['app', 'Settings/Notifications/Model'], function () { - NzbDrone.Settings.Notifications.Collection = Backbone.Collection.extend({ - url : NzbDrone.Constants.ApiRoot + '/notification', - model: NzbDrone.Settings.Notifications.Model +define(['app', 'Settings/Notifications/Model'], function (App, NotificationModel) { + return Backbone.Collection.extend({ + url : App.Constants.ApiRoot + '/notification', + model: NotificationModel }); }); diff --git a/UI/Settings/Notifications/CollectionView.js b/UI/Settings/Notifications/CollectionView.js index b44988011..2a6f51fae 100644 --- a/UI/Settings/Notifications/CollectionView.js +++ b/UI/Settings/Notifications/CollectionView.js @@ -1,22 +1,28 @@ 'use strict'; -define(['app', 'Settings/Notifications/ItemView', 'Settings/Notifications/AddView'], function () { - NzbDrone.Settings.Notifications.CollectionView = Backbone.Marionette.CompositeView.extend({ - itemView : NzbDrone.Settings.Notifications.ItemView, - itemViewContainer : 'tbody', - template : 'Settings/Notifications/CollectionTemplate', +define([ + 'app', + 'marionette', + 'Settings/Notifications/Collection', + 'Settings/Notifications/ItemView', + 'Settings/Notifications/AddView' +], function (App, Marionette, NotificationCollection, NotificationItemView, AddSelectionNotificationView) { + return Marionette.CompositeView.extend({ + itemView : NotificationItemView, + itemViewContainer: 'tbody', + template : 'Settings/Notifications/CollectionTemplate', events: { 'click .x-add': 'openSchemaModal' }, openSchemaModal: function () { - var schemaCollection = new NzbDrone.Settings.Notifications.Collection(); + var schemaCollection = new NotificationCollection(); schemaCollection.url = '/api/notification/schema'; schemaCollection.fetch(); schemaCollection.url = '/api/notification'; - var view = new NzbDrone.Settings.Notifications.AddView({ collection: schemaCollection, notificationCollection: this.collection}); - NzbDrone.modalRegion.show(view); + var view = new AddSelectionNotificationView({ collection: schemaCollection, notificationCollection: this.collection}); + App.modalRegion.show(view); } }); }); diff --git a/UI/Settings/Notifications/DeleteView.js b/UI/Settings/Notifications/DeleteView.js index d9ba35b54..1c2e5d26d 100644 --- a/UI/Settings/Notifications/DeleteView.js +++ b/UI/Settings/Notifications/DeleteView.js @@ -1,7 +1,6 @@ 'use strict'; -define(['app', 'Settings/Notifications/Model'], function () { - - NzbDrone.Settings.Notifications.DeleteView = Backbone.Marionette.ItemView.extend({ +define(['app', 'marionette'], function (App, Marionette) { + return Marionette.ItemView.extend({ template: 'Settings/Notifications/DeleteTemplate', events: { @@ -9,12 +8,10 @@ define(['app', 'Settings/Notifications/Model'], function () { }, removeNotification: function () { - var self = this; - this.model.destroy({ wait : true, - success: function (model) { - NzbDrone.modalRegion.closeModal(); + success: function () { + App.modalRegion.closeModal(); } }); } diff --git a/UI/Settings/Notifications/EditView.js b/UI/Settings/Notifications/EditView.js index a02cc3593..09ea025fb 100644 --- a/UI/Settings/Notifications/EditView.js +++ b/UI/Settings/Notifications/EditView.js @@ -2,23 +2,27 @@ define([ 'app', + 'marionette', 'Settings/Notifications/Model', - 'Settings/Notifications/DeleteView' + 'Settings/Notifications/DeleteView', + 'Settings/SyncNotification', + 'Shared/Messenger', + 'Mixins/AsModelBoundView' -], function () { +], function (App, Marionette, NotificationModel, DeleteView, SyncNotification, Messenger, AsModelBoundView) { - NzbDrone.Settings.Notifications.EditView = Backbone.Marionette.ItemView.extend({ - template : 'Settings/Notifications/EditTemplate', + var model = Marionette.ItemView.extend({ + template: 'Settings/Notifications/EditTemplate', events: { - 'click .x-save' : '_saveNotification', - 'click .x-remove' : '_deleteNotification', - 'click .x-test' : '_test' + 'click .x-save' : '_saveNotification', + 'click .x-remove': '_deleteNotification', + 'click .x-test' : '_test' }, ui: { - testButton : '.x-test', - testIcon : '.x-test-icon' + testButton: '.x-test', + testIcon : '.x-test-icon' }, initialize: function (options) { @@ -30,22 +34,22 @@ define([ var success = 'Notification Saved: ' + name; var fail = 'Failed to save notification: ' + name; - this.model.save(undefined, NzbDrone.Settings.SyncNotificaiton.callback({ - successMessage: success, - errorMessage: fail, + this.model.save(undefined, SyncNotification.callback({ + successMessage : success, + errorMessage : fail, successCallback: this._saveSuccess, - context: this + context : this })); }, _deleteNotification: function () { - var view = new NzbDrone.Settings.Notifications.DeleteView({ model: this.model }); - NzbDrone.modalRegion.show(view); + var view = new DeleteView({ model: this.model }); + App.modalRegion.show(view); }, _saveSuccess: function () { this.notificationCollection.add(this.model, { merge: true }); - NzbDrone.modalRegion.closeModal(); + App.modalRegion.closeModal(); }, _test: function () { @@ -62,9 +66,9 @@ define([ }); var self = this; - var commandPromise = NzbDrone.Commands.Execute(testCommand, properties); + var commandPromise = App.Commands.Execute(testCommand, properties); commandPromise.done(function () { - NzbDrone.Shared.Messenger.show({ + Messenger.show({ message: 'Notification settings tested successfully' }); }); @@ -74,7 +78,7 @@ define([ return; } - NzbDrone.Shared.Messenger.show({ + Messenger.show({ message: 'Failed to test notification settings', type : 'error' }); @@ -90,4 +94,6 @@ define([ } } }); + + return AsModelBoundView.call(model); }); diff --git a/UI/Settings/Notifications/ItemView.js b/UI/Settings/Notifications/ItemView.js index d6882d36f..c80e3bd54 100644 --- a/UI/Settings/Notifications/ItemView.js +++ b/UI/Settings/Notifications/ItemView.js @@ -2,15 +2,15 @@ define([ 'app', - 'Settings/Notifications/Collection', + 'marionette', 'Settings/Notifications/EditView', 'Settings/Notifications/DeleteView' -], function () { +], function (App, Marionette, EditView, DeleteView) { - NzbDrone.Settings.Notifications.ItemView = Backbone.Marionette.ItemView.extend({ - template : 'Settings/Notifications/ItemTemplate', - tagName: 'tr', + return Marionette.ItemView.extend({ + template: 'Settings/Notifications/ItemTemplate', + tagName : 'tr', events: { 'click .x-edit' : 'edit', @@ -18,13 +18,13 @@ define([ }, edit: function () { - var view = new NzbDrone.Settings.Notifications.EditView({ model: this.model, notificationCollection: this.model.collection}); - NzbDrone.modalRegion.show(view); + var view = new EditView({ model: this.model, notificationCollection: this.model.collection}); + App.modalRegion.show(view); }, deleteNotification: function () { - var view = new NzbDrone.Settings.Notifications.DeleteView({ model: this.model}); - NzbDrone.modalRegion.show(view); + var view = new DeleteView({ model: this.model}); + App.modalRegion.show(view); } }); }); diff --git a/UI/Settings/Notifications/Model.js b/UI/Settings/Notifications/Model.js index 0055d733e..9acfe9d9f 100644 --- a/UI/Settings/Notifications/Model.js +++ b/UI/Settings/Notifications/Model.js @@ -1,5 +1,5 @@ "use strict"; define(['app', 'backbone.deepmodel'], function (App, DeepModel) { - NzbDrone.Settings.Notifications.Model = DeepModel.DeepModel.extend({ + return DeepModel.DeepModel.extend({ }); }); diff --git a/UI/Settings/Quality/Profile/EditQualityProfileView.js b/UI/Settings/Quality/Profile/EditQualityProfileView.js index 296e43e5c..aedf419b5 100644 --- a/UI/Settings/Quality/Profile/EditQualityProfileView.js +++ b/UI/Settings/Quality/Profile/EditQualityProfileView.js @@ -1,7 +1,7 @@ 'use strict'; -define(['app', 'Quality/QualityProfileModel'], function () { +define(['app', 'marionette', 'Mixins/AsModelBoundView'], function (App, Marionette, AsModelBoundView) { - NzbDrone.Settings.Quality.Profile.EditQualityProfileView = Backbone.Marionette.ItemView.extend({ + var view = Marionette.ItemView.extend({ template: 'Settings/Quality/Profile/EditQualityProfileTemplate', events: { @@ -51,8 +51,10 @@ define(['app', 'Quality/QualityProfileModel'], function () { this.model.save(); this.trigger('saved'); - NzbDrone.modalRegion.closeModal(); + App.modalRegion.closeModal(); } }); + return AsModelBoundView.call(view); + }); diff --git a/UI/Settings/Quality/Profile/QualityProfileCollectionView.js b/UI/Settings/Quality/Profile/QualityProfileCollectionView.js index bd83551af..b01c8e147 100644 --- a/UI/Settings/Quality/Profile/QualityProfileCollectionView.js +++ b/UI/Settings/Quality/Profile/QualityProfileCollectionView.js @@ -1,20 +1,9 @@ 'use strict'; -define(['app', 'Settings/Quality/Profile/QualityProfileView'], function () { - NzbDrone.Settings.Quality.Profile.QualityProfileCollectionView = Backbone.Marionette.CompositeView.extend({ - itemView : NzbDrone.Settings.Quality.Profile.QualityProfileView, +define(['marionette', 'Settings/Quality/Profile/QualityProfileView'], function (Marionette, QualityProfileView) { + return Marionette.CompositeView.extend({ + itemView : QualityProfileView, itemViewContainer: 'tbody', - template : 'Settings/Quality/Profile/QualityProfileCollectionTemplate', - - initialize: function (options) { - }, - - ui: { - - }, - - onCompositeCollectionRendered: function () { - - } + template : 'Settings/Quality/Profile/QualityProfileCollectionTemplate' }); }); diff --git a/UI/Settings/Quality/Profile/QualityProfileView.js b/UI/Settings/Quality/Profile/QualityProfileView.js index 35aa90677..90ec57911 100644 --- a/UI/Settings/Quality/Profile/QualityProfileView.js +++ b/UI/Settings/Quality/Profile/QualityProfileView.js @@ -2,12 +2,12 @@ define([ 'app', - 'Quality/QualityProfileCollection', + 'marionette', 'Settings/Quality/Profile/EditQualityProfileView' -], function () { +], function (App, Marionette, EditProfileView) { - NzbDrone.Settings.Quality.Profile.QualityProfileView = Backbone.Marionette.ItemView.extend({ + return Marionette.ItemView.extend({ template: 'Settings/Quality/Profile/QualityProfileTemplate', tagName : 'tr', @@ -21,8 +21,8 @@ define([ }, edit: function () { - var view = new NzbDrone.Settings.Quality.Profile.EditQualityProfileView({ model: this.model}); - NzbDrone.modalRegion.show(view); + var view = new EditProfileView({ model: this.model}); + App.modalRegion.show(view); }, removeQuality: function () { diff --git a/UI/Settings/Quality/QualityLayout.js b/UI/Settings/Quality/QualityLayout.js index 72335ae3b..668166ae1 100644 --- a/UI/Settings/Quality/QualityLayout.js +++ b/UI/Settings/Quality/QualityLayout.js @@ -1,13 +1,14 @@ "use strict"; define([ 'app', + 'marionette', 'Quality/QualityProfileCollection', - 'Quality/QualitySizeCollection', 'Settings/Quality/Profile/QualityProfileCollectionView', + 'Quality/QualitySizeCollection', 'Settings/Quality/Size/QualitySizeCollectionView' ], - function (app, qualityProfileCollection) { - NzbDrone.Settings.Quality.QualityLayout = Backbone.Marionette.Layout.extend({ + function (App, Marionette, QualityProfileCollection, QualityProfileCollectionView, QualitySizeCollection, QualitySizeCollectionView) { + return Marionette.Layout.extend({ template: 'Settings/Quality/QualityLayoutTemplate', regions: { @@ -16,24 +17,16 @@ define([ qualitySize : '#quality-size' }, - ui: { - - }, - - events: { - - }, - initialize: function (options) { this.settings = options.settings; - qualityProfileCollection.fetch(); - this.qualitySizeCollection = new NzbDrone.Quality.QualitySizeCollection(); + QualityProfileCollection.fetch(); + this.qualitySizeCollection = new QualitySizeCollection(); this.qualitySizeCollection.fetch(); }, onRender: function () { - this.qualityProfile.show(new NzbDrone.Settings.Quality.Profile.QualityProfileCollectionView({collection: qualityProfileCollection})); - this.qualitySize.show(new NzbDrone.Settings.Quality.Size.QualitySizeCollectionView({collection: this.qualitySizeCollection})); + this.qualityProfile.show(new QualityProfileCollectionView({collection: QualityProfileCollection})); + this.qualitySize.show(new QualitySizeCollectionView({collection: this.qualitySizeCollection})); } }); }); diff --git a/UI/Settings/Quality/Size/QualitySizeCollectionView.js b/UI/Settings/Quality/Size/QualitySizeCollectionView.js index d7c4acc9d..29b6f6b8f 100644 --- a/UI/Settings/Quality/Size/QualitySizeCollectionView.js +++ b/UI/Settings/Quality/Size/QualitySizeCollectionView.js @@ -1,21 +1,9 @@ 'use strict'; -define(['app', 'Settings/Quality/Size/QualitySizeView'], function () { - NzbDrone.Settings.Quality.Size.QualitySizeCollectionView = Backbone.Marionette.CompositeView.extend({ - itemView : NzbDrone.Settings.Quality.Size.QualitySizeView, +define(['marionette', 'Settings/Quality/Size/QualitySizeView'], function (Marionette, QualitySizeView) { + return Marionette.CompositeView.extend({ + itemView : QualitySizeView, itemViewContainer: '#quality-sizes-container', - template : 'Settings/Quality/Size/QualitySizeCollectionTemplate', - - initialize: function () { - - }, - - ui: { - - }, - - onCompositeCollectionRendered: function () { - - } + template : 'Settings/Quality/Size/QualitySizeCollectionTemplate' }); }); diff --git a/UI/Settings/Quality/Size/QualitySizeView.js b/UI/Settings/Quality/Size/QualitySizeView.js index 084f8ce2a..6317db37e 100644 --- a/UI/Settings/Quality/Size/QualitySizeView.js +++ b/UI/Settings/Quality/Size/QualitySizeView.js @@ -1,13 +1,8 @@ 'use strict'; -define([ - 'app', - 'Quality/QualitySizeCollection', - 'bootstrap.slider' +define(['marionette', 'bootstrap.slider'], function (Marionette) { -], function () { - - NzbDrone.Settings.Quality.Size.QualitySizeView = Backbone.Marionette.ItemView.extend({ + return Marionette.ItemView.extend({ template : 'Settings/Quality/Size/QualitySizeTemplate', className: 'quality-size-item', diff --git a/UI/Settings/SettingsLayout.js b/UI/Settings/SettingsLayout.js index 9cf1c0371..3bc37dec9 100644 --- a/UI/Settings/SettingsLayout.js +++ b/UI/Settings/SettingsLayout.js @@ -1,17 +1,37 @@ "use strict"; define([ 'app', + 'marionette', + 'Settings/SettingsModel', + 'Settings/General/GeneralSettingsModel', 'Settings/Naming/NamingView', + 'Settings/Naming/NamingModel', 'Settings/Quality/QualityLayout', 'Settings/Indexers/CollectionView', + 'Settings/Indexers/Collection', 'Settings/DownloadClient/DownloadClientView', 'Settings/Notifications/CollectionView', + 'Settings/Notifications/Collection', 'Settings/General/GeneralView', - 'Settings/General/GeneralSettingsModel', - 'Settings/Misc/MiscView' + 'Settings/Misc/MiscView', + 'Settings/SyncNotification' ], - function () { - NzbDrone.Settings.SettingsLayout = Backbone.Marionette.Layout.extend({ + function (App, + Marionette, + SettingsModel, + GeneralSettingsModel, + NamingView, + NamingModel, + QualityLayout, + IndexerCollectionView, + IndexerCollection, + DownloadClientView, + NotificationCollectionView, + NotificationCollection, + GeneralView, + MiscView, + SyncNotification) { + return Marionette.Layout.extend({ template: 'Settings/SettingsLayoutTemplate', regions: { @@ -51,7 +71,7 @@ define([ } this.ui.namingTab.tab('show'); - NzbDrone.Router.navigate('settings/naming'); + App.Router.navigate('settings/naming'); }, showQuality: function (e) { @@ -60,7 +80,7 @@ define([ } this.ui.qualityTab.tab('show'); - NzbDrone.Router.navigate('settings/quality'); + App.Router.navigate('settings/quality'); }, showIndexers: function (e) { @@ -69,7 +89,7 @@ define([ } this.ui.indexersTab.tab('show'); - NzbDrone.Router.navigate('settings/indexers'); + App.Router.navigate('settings/indexers'); }, showDownloadClient: function (e) { @@ -78,7 +98,7 @@ define([ } this.ui.downloadClientTab.tab('show'); - NzbDrone.Router.navigate('settings/downloadclient'); + App.Router.navigate('settings/downloadclient'); }, showNotifications: function (e) { @@ -87,7 +107,7 @@ define([ } this.ui.notificationsTab.tab('show'); - NzbDrone.Router.navigate('settings/notifications'); + App.Router.navigate('settings/notifications'); }, showGeneral: function (e) { @@ -96,7 +116,7 @@ define([ } this.ui.generalTab.tab('show'); - NzbDrone.Router.navigate('settings/general'); + App.Router.navigate('settings/general'); }, showMisc: function (e) { @@ -105,23 +125,23 @@ define([ } this.ui.miscTab.tab('show'); - NzbDrone.Router.navigate('settings/misc'); + App.Router.navigate('settings/misc'); }, initialize: function (options) { - this.settings = new NzbDrone.Settings.SettingsModel(); + this.settings = new SettingsModel(); this.settings.fetch(); - this.generalSettings = new NzbDrone.Settings.General.GeneralSettingsModel(); + this.generalSettings = new GeneralSettingsModel(); this.generalSettings.fetch(); - this.namingSettings = new NzbDrone.Settings.Naming.NamingModel(); + this.namingSettings = new NamingModel(); this.namingSettings.fetch(); - this.indexerSettings = new NzbDrone.Settings.Indexers.Collection(); + this.indexerSettings = new IndexerCollection(); this.indexerSettings.fetch(); - this.notificationSettings = new NzbDrone.Settings.Notifications.Collection(); + this.notificationSettings = new NotificationCollection(); this.notificationSettings.fetch(); if (options.action) { @@ -130,13 +150,13 @@ define([ }, onRender: function () { - this.naming.show(new NzbDrone.Settings.Naming.NamingView()); - this.quality.show(new NzbDrone.Settings.Quality.QualityLayout({settings: this.settings})); - this.indexers.show(new NzbDrone.Settings.Indexers.CollectionView({collection: this.indexerSettings})); - this.downloadClient.show(new NzbDrone.Settings.DownloadClient.DownloadClientView({model: this.settings})); - this.notifications.show(new NzbDrone.Settings.Notifications.CollectionView({collection: this.notificationSettings})); - this.general.show(new NzbDrone.Settings.General.GeneralView({model: this.generalSettings})); - this.misc.show(new NzbDrone.Settings.Misc.MiscView({model: this.settings})); + this.naming.show(new NamingView()); + this.quality.show(new QualityLayout({settings: this.settings})); + this.indexers.show(new IndexerCollectionView({collection: this.indexerSettings})); + this.downloadClient.show(new DownloadClientView({model: this.settings})); + this.notifications.show(new NotificationCollectionView({collection: this.notificationSettings})); + this.general.show(new GeneralView({model: this.generalSettings})); + this.misc.show(new MiscView({model: this.settings})); }, onShow: function () { @@ -166,11 +186,11 @@ define([ save: function () { - NzbDrone.vent.trigger(NzbDrone.Commands.SaveSettings); + App.vent.trigger(App.Commands.SaveSettings); - this.settings.saveIfChanged(undefined, NzbDrone.Settings.SyncNotificaiton.callback({ + this.settings.saveIfChanged(undefined, SyncNotification.callback({ successMessage: 'Settings saved', - errorMessage: "Failed to save settings" + errorMessage : "Failed to save settings" })); } }); diff --git a/UI/Settings/SettingsModel.js b/UI/Settings/SettingsModel.js index 56caa1ad0..19d097275 100644 --- a/UI/Settings/SettingsModel.js +++ b/UI/Settings/SettingsModel.js @@ -1,9 +1,10 @@ "use strict"; define(['app', - 'Mixins/SaveIfChangedModel'], function () { - NzbDrone.Settings.SettingsModel = Backbone.Model.extend({ - url: NzbDrone.Constants.ApiRoot + '/settings' + 'backbone', + 'Mixins/SaveIfChangedModel'], function (App, Backbone, AsChangeTrackingModel) { + var model = Backbone.Model.extend({ + url: App.Constants.ApiRoot + '/settings' }); - _.extend(NzbDrone.Settings.SettingsModel.prototype, NzbDrone.Mixins.SaveIfChangedModel); + return AsChangeTrackingModel.call(model); }); diff --git a/UI/Settings/SyncNotification.js b/UI/Settings/SyncNotification.js index 20962e72f..b722e6582 100644 --- a/UI/Settings/SyncNotification.js +++ b/UI/Settings/SyncNotification.js @@ -1,31 +1,27 @@ "use strict"; -define([ - 'app' -], - function () { - NzbDrone.Settings.SyncNotificaiton = { - callback: function (options) { - return { - success: function () { - if (options.successMessage) { - NzbDrone.Shared.Messenger.show({message: options.successMessage}); - } - - if (options.successCallback) { - options.successCallback.call(options.context); - } - }, - error : function () { - if (options.errorMessage) { - NzbDrone.Shared.Messenger.show({message: options.errorMessage, type: 'error'}); - } +define(['shared/messenger'], function (Messenger) { + return { + callback: function (options) { + return { + success: function () { + if (options.successMessage) { + Messenger.show({message: options.successMessage}); + } - if (options.errorCallback) { - options.errorCallback.call(options.context); - } + if (options.successCallback) { + options.successCallback.call(options.context); + } + }, + error : function () { + if (options.errorMessage) { + Messenger.show({message: options.errorMessage, type: 'error'}); } - }; - } - }; - }); + if (options.errorCallback) { + options.errorCallback.call(options.context); + } + } + }; + } + }; +}); diff --git a/UI/Shared/LoadingView.js b/UI/Shared/LoadingView.js index 42f0d9456..8a8873857 100644 --- a/UI/Shared/LoadingView.js +++ b/UI/Shared/LoadingView.js @@ -5,4 +5,6 @@ define(['app'], function () { template : 'Shared/LoadingTemplate', className: 'nz-loading row' }); -}); \ No newline at end of file + + return NzbDrone.Shared.LoadingView; +}); diff --git a/UI/Shared/Messenger.js b/UI/Shared/Messenger.js index d53399f1e..da850085f 100644 --- a/UI/Shared/Messenger.js +++ b/UI/Shared/Messenger.js @@ -1,6 +1,6 @@ "use strict"; -define(['app'], function () { - NzbDrone.Shared.Messenger = { +define(function () { + return { show: function (options) { if (!options.type) { diff --git a/UI/Shared/Toolbar/ToolbarLayout.js b/UI/Shared/Toolbar/ToolbarLayout.js index 6850be9ee..c8b8ef5cc 100644 --- a/UI/Shared/Toolbar/ToolbarLayout.js +++ b/UI/Shared/Toolbar/ToolbarLayout.js @@ -1,5 +1,10 @@ "use strict"; -define(['app', 'Shared/Toolbar/Radio/RadioButtonCollectionView','Shared/Toolbar/Button/ButtonCollectionView', 'Shared/Toolbar/ButtonCollection'], function () { +define([ + 'app', + 'Shared/Toolbar/Radio/RadioButtonCollectionView', + 'Shared/Toolbar/Button/ButtonCollectionView', + 'Shared/Toolbar/ButtonCollection' +], function () { NzbDrone.Shared.Toolbar.ToolbarLayout = Backbone.Marionette.Layout.extend({ template: 'Shared/Toolbar/ToolbarLayoutTemplate', @@ -89,6 +94,8 @@ define(['app', 'Shared/Toolbar/Radio/RadioButtonCollectionView','Shared/Toolbar/ } }); + return NzbDrone.Shared.Toolbar.ToolbarLayout; + }); diff --git a/UI/app.js b/UI/app.js index a7074cfab..8dba99cbe 100644 --- a/UI/app.js +++ b/UI/app.js @@ -2,22 +2,23 @@ require.config({ paths: { - 'backbone' : 'JsLibraries/backbone', - 'handlebars' : 'JsLibraries/handlebars.runtime', - 'bootstrap' : 'JsLibraries/bootstrap', - 'bootstrap.slider' : 'JsLibraries/bootstrap.slider', - 'backbone.mutators' : 'JsLibraries/backbone.mutators', - 'backbone.deepmodel': 'JsLibraries/backbone.deep.model', - 'backbone.pageable' : 'JsLibraries/backbone.pageable', - 'backgrid' : 'JsLibraries/backbone.backgrid', - 'backgrid.paginator': 'JsLibraries/backbone.backgrid.paginator', - 'fullcalendar' : 'JsLibraries/fullcalendar', - 'backstrech' : 'JsLibraries/jquery.backstretch', - '$' : 'JsLibraries/jquery', - 'underscore' : 'JsLibraries/underscore', - 'marionette' : 'JsLibraries/backbone.marionette', - 'signalR' : 'JsLibraries/jquery.signalR', - 'libs' : 'JsLibraries/' + 'backbone' : 'JsLibraries/backbone', + 'handlebars' : 'JsLibraries/handlebars.runtime', + 'bootstrap' : 'JsLibraries/bootstrap', + 'bootstrap.slider' : 'JsLibraries/bootstrap.slider', + 'backbone.mutators' : 'JsLibraries/backbone.mutators', + 'backbone.deepmodel' : 'JsLibraries/backbone.deep.model', + 'backbone.pageable' : 'JsLibraries/backbone.pageable', + 'backbone.modelbinder': 'JsLibraries/backbone.modelbinder', + 'backgrid' : 'JsLibraries/backbone.backgrid', + 'backgrid.paginator' : 'JsLibraries/backbone.backgrid.paginator', + 'fullcalendar' : 'JsLibraries/fullcalendar', + 'backstrech' : 'JsLibraries/jquery.backstretch', + '$' : 'JsLibraries/jquery', + 'underscore' : 'JsLibraries/underscore', + 'marionette' : 'JsLibraries/backbone.marionette', + 'signalR' : 'JsLibraries/jquery.signalR', + 'libs' : 'JsLibraries/' }, shim: { @@ -53,10 +54,15 @@ require.config({ }, marionette: { - deps : ['backbone', 'mixins/backbone.marionette.templates'], + deps : [ + 'backbone', + 'mixins/backbone.marionette.templates', + 'mixins/AsNamedView' + ], exports: 'Marionette', - init : function (Backbone, TemplateMixin) { + init : function (Backbone, TemplateMixin, AsNamedView) { TemplateMixin.call(Marionette.TemplateCache); + AsNamedView.call(Marionette.ItemView.prototype); } }, @@ -143,19 +149,6 @@ define([ window.NzbDrone.Calendar = {}; - window.NzbDrone.Settings = { - Naming : {}, - Quality : { - Size : {}, - Profile: {} - }, - Indexers : {}, - DownloadClient: {}, - Notifications : {}, - General : {}, - Misc : {} - }; - window.NzbDrone.Missing = {}; window.NzbDrone.History = {}; window.NzbDrone.Logs = {}; @@ -171,8 +164,8 @@ define([ }; window.NzbDrone.Constants = { - ApiRoot: '/api', - Version: '0.0.0.0', + ApiRoot : '/api', + Version : '0.0.0.0', BuildDate: '2013-01-01T00:00:00Z' };