1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00
This commit is contained in:
Keivan Beigi 2013-06-20 18:43:58 -07:00
parent 0916c8b8d1
commit 24c77b4047
29 changed files with 610 additions and 517 deletions

View File

@ -2,6 +2,7 @@
<FileVersion>1</FileVersion> <FileVersion>1</FileVersion>
<AutoEnableOnStartup>False</AutoEnableOnStartup> <AutoEnableOnStartup>False</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution> <AllowParallelTestExecution>true</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit> <FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio> <FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec> <FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>

View File

@ -1,14 +1,16 @@
"use strict"; "use strict";
define([ define(
'app', [
'Quality/QualityProfileCollection', 'app',
'AddSeries/RootFolders/RootFolderCollection', 'marionette',
'AddSeries/RootFolders/RootFolderView', 'AddSeries/RootFolders/Layout',
'AddSeries/AddSeriesView', 'AddSeries/Existing/CollectionView',
'AddSeries/Existing/ImportSeriesView' 'AddSeries/AddSeriesView',
], 'Quality/QualityProfileCollection',
function (app, qualityProfileCollection, rootFolderCollection) { 'AddSeries/RootFolders/Collection'
NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({ ], function (App, Marionette, RootFolderLayout, ExistingSeriesCollectionView, AddSeriesView, qualityProfileCollection, rootFolderCollection) {
return Marionette.Layout.extend({
template: 'AddSeries/addSeriesLayoutTemplate', template: 'AddSeries/addSeriesLayoutTemplate',
regions: { regions: {
@ -20,25 +22,24 @@ define([
}, },
initialize: function () { initialize: function () {
this.rootFolderLayout = new NzbDrone.AddSeries.RootFolders.Layout(); this.rootFolderLayout = new RootFolderLayout();
this.rootFolderLayout.on('folderSelected', this._folderSelected, this); this.rootFolderLayout.on('folderSelected', this._folderSelected, this);
qualityProfileCollection.fetch();
rootFolderCollection.fetch();
},
onShow: function () {
this.workspace.show(new AddSeriesView());
}, },
_folderSelected: function (options) { _folderSelected: function (options) {
NzbDrone.modalRegion.closeModal(); App.modalRegion.closeModal();
this.workspace.show(new NzbDrone.AddSeries.Existing.ListView({model: options.model})); this.workspace.show(new ExistingSeriesCollectionView({model: options.model}));
},
onRender: function () {
qualityProfileCollection.fetch();
rootFolderCollection.fetch();
this.workspace.show(new NzbDrone.AddSeries.AddSeriesView());
}, },
_importSeries: function () { _importSeries: function () {
NzbDrone.modalRegion.show(this.rootFolderLayout); App.modalRegion.show(this.rootFolderLayout);
} }
}); });
}); });

View File

@ -1,63 +1,68 @@
"use strict"; "use strict";
define(['app', define(
'AddSeries/RootFolders/RootFolderCollection', [
'AddSeries/SearchResultView', 'marionette',
'Shared/SpinnerView', 'AddSeries/Collection',
'AddSeries/Collection'], function () { 'AddSeries/SearchResultCollectionView',
NzbDrone.AddSeries.AddSeriesView = Backbone.Marionette.Layout.extend({ 'Shared/SpinnerView',
template: 'AddSeries/AddSeriesTemplate', 'app',
'AddSeries/RootFolders/Collection',
'AddSeries/SearchResultView',
'Shared/SpinnerView'
], function (Marionette, AddSeriesCollection, SearchResultCollectionView, SpinnerView) {
return Marionette.Layout.extend({
template: 'AddSeries/AddSeriesTemplate',
ui: { ui: {
seriesSearch: '.x-series-search' seriesSearch: '.x-series-search'
}, },
regions: { regions: {
searchResult: '#search-result' searchResult: '#search-result'
}, },
initialize: function () { initialize: function () {
this.collection = new NzbDrone.AddSeries.Collection(); this.collection = new AddSeriesCollection();
}, },
onRender: function () { onRender: function () {
var self = this; var self = this;
this.ui.seriesSearch this.ui.seriesSearch.data('timeout', null).keyup(function () {
.data('timeout', null)
.keyup(function () {
window.clearTimeout(self.$el.data('timeout')); window.clearTimeout(self.$el.data('timeout'));
self.$el.data('timeout', window.setTimeout(self.search, 500, self)); self.$el.data('timeout', window.setTimeout(self.search, 500, self));
}); });
this.resultView = new NzbDrone.AddSeries.SearchResultCollectionView({ collection: this.collection }); this.resultView = new SearchResultCollectionView({ collection: this.collection });
}, },
search: function (context) { search: function (context) {
context.abortExistingRequest(); context.abortExistingRequest();
var term = context.ui.seriesSearch.val(); var term = context.ui.seriesSearch.val();
context.collection.reset(); context.collection.reset();
if (term === '') { if (term === '') {
context.searchResult.close(); context.searchResult.close();
} else { }
context.searchResult.show(new NzbDrone.Shared.SpinnerView()); else {
context.searchResult.show(new SpinnerView());
context.currentSearchRequest = context.collection.fetch({ context.currentSearchRequest = context.collection.fetch({
data : { term: term }, data : { term: term },
success: function () { success: function () {
context.searchResult.show(context.resultView); context.searchResult.show(context.resultView);
} }
}); });
}
},
abortExistingRequest: function () {
if (this.currentSearchRequest && this.currentSearchRequest.readyState > 0 && this.currentSearchRequest.readyState < 4) {
console.log('aborting previous pending search request.');
this.currentSearchRequest.abort();
}
} }
}, });
abortExistingRequest: function () {
if (this.currentSearchRequest && this.currentSearchRequest.readyState > 0 && this.currentSearchRequest.readyState < 4) {
console.log('aborting previous pending search request.');
this.currentSearchRequest.abort();
}
}
}); });
});

View File

@ -1,16 +1,21 @@
"use strict"; "use strict";
define(['app', 'Series/SeriesModel'], function () { define(
NzbDrone.AddSeries.Collection = Backbone.Collection.extend({ [
url : NzbDrone.Constants.ApiRoot + '/series/lookup', 'App',
model: NzbDrone.Series.SeriesModel, 'backbone',
'Series/SeriesModel'
], function (App, Backbone, SeriesModel) {
return Backbone.Collection.extend({
url : Constants.ApiRoot + '/series/lookup',
model: SeriesModel,
parse: function (response) { parse: function (response) {
_.each(response, function (model) { _.each(response, function (model) {
model.id = undefined; model.id = undefined;
}); });
return response; return response;
} }
});
}); });
});

View File

@ -0,0 +1,40 @@
'use strict';
define(
[
'marionette',
'AddSeries/Existing/CompositeView',
'AddSeries/Existing/UnmappedFolderCollection'
], function (Marionette, UnmappedFolderCompositeView, UnmappedFolderCollection) {
return Marionette.CollectionView.extend({
itemView: UnmappedFolderCompositeView,
initialize: function () {
this.collection = new UnmappedFolderCollection();
this.refreshItems();
},
refreshItems: function () {
this.collection.importItems(this.model);
},
showCollection: function () {
this._showAndSearch(0);
},
_showAndSearch: function (index) {
var model = this.collection.at(index);
if (model) {
var that = this;
var currentIndex = index;
this.addItemView(model, this.getItemView(), index);
$.when(this.children.findByModel(model).search()).then(function () {
that._showAndSearch(currentIndex + 1);
});
}
}
});
});

View File

@ -0,0 +1,106 @@
'use strict';
define(
[
'marionette',
'AddSeries/Collection',
'AddSeries/SearchResultView'
], function (Marionette, AddSeriesCollection, SearchResultView) {
return Marionette.CompositeView.extend({
template : 'AddSeries/Existing/UnmappedFolderCompositeViewTemplate',
itemViewContainer: '.x-folder-name-match-results',
itemView : SearchResultView,
events: {
'click .x-btn-search' : 'search',
'click .x-load-more' : '_loadMore',
'keydown .x-txt-search': 'keyDown'
},
ui: {
searchButton: '.x-btn-search',
searchText : '.x-txt-search',
searchBar : '.x-search-bar',
loadMore : '.x-load-more'
},
initialize: function () {
this.collection = new AddSeriesCollection();
this.on("item:removed", function () {
this.close();
}, this);
},
onRender: function () {
this.ui.loadMore.show();
},
search: function () {
var icon = this.ui.searchButton.find('icon');
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
var self = this;
var deferred = $.Deferred();
this.collection.reset();
this.searchCollection = new AddSeriesCollection();
this.searchCollection.fetch({
data : { term: this.ui.searchText.val() },
success: function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.resolve();
self.collection.add(self.searchCollection.shift());
if (self.showall) {
self._showAll();
}
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.reject();
}
});
return deferred.promise();
},
keyDown: function (e) {
//Check for enter being pressed
var code = (e.keyCode ? e.keyCode :e.which);
if (code === 13) {
this.search();
}
},
_loadMore: function () {
this.showall = true;
this.ui.searchBar.fadeIn();
this.ui.loadMore.fadeOut();
this._showAll();
},
_showAll: function () {
var self = this;
this.searchCollection.each(function (searchResult) {
self.collection.add(searchResult);
});
},
itemViewOptions: function () {
return {
rootFolder: this.model.get('rootFolder'),
folder : this.model.get('folder').path,
isExisting: true
};
}
});
});

View File

@ -1,139 +0,0 @@
'use strict';
define([
'app', 'AddSeries/RootFolders/RootFolderCollection',
'AddSeries/Existing/UnmappedFolderModel',
'AddSeries/Collection',
'AddSeries/SearchResultView',
'Series/SeriesModel'], function () {
NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView = Backbone.Marionette.CompositeView.extend({
template : 'AddSeries/Existing/UnmappedFolderCompositeViewTemplate',
itemViewContainer: '.x-folder-name-match-results',
itemView : NzbDrone.AddSeries.SearchResultView,
events: {
'click .x-btn-search' : 'search',
'click .x-load-more' : '_loadMore',
'keydown .x-txt-search': 'keyDown'
},
ui: {
searchButton: '.x-btn-search',
searchText : '.x-txt-search',
searchBar : '.x-search-bar',
loadMore : '.x-load-more'
},
initialize: function () {
this.collection = new NzbDrone.AddSeries.Collection();
this.collection.bind('reset', this.collectionReset, this);
this.on("item:removed", function () {
this.close();
}, this);
},
onRender: function () {
this.ui.loadMore.show();
},
search: function () {
var icon = this.ui.searchButton.find('icon');
icon.removeClass('icon-search').addClass('icon-spin icon-spinner disabled');
var self = this;
var deferred = $.Deferred();
this.collection.reset();
this.searchCollection = new NzbDrone.AddSeries.Collection();
this.searchCollection.fetch({
data : { term: this.ui.searchText.val() },
success: function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.resolve();
self.collection.add(self.searchCollection.shift());
if (self.showall) {
self._showAll();
}
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
deferred.reject();
}
});
return deferred.promise();
},
keyDown: function (e) {
//Check for enter being pressed
var code = (e.keyCode ? e.keyCode :e.which);
if (code === 13) {
this.search();
}
},
_loadMore: function () {
this.showall = true;
this.ui.searchBar.fadeIn();
this.ui.loadMore.fadeOut();
this._showAll();
},
_showAll: function () {
var self = this;
this.searchCollection.each(function (searchResult) {
self.collection.add(searchResult);
});
},
itemViewOptions: function () {
return {
rootFolder : this.model.get('rootFolder'),
folder : this.model.get('folder').path,
isExisting : true
};
}
});
NzbDrone.AddSeries.Existing.ListView = Backbone.Marionette.CollectionView.extend({
itemView: NzbDrone.AddSeries.Existing.UnmappedFolderCompositeView,
initialize: function () {
this.collection = new NzbDrone.AddSeries.Existing.UnmappedFolderCollection();
this.refreshItems();
},
refreshItems: function () {
this.collection.importItems(this.model);
},
showCollection: function () {
this.showAndSearch(0);
},
showAndSearch: function (index) {
var model = this.collection.at(index);
if (model) {
var that = this;
var currentIndex = index;
this.addItemView(model, this.getItemView(), index);
$.when(this.children.findByModel(model).search())
.then(function () {
that.showAndSearch(currentIndex + 1);
});
}
}
});
});

View File

@ -0,0 +1,23 @@
'use strict';
define(
[
'backbone',
'AddSeries/Existing/UnmappedFolderModel'
], function (Backbone, UnmappedFolderModel) {
return Backbone.Collection.extend({
model: UnmappedFolderModel,
importItems: function (rootFolderModel) {
this.reset();
var rootFolder = rootFolderModel;
_.each(rootFolderModel.get('unmappedFolders'), function (folder) {
this.push(new UnmappedFolderModel({
rootFolder: rootFolder,
folder : folder
}));
}, this);
}
});
});

View File

@ -1,21 +1,10 @@
'use strict'; 'use strict';
define(['app'], function () {
define(
[
'backbone'
], function (Backbone) {
return Backbone.Model.extend({
NzbDrone.AddSeries.Existing.UnmappedFolderModel = Backbone.Model.extend({ });
}); });
NzbDrone.AddSeries.Existing.UnmappedFolderCollection = Backbone.Collection.extend({
model: NzbDrone.AddSeries.Existing.UnmappedFolderModel,
importItems: function (rootFolderModel) {
this.reset();
var rootFolder = rootFolderModel;//.get('path');
_.each(rootFolderModel.get('unmappedFolders'), function (folder) {
this.push(new NzbDrone.AddSeries.Existing.UnmappedFolderModel({ rootFolder: rootFolder, folder: folder}));
}, this);
}
});
});

View File

@ -0,0 +1,15 @@
"use strict";
define(
[
'app',
'AddSeries/RootFolders/Model',
'mixins/backbone.signalr.mixin'
], function () {
var rootFolderCollection = Backbone.Collection.extend({
url : NzbDrone.Constants.ApiRoot + '/rootfolder',
model: NzbDrone.AddSeries.RootFolders.RootFolderModel
});
return new rootFolderCollection().BindSignalR();
});

View File

@ -0,0 +1,16 @@
"use strict";
define(
[
'marionette',
'AddSeries/RootFolders/ItemView'
], function (Marionette, RootFolderItemView) {
return Marionette.CollectionView.extend({
itemView: RootFolderItemView,
tagName : 'table',
className: 'table table-hover'
});
});

View File

@ -0,0 +1,27 @@
"use strict";
define(
[
'marionette'
], function (Marionette) {
return Marionette.ItemView.extend({
template: 'AddSeries/RootFolders/RootFolderItemTemplate',
tagName : 'tr',
events: {
'click .x-remove': 'removeFolder',
'click .x-folder': 'folderSelected'
},
removeFolder: function () {
this.model.destroy({ wait: true });
this.model.collection.remove(this.model);
},
folderSelected: function () {
this.trigger('folderSelected', this.model);
}
});
});

View File

@ -0,0 +1,57 @@
"use strict";
define(
[
'marionette',
'AddSeries/RootFolders/CollectionView',
'AddSeries/RootFolders/Model',
'AddSeries/RootFolders/Collection',
'Mixins/AutoComplete'
], function (Marionette, RootFolderCollectionView, RootFolderCollection, RootFolderModel) {
return Marionette.Layout.extend({
template: 'AddSeries/RootFolders/LayoutTemplate',
ui: {
pathInput: '.x-path input'
},
regions: {
currentDirs: '#current-dirs'
},
events: {
'click .x-add': 'addFolder'
},
initialize: function () {
this.collection = RootFolderCollection;
this.rootfolderListView = new RootFolderCollectionView({ collection: RootFolderCollection });
this.rootfolderListView.on('itemview:folderSelected', this._onFolderSelected, this);
},
onRender: function () {
this.currentDirs.show(this.rootfolderListView);
this.ui.pathInput.autoComplete('/directories');
},
_onFolderSelected: function (options) {
this.trigger('folderSelected', options);
},
addFolder: function () {
var newDir = new RootFolderModel({
Path: this.ui.pathInput.val()
});
RootFolderCollection.create(newDir, {
wait: true, success: function () {
RootFolderCollection.fetch();
}
});
}
});
});

View File

@ -11,4 +11,4 @@ define(['app'], function () {
freeSpace: 0 freeSpace: 0
} }
}); });
}); });

View File

@ -1,10 +0,0 @@
"use strict";
define(['app', 'AddSeries/RootFolders/RootFolderModel','mixins/backbone.signalr.mixin'], function () {
var rootFolderCollection = Backbone.Collection.extend({
url : NzbDrone.Constants.ApiRoot + '/rootfolder',
model: NzbDrone.AddSeries.RootFolders.RootFolderModel
});
return new rootFolderCollection().BindSignalR();
});

View File

@ -1,11 +1,13 @@
'use strict'; 'use strict';
define(['app', 'AddSeries/RootFolders/RootFolderCollection','handlebars'], function (app, rootFolders, Handlebars) { define(
[
'AddSeries/RootFolders/Collection',
'handlebars'
], function (rootFolders, Handlebars) {
Handlebars.registerHelper('rootFolderSelection', function () { Handlebars.registerHelper('rootFolderSelection', function () {
//TODO: We should be able to pass in the context, either an object or a property var templateFunction = Marionette.TemplateCache.get('AddSeries/RootFolders/RootFolderSelectionTemplate');
return new Handlebars.SafeString(templateFunction(rootFolders.toJSON()));
var templateFunction = Marionette.TemplateCache.get('AddSeries/RootFolders/RootFolderSelectionTemplate'); });
return new Handlebars.SafeString(templateFunction(rootFolders.toJSON()));
}); });
});

View File

@ -1,79 +0,0 @@
"use strict";
define(['app', 'AddSeries/RootFolders/RootFolderCollection', 'Mixins/AutoComplete'], function (app, rootFolders) {
NzbDrone.AddSeries.RootFolderItemView = Backbone.Marionette.ItemView.extend({
template: 'AddSeries/RootFolders/RootFolderItemTemplate',
tagName : 'tr',
events: {
'click .x-remove': 'removeFolder',
'click .x-folder': 'folderSelected'
},
removeFolder: function () {
this.model.destroy({ wait: true });
this.model.collection.remove(this.model);
},
folderSelected: function () {
this.trigger('folderSelected', this.model);
}
});
NzbDrone.AddSeries.RootDirListView = Backbone.Marionette.CollectionView.extend({
itemView: NzbDrone.AddSeries.RootFolderItemView,
tagName : 'table',
className: 'table table-hover'
});
NzbDrone.AddSeries.RootFolders.Layout = Backbone.Marionette.Layout.extend({
template: 'AddSeries/RootFolders/LayoutTemplate',
ui: {
pathInput: '.x-path input'
},
regions: {
currentDirs: '#current-dirs'
},
events: {
'click .x-add': 'addFolder'
},
initialize: function () {
this.collection = rootFolders;
this.rootfolderListView = new NzbDrone.AddSeries.RootDirListView({ collection: rootFolders });
this.rootfolderListView.on('itemview:folderSelected', this._onFolderSelected, this);
},
onRender: function () {
this.currentDirs.show(this.rootfolderListView);
this.ui.pathInput.autoComplete('/directories');
},
_onFolderSelected: function (options) {
this.trigger('folderSelected', options);
},
addFolder: function () {
var newDir = new NzbDrone.AddSeries.RootFolders.RootFolderModel(
{
Path: this.ui.pathInput.val()
});
rootFolders.create(newDir, {
wait: true, success: function () {
rootFolders.fetch();
}
});
}
});
});

View File

@ -0,0 +1,16 @@
'use strict';
define(
[
'marionette',
'AddSeries/SearchResultView'
], function (Marionette, SearchResultView) {
return Marionette.CollectionView.extend({
itemView : SearchResultView,
initialize: function () {
this.listenTo(this.collection, 'reset', this.render);
}
});
});

View File

@ -1,101 +1,95 @@
'use strict'; 'use strict';
define(['app', define(
'Quality/QualityProfileCollection', [
'Config', 'app',
'Series/SeriesCollection', 'marionette',
'AddSeries/RootFolders/RootFolderTemplateHelper', 'Config',
'Quality/QualityProfileTemplateHelper'], function (app, qualityProfiles) { 'Series/SeriesCollection',
'Shared/Messenger',
'Quality/QualityProfileCollection'
], function (App, Marionette, Config, SeriesCollection, Messenger, QualityProfiles) {
NzbDrone.AddSeries.SearchResultView = Backbone.Marionette.ItemView.extend({ return Marionette.ItemView.extend({
template: "AddSeries/SearchResultTemplate", template: "AddSeries/SearchResultTemplate",
ui: { ui: {
qualityProfile: '.x-quality-profile', qualityProfile: '.x-quality-profile',
rootFolder : '.x-root-folder', rootFolder : '.x-root-folder',
addButton : '.x-add', addButton : '.x-add',
overview : '.x-overview' overview : '.x-overview'
}, },
events: { events: {
'click .x-add' : 'addSeries', 'click .x-add' : 'addSeries',
'change .x-quality-profile': '_qualityProfileChanged' 'change .x-quality-profile': '_qualityProfileChanged'
}, },
initialize: function () { initialize: function () {
if (!this.model) { if (!this.model) {
throw 'model is required'; throw 'model is required';
}
this.model.set('isExisting', this.options.isExisting);
this.model.set('path', this.options.folder);
NzbDrone.vent.on(NzbDrone.Config.Events.ConfigUpdatedEvent, this._onConfigUpdated, this);
},
_onConfigUpdated: function (options) {
if (options.key === NzbDrone.Config.Keys.DefaultQualityProfileId) {
this.$('.x-quality-profile').val(options.value);
}
},
_qualityProfileChanged: function () {
NzbDrone.Config.SetValue(NzbDrone.Config.Keys.DefaultQualityProfileId, this.ui.qualityProfile.val());
},
onRender: function () {
this.listenTo(this.model, 'change', this.render);
var defaultQuality = NzbDrone.Config.GetValue(NzbDrone.Config.Keys.DefaultQualityProfileId);
if (qualityProfiles.get(defaultQuality)) {
this.ui.qualityProfile.val(defaultQuality);
}
},
addSeries: function () {
var icon = this.ui.addButton.find('icon');
icon.removeClass('icon-plus').addClass('icon-spin icon-spinner disabled');
var quality = this.ui.qualityProfile.val();
var rootFolderPath = this.ui.rootFolder.children(':selected').text();
this.model.set('qualityProfileId', quality);
this.model.set('rootFolderPath', rootFolderPath);
var self = this;
this.model.save(undefined, {
url : NzbDrone.Series.SeriesCollection.prototype.url,
success: function () {
self.close();
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
NzbDrone.Shared.Messenger.show({
message: 'Added: ' + self.model.get('title')
});
NzbDrone.vent.trigger(NzbDrone.Events.SeriesAdded, { series: self.model });
self.model.collection.remove(self.model);
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
} }
});
} this.model.set('isExisting', this.options.isExisting);
}); this.model.set('path', this.options.folder);
App.vent.on(Config.Events.ConfigUpdatedEvent, this._onConfigUpdated, this);
},
NzbDrone.AddSeries.SearchResultCollectionView = Backbone.Marionette.CollectionView.extend({ _onConfigUpdated: function (options) {
if (options.key === Config.Keys.DefaultQualityProfileId) {
this.$('.x-quality-profile').val(options.value);
}
},
_qualityProfileChanged: function () {
Config.SetValue(Config.Keys.DefaultQualityProfileId, this.ui.qualityProfile.val());
},
onRender: function () {
this.listenTo(this.model, 'change', this.render);
var defaultQuality = Config.GetValue(Config.Keys.DefaultQualityProfileId);
if (QualityProfiles.get(defaultQuality)) {
this.ui.qualityProfile.val(defaultQuality);
}
},
addSeries: function () {
var icon = this.ui.addButton.find('icon');
icon.removeClass('icon-plus').addClass('icon-spin icon-spinner disabled');
var quality = this.ui.qualityProfile.val();
var rootFolderPath = this.ui.rootFolder.children(':selected').text();
this.model.set('qualityProfileId', quality);
this.model.set('rootFolderPath', rootFolderPath);
var self = this;
this.model.save(undefined, {
url : SeriesCollection.prototype.url,
success: function () {
self.close();
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
Messenger.show({
message: 'Added: ' + self.model.get('title')
});
App.vent.trigger(App.Events.SeriesAdded, { series: self.model });
self.model.collection.remove(self.model);
},
fail : function () {
icon.removeClass('icon-spin icon-spinner disabled').addClass('icon-search');
}
});
}
});
itemView : NzbDrone.AddSeries.SearchResultView,
initialize: function () {
this.listenTo(this.collection, 'reset', this.render);
}
}); });
});

View File

@ -1,37 +1,42 @@
"use strict"; "use strict";
define(['app'], function () { define(
[
'app'
], function () {
NzbDrone.Config = { NzbDrone.Config = {
Events: { Events: {
ConfigUpdatedEvent: 'ConfigUpdatedEvent' ConfigUpdatedEvent: 'ConfigUpdatedEvent'
}, },
Keys : { Keys : {
DefaultQualityProfileId: 'DefaultQualityProfileId' DefaultQualityProfileId: 'DefaultQualityProfileId'
} }
}; };
NzbDrone.Config.GetValue = function (key, defaultValue) { NzbDrone.Config.GetValue = function (key, defaultValue) {
var storeValue = localStorage.getItem(key); var storeValue = localStorage.getItem(key);
if (!storeValue) { if (!storeValue) {
return defaultValue; return defaultValue;
} }
return storeValue.toString(); return storeValue.toString();
}; };
NzbDrone.Config.SetValue = function (key, value) { NzbDrone.Config.SetValue = function (key, value) {
console.log('Config: [{0}] => [{1}] '.format(key, value)); console.log('Config: [{0}] => [{1}] '.format(key, value));
if (NzbDrone.Config.GetValue(key) === value.toString()) { if (NzbDrone.Config.GetValue(key) === value.toString()) {
return; return;
} }
localStorage.setItem(key, value); localStorage.setItem(key, value);
NzbDrone.vent.trigger(NzbDrone.Config.Events.ConfigUpdatedEvent, {key: key, value: value}); NzbDrone.vent.trigger(NzbDrone.Config.Events.ConfigUpdatedEvent, {key: key, value: value});
}; };
}); return NzbDrone.Config;
});

View File

@ -1,12 +1,15 @@
"use strict"; "use strict";
define(['app'], function () { define(function () {
//This module will automatically route all links through backbone router rather than //This module will automatically route all links through backbone router rather than
//causing links to reload pages. //causing links to reload pages.
var routeBinder = { var routeBinder = {
bind: function () { bind: function (router) {
this._router = router;
$(document).on('click', 'a[href]', this._handleClick); $(document).on('click', 'a[href]', this._handleClick);
}, },
@ -44,7 +47,7 @@ define(['app'], function () {
if (!href.startsWith('http')) { if (!href.startsWith('http')) {
NzbDrone.Router.navigate(href, { trigger: true }); this._router.navigate(href, { trigger: true });
} }
else { else {

29
UI/Router.js Normal file
View File

@ -0,0 +1,29 @@
"use strict";
require(
[
'marionette',
'Controller'
], function (Marionette, Controller) {
return Marionette.AppRouter.extend({
controller: Controller,
appRoutes : {
'' : 'series',
'series' : 'series',
'series/index' : 'series',
'series/add' : 'addSeries',
'series/add/:action(/:query)': 'addSeries',
'series/details/:query' : 'seriesDetails',
'calendar' : 'calendar',
'settings' : 'settings',
'settings/:action(/:query)' : 'settings',
'missing' : 'missing',
'history' : 'history',
'logs' : 'logs',
'rss' : 'rss',
':whatever' : 'notFound'
}
});
});

View File

@ -1,34 +0,0 @@
"use strict";
require(['Controller', 'RouteBinder', 'Shared/Footer/View'], function (Controller, RouteBinder, FooterView) {
NzbDrone.Router = Backbone.Marionette.AppRouter.extend({
controller: Controller,
appRoutes : {
'' : 'series',
'series' : 'series',
'series/index' : 'series',
'series/add' : 'addSeries',
'series/add/:action(/:query)': 'addSeries',
'series/details/:query' : 'seriesDetails',
'calendar' : 'calendar',
'settings' : 'settings',
'settings/:action(/:query)' : 'settings',
'missing' : 'missing',
'history' : 'history',
'logs' : 'logs',
'rss' : 'rss',
':whatever' : 'notFound'
}
});
NzbDrone.addInitializer(function () {
NzbDrone.Router = new NzbDrone.Router();
Backbone.history.start({ pushState: true });
RouteBinder.bind();
NzbDrone.footerRegion.show(new FooterView());
});
});

View File

@ -1,7 +1,7 @@
var statusText = $.ajax({ var statusText = $.ajax({
type : "GET", type : "GET",
url : 'api/system/status', url : '/api/system/status',
async: false, async: false
}).responseText; }).responseText;
window.ServerStatus = JSON.parse(statusText); window.ServerStatus = JSON.parse(statusText);

View File

@ -32,4 +32,6 @@ define(['app'], function () {
return date.format('{MM}/{dd}/{yyyy}'); return date.format('{MM}/{dd}/{yyyy}');
}; };
return NzbDrone.Shared.FormatHelpers;
}); });

View File

@ -1,10 +1,15 @@
"use strict"; "use strict";
define(['app'], function () { define(
NzbDrone.Shared.SpinnerView = Backbone.Marionette.ItemView.extend({ [
template : 'Shared/SpinnerTemplate', 'app'
className: 'nz-spinner row' ], function () {
NzbDrone.Shared.SpinnerView = Backbone.Marionette.ItemView.extend({
template : 'Shared/SpinnerTemplate',
className: 'nz-spinner row'
});
return NzbDrone.Shared.SpinnerView;
}); });
});

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
define(['app','handlebars'], function (App,Handlebars) { define(['app','handlebars','Shared/FormatHelpers'], function (App,Handlebars) {
Handlebars.registerHelper('partial', function (templateName) { Handlebars.registerHelper('partial', function (templateName) {
//TODO: We should be able to pass in the context, either an object or a property //TODO: We should be able to pass in the context, either an object or a property

View File

@ -1,34 +1,39 @@
"use strict"; "use strict";
define(['app', 'Shared/Toolbar/Radio/RadioButtonView', 'Config'], function () { define(
NzbDrone.Shared.Toolbar.RadioButtonCollectionView = Backbone.Marionette.CollectionView.extend({ [
className: 'btn-group', 'app',
itemView : NzbDrone.Shared.Toolbar.RadioButtonView, 'Shared/Toolbar/Radio/RadioButtonView',
'Config'
], function (App, RadioButtonView, Config) {
NzbDrone.Shared.Toolbar.RadioButtonCollectionView = Backbone.Marionette.CollectionView.extend({
className: 'btn-group',
itemView : NzbDrone.Shared.Toolbar.RadioButtonView,
attributes: { attributes: {
'data-toggle': 'buttons-radio' 'data-toggle': 'buttons-radio'
}, },
initialize: function (options) { initialize: function (options) {
this.menu = options.menu; this.menu = options.menu;
if (this.menu.storeState) { if (this.menu.storeState) {
this.setActive(); this.setActive();
}
},
setActive: function () {
var storedKey = Config.GetValue(this.menu.menuKey, this.menu.defaultAction);
this.collection.each(function (model) {
if (model.get('key').toLocaleLowerCase() === storedKey.toLowerCase()) {
model.set('active', true);
}
else {
model.set('active, false');
}
});
} }
}, });
setActive: function () {
var storedKey = NzbDrone.Config.GetValue(this.menu.menuKey, this.menu.defaultAction);
this.collection.each(function (model) {
if (model.get('key').toLocaleLowerCase() === storedKey.toLowerCase()) {
model.set('active', true);
}
else {
model.set('active, false');
}
});
}
}); });
});

View File

@ -1,7 +1,7 @@
"use strict"; "use strict";
require.config({ require.config({
urlArgs: 'bust=' + window.ServerStatus.version, urlArgs: 'v=' + window.ServerStatus.version,
paths: { paths: {
'backbone' : 'JsLibraries/backbone', 'backbone' : 'JsLibraries/backbone',
@ -22,6 +22,7 @@ require.config({
'marionette' : 'JsLibraries/backbone.marionette', 'marionette' : 'JsLibraries/backbone.marionette',
'signalR' : 'JsLibraries/jquery.signalR', 'signalR' : 'JsLibraries/jquery.signalR',
'libs' : 'JsLibraries/' 'libs' : 'JsLibraries/'
}, },
shim: { shim: {
@ -147,9 +148,10 @@ define(
[ [
'marionette', 'marionette',
'shared/modal/region', 'shared/modal/region',
'router',
'Instrumentation/StringFormat', 'Instrumentation/StringFormat',
'Instrumentation/ErrorHandler' 'Instrumentation/ErrorHandler'
], function (Marionette, ModalRegion) { ], function (Marionette, ModalRegion, Router, RouteBinder) {
require( require(
[ [
@ -234,6 +236,13 @@ define(
window.NzbDrone.start(); window.NzbDrone.start();
NzbDrone.Router = new Router();
Backbone.history.start({ pushState: true });
RouteBinder.bind(NzbDrone.Router);
//NzbDrone.footerRegion.show(new FooterView());
window.require( window.require(
[ [
'Routing' 'Routing'