added quality profile support to add series.

This commit is contained in:
kay.one 2013-01-26 19:04:15 -08:00
parent 1024e0f83d
commit f3e601d4ed
14 changed files with 132 additions and 15 deletions

View File

@ -195,6 +195,10 @@
<Content Include="_backboneApp\AddSeries\SearchResultModel.js" />
<Content Include="_backboneApp\AddSeries\SearchResultCollection.js" />
<Content Include="_backboneApp\Content\Intelisense\bootstrap.css" />
<Content Include="_backboneApp\Quality\qualityProfileModel.js" />
<Content Include="_backboneApp\Quality\qualityProfileCollection.js" />
<Content Include="_backboneApp\Quality\qualityTypeModel.js" />
<Content Include="_backboneApp\Quality\qualityTypeCollection.js" />
<Content Include="_backboneApp\nzbdrone.logging.js" />
<Content Include="_backboneApp\JsLibraries\backbone.marionette.extend.js" />
<Compile Include="_backboneApp\CassetteConfiguration.cs" />

View File

@ -15,12 +15,17 @@ NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.Layout.extend({
collection: new NzbDrone.AddSeries.SearchResultCollection(),
initialize: function (rootFolders) {
if (rootFolders === undefined) {
initialize: function (options) {
if (options.rootFolders === undefined) {
throw "rootFolder arg is required.";
}
this.rootFoldersCollection = rootFolders;
if (options.qualityProfiles === undefined) {
throw "qualityProfiles arg is required.";
}
this.rootFoldersCollection = options.rootFolders;
this.qualityProfilesCollection = options.qualityProfiles;
},
onRender: function () {
@ -61,7 +66,8 @@ NzbDrone.AddSeries.AddNewSeriesView = Backbone.Marionette.Layout.extend({
resultUpdated: function (options, context) {
_.each(options.models, function (model) {
model.set('rootFolders', context.rootFoldersCollection.rootFolders.models);
model.set('rootFolders', context.rootFoldersCollection.models);
model.set('qualityProfiles', context.qualityProfilesCollection.models);
});
context.searchResult.show(context.resultView);

View File

@ -4,16 +4,15 @@
</div>
<div id="{{id}}" class="accordion-body collapse">
<div class="accordion-inner">
<select class="root-dir-input span7" name="rootFolders">
<select class="root-dir-input span7">
{{#each rootFolders}}
<option value="{{id}}">{{attributes.path}}</option>
{{/each}}
</select>
<select class="quality-profile-input span2">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
{{#each qualityProfiles}}
<option value="{{id}}">{{attributes.name}}</option>
{{/each}}
</select>
<div class="btn btn-success pull-right icon-plus">
</div>

View File

@ -8,6 +8,8 @@ NzbDrone.AddSeries.SearchItemView = Backbone.Marionette.ItemView.extend({
className: 'search-item accordion-group',
onRender: function () {
this.listenTo(this.model, 'change', this.render);
//this.listenTo(this.model.get('rootFolders'), 'reset', this.render);
//this.listenTo(this.model.get('qualityProfiles'), 'reset', this.render);
}
});

View File

@ -1,6 +1,7 @@
/// <reference path="../app.js" />
/// <reference path="AddNewSeries/AddNewSeriesView.js" />
/// <reference path="RootDir/RootDirView.js" />
/// <reference path="../Quality/qualityProfileCollection.js" />
/// <reference path="../Shared/SpinnerView.js" />
NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({
@ -21,6 +22,7 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({
rootFolderCollection: new NzbDrone.AddSeries.RootDirCollection(),
qualityProfileCollection: new NzbDrone.Quality.QualityProfileCollection(),
onRender: function () {
this.$('#myTab a').click(function (e) {
@ -28,7 +30,9 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({
$(this).tab('show');
});
this.addNew.show(new NzbDrone.AddSeries.AddNewSeriesView({ rootFolders: this.rootFolderCollection }));
this.qualityProfileCollection.fetch();
this.addNew.show(new NzbDrone.AddSeries.AddNewSeriesView({ rootFolders: this.rootFolderCollection, qualityProfiles: this.qualityProfileCollection }));
//this.importExisting.show(new NzbDrone.ImportExistingView());
this.rootFolders.show(new NzbDrone.AddSeries.RootDirView({ collection: this.rootFolderCollection }));
@ -36,7 +40,7 @@ NzbDrone.AddSeries.AddSeriesLayout = Backbone.Marionette.Layout.extend({
NzbDrone.vent.listenTo(this.rootFolderCollection, 'remove', this.evaluateActions, this);
NzbDrone.vent.listenTo(this.rootFolderCollection, 'reset', this.evaluateActions, this);
},
evaluateActions: function () {
if (this.rootFolderCollection.length == 0) {
this.ui.addNewTab.hide();

View File

@ -1,7 +1,8 @@
/// <reference path="../../app.js" />
/// <reference path="RootDirModel.js" />
NzbDrone.AddSeries.RootDirCollection = Backbone.Collection.extend({
url: NzbDrone.Constants.ApiRoot + 'rootdir/',
url: NzbDrone.Constants.ApiRoot + '/rootdir',
model: NzbDrone.AddSeries.RootDirModel,
});

View File

@ -2,7 +2,7 @@
/// <reference path="SearchResultModel.js" />
NzbDrone.AddSeries.SearchResultCollection = Backbone.Collection.extend({
url: NzbDrone.Constants.ApiRoot + 'series/lookup',
url: NzbDrone.Constants.ApiRoot + '/series/lookup',
model: NzbDrone.AddSeries.SearchResultModel,
});

View File

@ -1,4 +1,6 @@
/// <reference path="../app.js" />
/// <reference path="RootDir/RootDirCollection.js" />
/// <reference path="../Quality/qualityProfileCollection.js" />
NzbDrone.AddSeries.SearchResultModel = Backbone.Model.extend({
mutators: {
seriesYear: function () {
@ -11,5 +13,11 @@ NzbDrone.AddSeries.SearchResultModel = Backbone.Model.extend({
return date;
}
}
},
defaults: {
qualityProfiles: new NzbDrone.Quality.QualityProfileCollection(),
rootFolders: new NzbDrone.AddSeries.RootDirCollection()
}
});

View File

@ -0,0 +1,7 @@
/// <reference path="../app.js" />
/// <reference path="qualityProfileModel.js" />
NzbDrone.Quality.QualityProfileCollection = Backbone.Collection.extend({
model: NzbDrone.Quality.QualityProfileModel,
url: NzbDrone.Constants.ApiRoot + '/qualityprofiles'
});

View File

@ -0,0 +1,47 @@
/// <reference path="../app.js" />
NzbDrone.Quality.QualityProfileModel = Backbone.Model.extend({
initialize: function () {
this.validators = {};
this.validators.name = function (value) {
return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must enter a name' };
};
//this.validators.allowed = function (value) {
// return value.length > 0 ? { isValid: true } : { isValid: false, message: 'You must have allowed qualities' };
//};
//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' };
};
},
validateItem: function (key) {
return (this.validators[key]) ? this.validators[key](this.get(key)) : { isValid: true };
},
// TODO: Implement Backbone's standard validate() method instead.
validateAll: function () {
var messages = {};
for (var key in this.validators) {
if (this.validators.hasOwnProperty(key)) {
var check = this.validators[key](this.get(key));
if (check.isValid === false) {
messages[key] = check.message;
}
}
}
return _.size(messages) > 0 ? { isValid: false, messages: messages } : { isValid: true };
},
defaults: {
Id: null,
Name: '',
//allowed: {},
Cutoff: null
}
});

View File

@ -0,0 +1,4 @@
NzbDrone.Quality.QualityTypeCollection = Backbone.Collection.extend({
model: NzbDrone.Quality.QualityTypeModel,
url: NzbDrone.Constants.ApiRoot + '/qualitytypes'
});

View File

@ -0,0 +1,34 @@
NzbDrone.Quality.QualityTypeModel = Backbone.Model.extend({
initialize: function () {
this.validators = {};
},
validateItem: function (key) {
return (this.validators[key]) ? this.validators[key](this.get(key)) : { isValid: true };
},
// TODO: Implement Backbone's standard validate() method instead.
validateAll: function () {
var messages = {};
for (var key in this.validators) {
if (this.validators.hasOwnProperty(key)) {
var check = this.validators[key](this.get(key));
if (check.isValid === false) {
messages[key] = check.message;
}
}
}
return _.size(messages) > 0 ? { isValid: false, messages: messages } : { isValid: true };
},
defaults: {
Id: null,
Name: '',
MaxSize: 100,
MinSize: 0
}
});

View File

@ -57,7 +57,7 @@ $(document).ajaxError(function (event, xmlHttpRequest, ajaxOptions) {
var errorView = NzbDrone.Shared.ErrorView.instance;
var model = new NzbDrone.Shared.ErrorModel();
model.set('title', ajaxOptions.url + " : " + xmlHttpRequest.statusText);
model.set('title', ajaxOptions.type + " " + ajaxOptions.url + " : " + xmlHttpRequest.statusText);
model.set('message', xmlHttpRequest.responseText);
errorView.collection.add(model);

View File

@ -19,6 +19,7 @@ if (typeof console == "undefined") {
NzbDrone = new Backbone.Marionette.Application();
NzbDrone.AddSeries = NzbDrone.module("AddSeries");
NzbDrone.Quality = NzbDrone.module("Quality");
NzbDrone.Shared = NzbDrone.module("Shared");
/*
@ -31,7 +32,7 @@ NzbDrone.ModelBinder = new Backbone.ModelBinder();
NzbDrone.Constants = {
ApiRoot: '/api/'
ApiRoot: '/api'
};
NzbDrone.Events = {