From c511292abecfad94384708d4f18ad2785c8e34db Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 29 Jan 2013 22:52:31 -0800 Subject: [PATCH] added more import code in ui. some jshint cleanup. --- .../ExternalNotificationBase.cs | 4 +-- NzbDrone.Core/Providers/RootDirProvider.cs | 4 +-- NzbDrone.Web/NzbDrone.Web.csproj | 1 + .../AddNewSeries/AddNewSeriesView.js | 21 ++++++------ .../AddNewSeries/SearchResultTemplate.html | 33 +++++++++--------- .../AddNewSeries/SearchResultView.js | 17 ++++++---- .../_backboneApp/AddSeries/AddSeriesLayout.js | 34 +++++++++++-------- .../ImportSeriesTemplate.html | 18 +++++++--- .../ImportExistingSeries/ImportSeriesView.js | 16 ++++----- .../AddSeries/RootDir/RootDirView.js | 13 +++---- .../Quality/qualityProfileModel.js | 2 +- .../_backboneApp/Shared/NotificationModel.js | 6 ++-- .../_backboneApp/Shared/NotificationView.js | 8 +++-- .../_backboneApp/Shared/SpinnerView.js | 2 +- NzbDrone.Web/_backboneApp/app.js | 24 ++++++------- 15 files changed, 112 insertions(+), 91 deletions(-) diff --git a/NzbDrone.Core/Providers/ExternalNotification/ExternalNotificationBase.cs b/NzbDrone.Core/Providers/ExternalNotification/ExternalNotificationBase.cs index 43fe7bec3..c5192ccc5 100644 --- a/NzbDrone.Core/Providers/ExternalNotification/ExternalNotificationBase.cs +++ b/NzbDrone.Core/Providers/ExternalNotification/ExternalNotificationBase.cs @@ -1,6 +1,4 @@ -using System; -using NLog; -using NzbDrone.Core.Model; +using NLog; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs index 3e1ef5bc2..aec0ceefa 100644 --- a/NzbDrone.Core/Providers/RootDirProvider.cs +++ b/NzbDrone.Core/Providers/RootDirProvider.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.IO; using NLog; using NzbDrone.Common; -using NzbDrone.Core.Model; -using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Repository; using PetaPoco; @@ -70,7 +68,7 @@ namespace NzbDrone.Core.Providers { if (!_seriesProvider.SeriesPathExists(seriesFolder)) { - results.Add(seriesFolder.Normalize()); + results.Add(new DirectoryInfo(seriesFolder.Normalize()).Name); } } diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 9fcca2db3..311633649 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -25,6 +25,7 @@ 4.0 ..\ true + \_backboneApp\JsLibraries\|\Scripts\ true diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/AddNewSeriesView.js b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/AddNewSeriesView.js index f114c2b8d..d15551c91 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/AddNewSeriesView.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/AddNewSeriesView.js @@ -1,27 +1,28 @@ -/// +'use strict;' +/// /// NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.Layout.extend({ - template: "AddSeries/AddNewSeries/AddNewSeriesTemplate", - route: "Series/add/new", + template: 'AddSeries/AddNewSeries/AddNewSeriesTemplate', + route: 'Series/add/new', ui: { seriesSearch: '.search input' }, regions: { - searchResult: "#search-result", + searchResult: '#search-result', }, collection: new NzbDrone.AddSeries.SearchResultCollection(), initialize: function (options) { if (options.rootFolders === undefined) { - throw "rootFolder arg is required."; + throw 'rootFolder arg. is required.'; } if (options.qualityProfiles === undefined) { - throw "qualityProfiles arg is required."; + throw 'qualityProfiles arg. is required.'; } this.rootFoldersCollection = options.rootFolders; @@ -31,12 +32,12 @@ NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.Layout.extend({ onRender: function () { console.log('binding auto complete'); var self = this; - + this.ui.seriesSearch .data('timeout', null) .keyup(function () { - clearTimeout(self.$el.data('timeout')); - self.$el.data('timeout', setTimeout(self.search, 500, self)); + window.clearTimeout(self.$el.data('timeout')); + self.$el.data('timeout', window.setTimeout(self.search, 500, self)); }); this.resultView = new NzbDrone.AddSeries.SearchResultView({ collection: this.collection }); @@ -48,7 +49,7 @@ NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.Layout.extend({ var term = context.ui.seriesSearch.val(); context.collection.reset(); - if (term != "") { + if (term !== '') { context.searchResult.show(new NzbDrone.Shared.SpinnerView()); context.collection.fetch({ diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultTemplate.html b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultTemplate.html index fe5368668..ae141ae57 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultTemplate.html +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultTemplate.html @@ -1,21 +1,22 @@ - -
-
- + {{#each rootFolders.models}} - {{/each}} - - + -
+ {{/each}} + +
+
-
diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultView.js b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultView.js index 7c1f738f7..26cfaa959 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultView.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddNewSeries/SearchResultView.js @@ -1,4 +1,6 @@ -/// +'use strict'; +/*global NzbDrone, Backbone*/ +/// /// /// /// @@ -6,11 +8,12 @@ NzbDrone.AddSeries.SearchItemView = Backbone.Marionette.ItemView.extend({ template: "AddSeries/AddNewSeries/SearchResultTemplate", - className: 'search-item accordion-group', + className: 'search-item', ui: { qualityProfile: '.x-quality-profile', - rootFolder: '.x-root-folder' + rootFolder: '.x-root-folder', + addButton: '.x-add' }, events: { @@ -38,6 +41,8 @@ NzbDrone.AddSeries.SearchItemView = Backbone.Marionette.ItemView.extend({ path: path }); + var self = this; + model.save(undefined, { success: function () { var notificationModel = new NzbDrone.Shared.NotificationModel({ @@ -47,6 +52,7 @@ NzbDrone.AddSeries.SearchItemView = Backbone.Marionette.ItemView.extend({ }); NzbDrone.Shared.NotificationCollectionView.Instance.collection.add(notificationModel); + self.close(); } }); } @@ -62,8 +68,5 @@ NzbDrone.AddSeries.SearchResultView = Backbone.Marionette.CollectionView.extend( initialize: function () { this.listenTo(this.collection, 'reset', this.render); - }, - - - + } }); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js b/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js index 247ee979c..c6ceb2d56 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js @@ -6,29 +6,31 @@ /// NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ - template: "AddSeries/addSeriesLayoutTemplate", + template: 'AddSeries/addSeriesLayoutTemplate', regions: { - addNew: "#add-new", - importExisting: "#import-existing", - rootFolders: "#root-folders" + addNew: '#add-new', + importExisting: '#import-existing', + rootFolders: '#root-folders' }, ui: { - addNewTab: ".x-add-new-tab", - importExistingTab: ".x-import-existing-tab", - rootFoldersTab: ".x-root-folders-tab", + addNewTab: '.x-add-new-tab', + importExistingTab: '.x-import-existing-tab', + rootFoldersTab: '.x-root-folders-tab' }, events: { - "click .x-add-new-tab": 'showAddNew', - "click .x-import-existing-tab": 'showImport', - "click .x-root-folders-tab": 'showRootFolders', + 'click .x-add-new-tab': 'showAddNew', + 'click .x-import-existing-tab': 'showImport', + 'click .x-root-folders-tab': 'showRootFolders' }, showAddNew: function (e) { - if (e) e.preventDefault(); + if (e) { + e.preventDefault(); + } this.ui.addNewTab.tab('show'); NzbDrone.Router.navigate('series/add/new'); @@ -36,14 +38,18 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ }, showImport: function (e) { - if (e) e.preventDefault(); + if (e) { + e.preventDefault(); + } this.ui.importExistingTab.tab('show'); NzbDrone.Router.navigate('series/add/import'); }, showRootFolders: function (e) { - if (e) e.preventDefault(); + if (e) { + e.preventDefault(); + } this.ui.rootFoldersTab.tab('show'); NzbDrone.Router.navigate('series/add/rootfolders'); @@ -90,7 +96,7 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ }, evaluateActions: function () { - if (this.rootFolderCollection.length == 0) { + if (this.rootFolderCollection.length === 0) { this.ui.addNewTab.hide(); this.ui.importExistingTab.hide(); this.showRootFolders(); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesTemplate.html b/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesTemplate.html index 0bf996b91..282e553cd 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesTemplate.html +++ b/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesTemplate.html @@ -1,5 +1,15 @@ -{{#each unmappedFolders}} -
- {{this}} +
+

{{path}}

+ {{#each unmappedFolders}} +
+
+ {{this}} +
+
+
+ {{this}} +
+
+
+ {{/each}}
-{{/each}} diff --git a/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesView.js b/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesView.js index 35cd10395..963ec3ebc 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesView.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/ImportExistingSeries/ImportSeriesView.js @@ -1,28 +1,28 @@ -/// +'use strict'; +/*global NzbDrone, Backbone*/ + +/// /// /// - NzbDrone.AddSeries.ExistingFolderItemView = Backbone.Marionette.ItemView.extend({ template: "AddSeries/ImportExistingSeries/ImportSeriesTemplate", events: { //'click .x-add': 'add' - }, - + } }); NzbDrone.AddSeries.ExistingFolderListView = Backbone.Marionette.CollectionView.extend({ itemView: NzbDrone.AddSeries.ExistingFolderItemView, - initialize: function (options) { + initialize: function () { if (this.collection === undefined) { throw "root folder collection is required."; } - + this.listenTo(this.collection, 'reset', this.render, this); - }, - + } }); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirView.js b/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirView.js index 29ed1390f..348e945b5 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirView.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/RootDir/RootDirView.js @@ -1,10 +1,11 @@ -/// +'use strict;' +/// /// /// NzbDrone.AddSeries.RootDirItemView = Backbone.Marionette.ItemView.extend({ - template: "AddSeries/RootDir/RootDirItemTemplate", + template: 'AddSeries/RootDir/RootDirItemTemplate', tagName: 'tr', events: { @@ -30,15 +31,15 @@ NzbDrone.AddSeries.RootDirListView = Backbone.Marionette.CollectionView.extend({ }); NzbDrone.AddSeries.RootDirView = Backbone.Marionette.Layout.extend({ - template: "AddSeries/RootDir/RootDirTemplate", - route: "series/add/rootdir", + template: 'AddSeries/RootDir/RootDirTemplate', + route: 'series/add/rootdir', ui: { pathInput: '.x-path input' }, regions: { - currentDirs: "#current-dirs", + currentDirs: '#current-dirs', }, events: { @@ -74,7 +75,7 @@ NzbDrone.AddSeries.RootDirView = Backbone.Marionette.Layout.extend({ var term = context.ui.seriesSearch.val(); - if (term == "") { + if (term === "") { context.collection.reset(); } else { console.log(term); diff --git a/NzbDrone.Web/_backboneApp/Quality/qualityProfileModel.js b/NzbDrone.Web/_backboneApp/Quality/qualityProfileModel.js index 9db408c1f..a5fdd862d 100644 --- a/NzbDrone.Web/_backboneApp/Quality/qualityProfileModel.js +++ b/NzbDrone.Web/_backboneApp/Quality/qualityProfileModel.js @@ -13,7 +13,7 @@ NzbDrone.Quality.QualityProfileModel = Backbone.Model.extend({ //}; //Todo: Cutoff should be something that is allowed (double check) this.validators.cutoff = function (value) { - return value != null ? { isValid: true } : { isValid: false, message: 'You must have a valid cutoff' }; + return value !== null ? { isValid: true } : { isValid: false, message: 'You must have a valid cutoff' }; }; }, diff --git a/NzbDrone.Web/_backboneApp/Shared/NotificationModel.js b/NzbDrone.Web/_backboneApp/Shared/NotificationModel.js index 162f8f28d..0c875a21f 100644 --- a/NzbDrone.Web/_backboneApp/Shared/NotificationModel.js +++ b/NzbDrone.Web/_backboneApp/Shared/NotificationModel.js @@ -19,13 +19,13 @@ NzbDrone.Shared.NotificationModel = Backbone.Model.extend({ return "icon"; } - if (this.get('level') == 'info') { + if (this.get('level') === 'info') { return "icon-info-sign"; } - else if (this.get('level') == 'success') { + else if (this.get('level') === 'success') { return 'icon-ok-sign'; } - else if (this.get('level') == 'error') { + else if (this.get('level') === 'error') { return 'icon-warning-sign'; } diff --git a/NzbDrone.Web/_backboneApp/Shared/NotificationView.js b/NzbDrone.Web/_backboneApp/Shared/NotificationView.js index ba248a67b..acedefcfc 100644 --- a/NzbDrone.Web/_backboneApp/Shared/NotificationView.js +++ b/NzbDrone.Web/_backboneApp/Shared/NotificationView.js @@ -46,12 +46,12 @@ window.onerror = function (msg, url, line) { var a = document.createElement('a'); a.href = url; - model.set('title', a.pathname.split('/').pop() + " : " + line); + model.set('title', a.pathname.split('/').pop() + ' : ' + line); model.set('message', msg); model.set('level', 'error'); NzbDrone.Shared.NotificationCollectionView.Instance.collection.add(model); } catch (error) { - alert("Couldn't report JS error. " + error); + alert('Couldn\'t report JS error. ' + error); } var suppressErrorAlert = false; @@ -60,7 +60,9 @@ window.onerror = function (msg, url, line) { $(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) { - if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) return; + if (xmlHttpRequest.status >= 200 && xmlHttpRequest.status <= 300) { + return; + } var model = new NzbDrone.Shared.NotificationModel(); model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText); model.set('message', xmlHttpRequest.responseText); diff --git a/NzbDrone.Web/_backboneApp/Shared/SpinnerView.js b/NzbDrone.Web/_backboneApp/Shared/SpinnerView.js index 9c04c03c2..ac15457a3 100644 --- a/NzbDrone.Web/_backboneApp/Shared/SpinnerView.js +++ b/NzbDrone.Web/_backboneApp/Shared/SpinnerView.js @@ -2,7 +2,7 @@ NzbDrone.Shared.SpinnerView = Backbone.Marionette.ItemView.extend({ - template: "Shared/SpinnerTemplate", + template: 'Shared/SpinnerTemplate', className: 'nz-spinner row', }); diff --git a/NzbDrone.Web/_backboneApp/app.js b/NzbDrone.Web/_backboneApp/app.js index 3ef1e704b..39d91f55a 100644 --- a/NzbDrone.Web/_backboneApp/app.js +++ b/NzbDrone.Web/_backboneApp/app.js @@ -12,15 +12,15 @@ /// /// -if (typeof console == "undefined") { +if (typeof console === undefined) { window.console = { log: function () { } }; } NzbDrone = new Backbone.Marionette.Application(); -NzbDrone.Series = NzbDrone.module("Series"); -NzbDrone.AddSeries = NzbDrone.module("AddSeries"); -NzbDrone.Quality = NzbDrone.module("Quality"); -NzbDrone.Shared = NzbDrone.module("Shared"); +NzbDrone.Series = NzbDrone.module('Series'); +NzbDrone.AddSeries = NzbDrone.module('AddSeries'); +NzbDrone.Quality = NzbDrone.module('Quality'); +NzbDrone.Shared = NzbDrone.module('Shared'); /* _.templateSettings = { @@ -36,7 +36,7 @@ NzbDrone.Constants = { }; NzbDrone.Events = { - DisplayInMainRegion: "DisplayInMainRegion" + DisplayInMainRegion: 'DisplayInMainRegion' }; @@ -58,9 +58,9 @@ NzbDrone.Router = Backbone.Marionette.AppRouter.extend({ controller: new NzbDrone.Controller(), // "someMethod" must exist at controller.someMethod appRoutes: { - "series/add": "addSeries", - "series/add/:action(/:query)": "addSeries", - ":whatever": "notFound" + 'series/add': 'addSeries', + 'series/add/:action(/:query)': 'addSeries', + ':whatever': 'notFound' } @@ -68,12 +68,12 @@ NzbDrone.Router = Backbone.Marionette.AppRouter.extend({ NzbDrone.addInitializer(function (options) { - console.log("starting application"); + console.log('starting application'); NzbDrone.addRegions({ - mainRegion: "#main-region", - notificationRegion: "#notification-region" + mainRegion: '#main-region', + notificationRegion: '#notification-region' }); NzbDrone.Router = new NzbDrone.Router();