From b6a4e6c32cc6ae0e1242ece3be57d9f445fbb506 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 1 Feb 2013 19:33:23 -0800 Subject: [PATCH] FInished add series. need some error handling but mostly on the server. --- .../_backboneApp/AddSeries/AddSeriesLayout.js | 3 +- .../FolderMatchResultViewTemplatate.html | 2 +- .../AddSeries/Existing/ImportSeriesView.js | 93 +++++++++++++++++-- ...UnmappedFolderCompositeViewTemplatate.html | 9 +- .../AddSeries/Existing/UnmappedFolderModel.js | 17 +++- .../_backboneApp/AddSeries/addSeries.css | 12 ++- 6 files changed, 116 insertions(+), 20 deletions(-) diff --git a/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js b/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js index 8e92a4347..8a2e35e6f 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/AddSeriesLayout.js @@ -72,9 +72,10 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ onRender: function () { this.qualityProfileCollection.fetch(); + this.rootFolderCollection.fetch(); this.addNew.show(new NzbDrone.AddSeries.AddNewSeriesView({ rootFolders: this.rootFolderCollection, qualityProfiles: this.qualityProfileCollection })); - this.importExisting.show(new NzbDrone.AddSeries.Existing.ImportSeriesView({ collection: this.rootFolderCollection })); + this.importExisting.show(new NzbDrone.AddSeries.Existing.ImportSeriesView({ collection: this.rootFolderCollection, quality: this.qualityProfileCollection })); this.rootFolders.show(new NzbDrone.AddSeries.RootDirView({ collection: this.rootFolderCollection })); this.listenTo(this.rootFolderCollection, 'add', this.evaluateActions, this); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/Existing/FolderMatchResultViewTemplatate.html b/NzbDrone.Web/_backboneApp/AddSeries/Existing/FolderMatchResultViewTemplatate.html index 9ade9671c..e8b8cafb1 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/Existing/FolderMatchResultViewTemplatate.html +++ b/NzbDrone.Web/_backboneApp/AddSeries/Existing/FolderMatchResultViewTemplatate.html @@ -1,5 +1,5 @@ 
{{seriesName}} {{seriesYear}} - +
diff --git a/NzbDrone.Web/_backboneApp/AddSeries/Existing/ImportSeriesView.js b/NzbDrone.Web/_backboneApp/AddSeries/Existing/ImportSeriesView.js index 0c4253570..5de41b5bb 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/Existing/ImportSeriesView.js +++ b/NzbDrone.Web/_backboneApp/AddSeries/Existing/ImportSeriesView.js @@ -6,23 +6,58 @@ NzbDrone.AddSeries.Existing.FolderMatchResultView = Backbone.Marionette.ItemView.extend({ - template: "AddSeries/Existing/FolderMatchResultViewTemplatate", + template: 'AddSeries/Existing/FolderMatchResultViewTemplatate', + events: { + 'click .x-btn-add': 'addSeries' + }, + + addSeries: function () { + + var seriesId = this.model.get('id'); + var title = this.model.get('seriesName'); + var quality = this.options.qualityProfile.val(); + var path = this.options.rootFolder + "\\" + title; + + var model = new NzbDrone.Series.SeriesModel({ + seriesId: seriesId, + title: title, + qualityProfileId: quality, + path: path + }); + + var self = this; + + model.save(undefined, { + success: function () { + var notificationModel = new NzbDrone.Shared.NotificationModel({ + title: 'Added', + message: title, + level: 'success' + }); + + NzbDrone.Shared.NotificationCollectionView.Instance.collection.add(notificationModel); + self.close(); + } + }); + } }); NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.CompositeView.extend({ - template: "AddSeries/Existing/UnmappedFolderCompositeViewTemplatate", - itemViewContainer: ".x-folder-name-match-results", + template: 'AddSeries/Existing/UnmappedFolderCompositeViewTemplatate', + itemViewContainer: '.x-folder-name-match-results', itemView: NzbDrone.AddSeries.Existing.FolderMatchResultView, events: { - 'click .x-search': 'search' + 'click .x-btn-search': 'search' }, ui: { - searchButton: '.x-search' + searchButton: '.x-btn-search', + searchText: '.x-txt-search', + profileList: '.x-lst-quality-profile' }, initialize: function () { @@ -35,19 +70,29 @@ NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.Co icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled'); - + var self = this; this.collection.fetch({ - data: $.param({ term: this.model.get('folder') }), - success: function () { + data: $.param({ term: this.ui.searchText.val() }), + success: function (model) { icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); + }, - fail:function() { + fail: function () { icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search'); } }); + }, + + itemViewOptions: function () { + return { + qualityProfile: this.ui.profileList, + rootFolder: this.model.get('rootFolder') + }; } + + }); NzbDrone.AddSeries.Existing.RootFolderCompositeView = Backbone.Marionette.CompositeView.extend({ @@ -62,20 +107,48 @@ NzbDrone.AddSeries.Existing.RootFolderCompositeView = Backbone.Marionette.Compos throw "model is required."; } + if (!this.options.quality) { + throw "quality collection is required."; + } + this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection(); - this.collection.importArray(this.model.get('unmappedFolders')); + this.refreshItems(); + this.listenTo(this.options.quality, 'reset', this.refreshItems, this); + }, + + refreshItems: function () { + this.collection.importItems(this.model, this.options.quality); }, + + }); NzbDrone.AddSeries.Existing.ImportSeriesView = Backbone.Marionette.CollectionView.extend({ itemView: NzbDrone.AddSeries.Existing.RootFolderCompositeView, + + initialize: function () { + if (!this.collection) { throw "root folder collection is required."; } + + if (!this.options.quality) { + throw "quality collection is required."; + } + + this.itemViewOptions = { + quality: this.options.quality + }; + } + + + + + }); diff --git a/NzbDrone.Web/_backboneApp/AddSeries/Existing/UnmappedFolderCompositeViewTemplatate.html b/NzbDrone.Web/_backboneApp/AddSeries/Existing/UnmappedFolderCompositeViewTemplatate.html index 58692cc04..eb199b5ba 100644 --- a/NzbDrone.Web/_backboneApp/AddSeries/Existing/UnmappedFolderCompositeViewTemplatate.html +++ b/NzbDrone.Web/_backboneApp/AddSeries/Existing/UnmappedFolderCompositeViewTemplatate.html @@ -1,8 +1,13 @@ 
- {{folder}} -