From 72772bed5a816b448f7bf1b384d59e3723ed3f44 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 20 Jun 2013 22:19:41 -0700 Subject: [PATCH] moved add series to require. --- UI/AddSeries/Collection.js | 2 +- UI/AddSeries/RootFolders/Collection.js | 10 +- UI/AddSeries/RootFolders/Layout.js | 2 +- UI/AddSeries/RootFolders/Model.js | 26 +-- ...e.html => RootFolderSelectionPartial.html} | 4 +- .../RootFolders/RootFolderTemplateHelper.js | 13 -- UI/AddSeries/SearchResultTemplate.html | 8 +- UI/AddSeries/SearchResultView.js | 18 +- UI/Controller.js | 42 ++--- ...ml => QualityProfileSelectionPartial.html} | 0 UI/Quality/QualityProfileTemplateHelper.js | 10 -- UI/RouteBinder.js | 17 +- UI/Router.js | 21 ++- UI/Series/Index/List/ItemView.js | 3 +- UI/Shared/Toolbar/ToolbarLayout.js | 155 +++++++++--------- UI/app.js | 15 +- 16 files changed, 171 insertions(+), 175 deletions(-) rename UI/AddSeries/RootFolders/{RootFolderSelectionTemplate.html => RootFolderSelectionPartial.html} (89%) delete mode 100644 UI/AddSeries/RootFolders/RootFolderTemplateHelper.js rename UI/Quality/{QualityProfileSelectionTemplate.html => QualityProfileSelectionPartial.html} (100%) delete mode 100644 UI/Quality/QualityProfileTemplateHelper.js diff --git a/UI/AddSeries/Collection.js b/UI/AddSeries/Collection.js index c0c59b434..97ee6ee6d 100644 --- a/UI/AddSeries/Collection.js +++ b/UI/AddSeries/Collection.js @@ -1,7 +1,7 @@ "use strict"; define( [ - 'App', + 'app', 'backbone', 'Series/SeriesModel' ], function (App, Backbone, SeriesModel) { diff --git a/UI/AddSeries/RootFolders/Collection.js b/UI/AddSeries/RootFolders/Collection.js index 91bb78cac..4b4822941 100644 --- a/UI/AddSeries/RootFolders/Collection.js +++ b/UI/AddSeries/RootFolders/Collection.js @@ -1,15 +1,17 @@ "use strict"; define( [ - 'app', + 'backbone', 'AddSeries/RootFolders/Model', 'mixins/backbone.signalr.mixin' - ], function () { + ], function (Backbone, RootFolderModel) { var rootFolderCollection = Backbone.Collection.extend({ url : NzbDrone.Constants.ApiRoot + '/rootfolder', - model: NzbDrone.AddSeries.RootFolders.RootFolderModel + model: RootFolderModel }); - return new rootFolderCollection().BindSignalR(); + var collection = new rootFolderCollection().BindSignalR(); + + return collection; }); diff --git a/UI/AddSeries/RootFolders/Layout.js b/UI/AddSeries/RootFolders/Layout.js index 6d4f18ce7..af1877625 100644 --- a/UI/AddSeries/RootFolders/Layout.js +++ b/UI/AddSeries/RootFolders/Layout.js @@ -4,8 +4,8 @@ define( [ 'marionette', 'AddSeries/RootFolders/CollectionView', - 'AddSeries/RootFolders/Model', 'AddSeries/RootFolders/Collection', + 'AddSeries/RootFolders/Model', 'Mixins/AutoComplete' ], function (Marionette, RootFolderCollectionView, RootFolderCollection, RootFolderModel) { diff --git a/UI/AddSeries/RootFolders/Model.js b/UI/AddSeries/RootFolders/Model.js index 9719c997f..6854a717a 100644 --- a/UI/AddSeries/RootFolders/Model.js +++ b/UI/AddSeries/RootFolders/Model.js @@ -1,14 +1,18 @@ "use strict"; -define(['app'], function () { - NzbDrone.AddSeries.RootFolders.RootFolderModel = Backbone.Model.extend({ - mutators: { - freeSpaceString: function () { - return this.get('freeSpace').bytes(2) + " Free"; - } - }, +define( + [ + 'backbone', + 'sugar' + ], function (Backbone) { + return Backbone.Model.extend({ + mutators: { + freeSpaceString: function () { + return this.get('freeSpace').bytes(2) + " Free"; + } + }, - defaults: { - freeSpace: 0 - } + defaults: { + freeSpace: 0 + } + }); }); -}); diff --git a/UI/AddSeries/RootFolders/RootFolderSelectionTemplate.html b/UI/AddSeries/RootFolders/RootFolderSelectionPartial.html similarity index 89% rename from UI/AddSeries/RootFolders/RootFolderSelectionTemplate.html rename to UI/AddSeries/RootFolders/RootFolderSelectionPartial.html index c562eb0f6..c0489dd8c 100644 --- a/UI/AddSeries/RootFolders/RootFolderSelectionTemplate.html +++ b/UI/AddSeries/RootFolders/RootFolderSelectionPartial.html @@ -3,4 +3,6 @@ {{/each}} - \ No newline at end of file + + +{{debug}} diff --git a/UI/AddSeries/RootFolders/RootFolderTemplateHelper.js b/UI/AddSeries/RootFolders/RootFolderTemplateHelper.js deleted file mode 100644 index d49483b42..000000000 --- a/UI/AddSeries/RootFolders/RootFolderTemplateHelper.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -define( - [ - 'AddSeries/RootFolders/Collection', - 'handlebars' - ], function (rootFolders, Handlebars) { - - Handlebars.registerHelper('rootFolderSelection', function () { - var templateFunction = Marionette.TemplateCache.get('AddSeries/RootFolders/RootFolderSelectionTemplate'); - return new Handlebars.SafeString(templateFunction(rootFolders.toJSON())); - }); - }); diff --git a/UI/AddSeries/SearchResultTemplate.html b/UI/AddSeries/SearchResultTemplate.html index c3180cb0d..da6a2ec73 100644 --- a/UI/AddSeries/SearchResultTemplate.html +++ b/UI/AddSeries/SearchResultTemplate.html @@ -2,7 +2,8 @@
@@ -19,12 +20,13 @@
{{#unless isExisting}} - {{rootFolderSelection}} + {{> RootFolderSelectionPartial rootFolders}} {{/unless}}
- {{qualityProfileSelection}} + {{> QualityProfileSelectionPartial qualityProfiles}}
+{{debug}} diff --git a/UI/AddSeries/SearchResultView.js b/UI/AddSeries/SearchResultView.js index 242370f7d..94bbf9d34 100644 --- a/UI/AddSeries/SearchResultView.js +++ b/UI/AddSeries/SearchResultView.js @@ -3,11 +3,12 @@ define( [ 'app', 'marionette', - 'Config', + 'Quality/QualityProfileCollection', + 'AddSeries/RootFolders/Collection', 'Series/SeriesCollection', - 'Shared/Messenger', - 'Quality/QualityProfileCollection' - ], function (App, Marionette, Config, SeriesCollection, Messenger, QualityProfiles) { + 'Config', + 'Shared/Messenger' + ], function (App, Marionette, QualityProfiles, RootFolders, SeriesCollection, Config, Messenger) { return Marionette.ItemView.extend({ @@ -88,8 +89,15 @@ define( icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); } }); + }, + + serializeData: function () { + var data = this.model.toJSON(); + data.rootFolders = RootFolders.toJSON(); + data.qualityProfiles = QualityProfiles.toJSON(); + + return data; } }); - }); diff --git a/UI/Controller.js b/UI/Controller.js index df2f000af..8057fd005 100644 --- a/UI/Controller.js +++ b/UI/Controller.js @@ -1,23 +1,25 @@ "use strict"; -define(['app', - 'Settings/SettingsLayout', - 'Form/FormBuilder', - 'AddSeries/AddSeriesLayout', - 'Series/Index/SeriesIndexLayout', - 'Calendar/CalendarLayout', - 'Shared/NotificationView', - 'Shared/NotFoundView', - 'MainMenuView', - 'Series/Details/SeriesDetailsLayout', - 'Series/EpisodeCollection', - 'Logs/Layout', - 'Release/Layout', - 'Missing/MissingLayout', - 'History/HistoryLayout', - 'Shared/FormatHelpers', - 'Shared/TemplateHelpers', - 'Shared/Footer/View'], - function (App, SettingsLayout) { +define( + [ + 'app', + 'Settings/SettingsLayout', + 'AddSeries/AddSeriesLayout', + 'Form/FormBuilder', + 'Series/Index/SeriesIndexLayout', + 'Calendar/CalendarLayout', + 'Shared/NotificationView', + 'Shared/NotFoundView', + 'MainMenuView', + 'Series/Details/SeriesDetailsLayout', + 'Series/EpisodeCollection', + 'Logs/Layout', + 'Release/Layout', + 'Missing/MissingLayout', + 'History/HistoryLayout', + 'Shared/FormatHelpers', + 'Shared/TemplateHelpers', + 'Shared/Footer/View' + ], function (App, SettingsLayout, AddSeriesLayout) { var controller = Backbone.Marionette.Controller.extend({ series : function () { @@ -39,7 +41,7 @@ define(['app', addSeries: function (action) { this._setTitle('Add Series'); - App.mainRegion.show(new NzbDrone.AddSeries.AddSeriesLayout({action: action})); + App.mainRegion.show(new AddSeriesLayout({action: action})); }, calendar: function () { diff --git a/UI/Quality/QualityProfileSelectionTemplate.html b/UI/Quality/QualityProfileSelectionPartial.html similarity index 100% rename from UI/Quality/QualityProfileSelectionTemplate.html rename to UI/Quality/QualityProfileSelectionPartial.html diff --git a/UI/Quality/QualityProfileTemplateHelper.js b/UI/Quality/QualityProfileTemplateHelper.js deleted file mode 100644 index 98e800b60..000000000 --- a/UI/Quality/QualityProfileTemplateHelper.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict'; - -define(['app', 'Quality/QualityProfileCollection','handlebars'], function (app, qualityProfiles,Handlebars) { - - Handlebars.registerHelper('qualityProfileSelection', function () { - - var templateFunction = Marionette.TemplateCache.get('Quality/QualityProfileSelectionTemplate'); - return new Handlebars.SafeString(templateFunction(qualityProfiles.toJSON())); - }); -}); diff --git a/UI/RouteBinder.js b/UI/RouteBinder.js index 6710099a8..fc76a63ed 100644 --- a/UI/RouteBinder.js +++ b/UI/RouteBinder.js @@ -1,23 +1,18 @@ "use strict"; define(function () { - //This module will automatically route all links through backbone router rather than //causing links to reload pages. var routeBinder = { bind: function (router) { - - this._router = router; - - $(document).on('click', 'a[href]', this._handleClick); - }, - - _isInTab: function (element) { - return; + var self = this; + $(document).on('click', 'a[href]', function (event) { + self._handleClick(event, router); + }); }, - _handleClick: function (event) { + _handleClick: function (event, router) { var $target = $(event.target); //check if tab nav @@ -47,7 +42,7 @@ define(function () { if (!href.startsWith('http')) { - this._router.navigate(href, { trigger: true }); + router.navigate(href, { trigger: true }); } else { diff --git a/UI/Router.js b/UI/Router.js index 37df317cd..07c76295f 100644 --- a/UI/Router.js +++ b/UI/Router.js @@ -1,11 +1,13 @@ "use strict"; require( [ + 'app', 'marionette', - 'Controller' - ], function (Marionette, Controller) { + 'Controller', + 'RouteBinder' + ], function (App, Marionette, Controller, RouterBinder) { - return Marionette.AppRouter.extend({ + NzbDrone.Router = Marionette.AppRouter.extend({ controller: Controller, appRoutes : { @@ -25,5 +27,18 @@ require( ':whatever' : 'notFound' } }); + + NzbDrone.addInitializer(function () { + + NzbDrone.Router = new NzbDrone.Router(); + Backbone.history.start({ pushState: true }); + + RouterBinder.bind(NzbDrone.Router); + // NzbDrone.footerRegion.show(new FooterView()); + }); + + + return NzbDrone.Router; + }); diff --git a/UI/Series/Index/List/ItemView.js b/UI/Series/Index/List/ItemView.js index 1cf32b1a6..355e249a5 100644 --- a/UI/Series/Index/List/ItemView.js +++ b/UI/Series/Index/List/ItemView.js @@ -5,7 +5,8 @@ define([ 'Quality/QualityProfileCollection', 'Series/SeriesCollection', 'Series/Edit/EditSeriesView', - 'Series/Delete/DeleteSeriesView' + 'Series/Delete/DeleteSeriesView', + 'Shared/FormatHelpers' ], function () { NzbDrone.Series.Index.List.ItemView = Backbone.Marionette.ItemView.extend({ diff --git a/UI/Shared/Toolbar/ToolbarLayout.js b/UI/Shared/Toolbar/ToolbarLayout.js index c8b8ef5cc..00049918e 100644 --- a/UI/Shared/Toolbar/ToolbarLayout.js +++ b/UI/Shared/Toolbar/ToolbarLayout.js @@ -1,102 +1,101 @@ "use strict"; -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', - - regions: { - left_1 : '.x-toolbar-left-1', - left_2 : '.x-toolbar-left-2', - right_1: '.x-toolbar-right-1', - right_2: '.x-toolbar-right-2' - }, - - initialize: function (options) { - - if (!options) { - throw 'options needs to be passed'; - } +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', + + regions: { + left_1 : '.x-toolbar-left-1', + left_2 : '.x-toolbar-left-2', + right_1: '.x-toolbar-right-1', + right_2: '.x-toolbar-right-2' + }, + + initialize: function (options) { + + if (!options) { + throw 'options needs to be passed'; + } - if (!options.context) { - throw 'context needs to be passed'; - } + if (!options.context) { + throw 'context needs to be passed'; + } - this.left = options.left; - this.right = options.right; - this.toolbarContext = options.context; + this.left = options.left; + this.right = options.right; + this.toolbarContext = options.context; - }, + }, - onShow: function () { - if (this.left) { - _.each(this.left, this._showToolbarLeft, this); - } - if (this.right) { - _.each(this.right, this._showToolbarRight, this); - } - }, + onShow: function () { + if (this.left) { + _.each(this.left, this._showToolbarLeft, this); + } + if (this.right) { + _.each(this.right, this._showToolbarRight, this); + } + }, - _showToolbarLeft: function (element, index) { - this._showToolbar(element, index, 'left'); - }, + _showToolbarLeft: function (element, index) { + this._showToolbar(element, index, 'left'); + }, - _showToolbarRight: function (element, index) { - this._showToolbar(element, index, 'right'); - }, + _showToolbarRight: function (element, index) { + this._showToolbar(element, index, 'right'); + }, - _showToolbar: function (buttonGroup, index, position) { + _showToolbar: function (buttonGroup, index, position) { - var groupCollection = new NzbDrone.Shared.Toolbar.ButtonCollection(); + var groupCollection = new NzbDrone.Shared.Toolbar.ButtonCollection(); - _.each(buttonGroup.items, function (button) { + _.each(buttonGroup.items, function (button) { - if (buttonGroup.storeState && !button.key) { - throw 'must provide key for all buttons when storSstate is enabled'; - } + if (buttonGroup.storeState && !button.key) { + throw 'must provide key for all buttons when storSstate is enabled'; + } - var model = new NzbDrone.Shared.Toolbar.ButtonModel(button); - model.set('menuKey', buttonGroup.menuKey); - model.ownerContext = this.toolbarContext; - groupCollection.add(model); + var model = new NzbDrone.Shared.Toolbar.ButtonModel(button); + model.set('menuKey', buttonGroup.menuKey); + model.ownerContext = this.toolbarContext; + groupCollection.add(model); - }, this); + }, this); - var buttonGroupView; + var buttonGroupView; - switch (buttonGroup.type) { - case 'radio': - { - buttonGroupView = new NzbDrone.Shared.Toolbar.RadioButtonCollectionView( - { - collection: groupCollection, - menu : buttonGroup - }); - break; + switch (buttonGroup.type) { + case 'radio': + { + buttonGroupView = new NzbDrone.Shared.Toolbar.RadioButtonCollectionView({ + collection: groupCollection, + menu : buttonGroup + }); + break; + } + default : + { + buttonGroupView = new NzbDrone.Shared.Toolbar.ButtonCollectionView({ + collection: groupCollection, + menu : buttonGroup + }); + break; + } } - default : - { - buttonGroupView = new NzbDrone.Shared.Toolbar.ButtonCollectionView( - { - collection: groupCollection, - menu : buttonGroup - }); - break; - } - } - this[position + '_' + (index + 1).toString()].show(buttonGroupView); - } - }); + this[position + '_' + (index + 1).toString()].show(buttonGroupView); + } + }); - return NzbDrone.Shared.Toolbar.ToolbarLayout; + return NzbDrone.Shared.Toolbar.ToolbarLayout; -}); + }); diff --git a/UI/app.js b/UI/app.js index b7cd9f031..3c76d590e 100644 --- a/UI/app.js +++ b/UI/app.js @@ -148,10 +148,9 @@ define( [ 'marionette', 'shared/modal/region', - 'router', 'Instrumentation/StringFormat', 'Instrumentation/ErrorHandler' - ], function (Marionette, ModalRegion, Router, RouteBinder) { + ], function (Marionette, ModalRegion) { require( [ @@ -175,12 +174,6 @@ define( Details: {} }; - window.NzbDrone.AddSeries = { - New : {}, - Existing : {}, - RootFolders: {} - }; - window.NzbDrone.Episode = { Search : {}, Summary : {}, @@ -236,16 +229,12 @@ define( window.NzbDrone.start(); - NzbDrone.Router = new Router(); - Backbone.history.start({ pushState: true }); - - RouteBinder.bind(NzbDrone.Router); //NzbDrone.footerRegion.show(new FooterView()); window.require( [ - 'Routing' + 'Router' ]); return NzbDrone;