From 519b6debfb415c05e44abce702264bfdbeb64c9c Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 5 Jun 2014 23:38:05 -0700 Subject: [PATCH] Fixed validation that was causing add existing series to fail --- .../ReleaseIntegrationTest.cs | 5 -- .../RootFolders/RootFolderLayoutTemplate.html | 18 ++++---- src/UI/AddSeries/addSeries.less | 4 ++ src/UI/Mixins/AsValidatedView.js | 46 +++++++++++++------ .../Settings/Indexers/Edit/IndexerEditView.js | 4 -- src/UI/jQuery/jquery.validation.js | 4 +- 6 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/NzbDrone.Integration.Test/ReleaseIntegrationTest.cs b/src/NzbDrone.Integration.Test/ReleaseIntegrationTest.cs index a97bdf3b8..a4e1e4d40 100644 --- a/src/NzbDrone.Integration.Test/ReleaseIntegrationTest.cs +++ b/src/NzbDrone.Integration.Test/ReleaseIntegrationTest.cs @@ -10,17 +10,13 @@ namespace NzbDrone.Integration.Test [Test] public void should_only_have_unknown_series_releases() { - var releases = Releases.All(); var indexers = Indexers.All(); - releases.Should().OnlyContain(c => c.Rejections.Contains("Unknown Series")); releases.Should().OnlyContain(c => BeValidRelease(c)); } - - private bool BeValidRelease(ReleaseResource releaseResource) { releaseResource.Age.Should().BeGreaterOrEqualTo(-1); @@ -33,6 +29,5 @@ namespace NzbDrone.Integration.Test return true; } - } } \ No newline at end of file diff --git a/src/UI/AddSeries/RootFolders/RootFolderLayoutTemplate.html b/src/UI/AddSeries/RootFolders/RootFolderLayoutTemplate.html index 2e16ae6e3..1d0822902 100644 --- a/src/UI/AddSeries/RootFolders/RootFolderLayoutTemplate.html +++ b/src/UI/AddSeries/RootFolders/RootFolderLayoutTemplate.html @@ -8,14 +8,16 @@
Enter the path that contains some or all of your TV series, you will be able to choose which series you want to import
-
-   - - - - +
+
+   + + + + +
{{#if items}} diff --git a/src/UI/AddSeries/addSeries.less b/src/UI/AddSeries/addSeries.less index ee287bbac..0fa784a19 100644 --- a/src/UI/AddSeries/addSeries.less +++ b/src/UI/AddSeries/addSeries.less @@ -130,4 +130,8 @@ li.add-new:hover { overflow: auto; max-height: 300px; } + + .validation-errors { + display: none; + } } diff --git a/src/UI/Mixins/AsValidatedView.js b/src/UI/Mixins/AsValidatedView.js index 7a6cea293..203efa06b 100644 --- a/src/UI/Mixins/AsValidatedView.js +++ b/src/UI/Mixins/AsValidatedView.js @@ -12,12 +12,18 @@ define( var originalBeforeClose = this.prototype.onBeforeClose; var errorHandler = function (response) { - this.model.trigger('validation:failed', response); + if (this.model) { + this.model.trigger('validation:failed', response); + } + + else { + this.trigger('validation:failed', response); + } }; var validatedSync = function (method, model, options) { model.trigger('validation:sync'); -// this.$el.removeAllErrors(); + arguments[2].isValidatedCall = true; return model._originalSync.apply(this, arguments).fail(errorHandler.bind(this)); }; @@ -30,22 +36,34 @@ define( } }; + var validationFailed = function (response) { + if (response.status === 400) { + + var view = this; + var validationErrors = JSON.parse(response.responseText); + _.each(validationErrors, function (error) { + view.$el.processServerError(error); + }); + } + }; + this.prototype.onRender = function () { - this.listenTo(this.model, 'validation:sync', function () { - this.$el.removeAllErrors(); - }); + if (this.model) { + this.listenTo(this.model, 'validation:sync', function () { + this.$el.removeAllErrors(); + }); + + this.listenTo(this.model, 'validation:failed', validationFailed); + } - this.listenTo(this.model, 'validation:failed', function (response) { - if (response.status === 400) { + else { + this.listenTo(this, 'validation:sync', function () { + this.$el.removeAllErrors(); + }); - var view = this; - var validationErrors = JSON.parse(response.responseText); - _.each(validationErrors, function (error) { - view.$el.processServerError(error); - }); - } - }); + this.listenTo(this, 'validation:failed', validationFailed); + } Validation.bind(this); this.bindToModelValidation = bindToModel.bind(this); diff --git a/src/UI/Settings/Indexers/Edit/IndexerEditView.js b/src/UI/Settings/Indexers/Edit/IndexerEditView.js index 004750332..4a77072d7 100644 --- a/src/UI/Settings/Indexers/Edit/IndexerEditView.js +++ b/src/UI/Settings/Indexers/Edit/IndexerEditView.js @@ -30,10 +30,6 @@ define([ this.targetCollection = options.targetCollection; }, - onBeforeClose: function () { - window.alert('closing down!'); - }, - _save: function () { var self = this; var promise = this.model.save(); diff --git a/src/UI/jQuery/jquery.validation.js b/src/UI/jQuery/jquery.validation.js index 4f836f657..210f94d69 100644 --- a/src/UI/jQuery/jquery.validation.js +++ b/src/UI/jQuery/jquery.validation.js @@ -9,7 +9,7 @@ define( var validationName = error.propertyName.toLowerCase(); this.find('.validation-errors') - .addClass('alert alert-error') + .addClass('alert alert-danger') .append('
' + error.errorMessage + '
'); var input = this.find('[name]').filter(function () { @@ -65,7 +65,7 @@ define( $.fn.removeAllErrors = function () { this.find('.error').removeClass('error'); - this.find('.validation-errors').removeClass('alert').removeClass('alert-error').html(''); + this.find('.validation-errors').removeClass('alert').removeClass('alert-danger').html(''); this.find('.validation-error').remove(); return this.find('.help-inline.error-message').remove(); };