1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00

Fixed validation that was causing add existing series to fail

This commit is contained in:
Mark McDowall 2014-06-05 23:38:05 -07:00
parent ddbcb883ca
commit 519b6debfb
6 changed files with 48 additions and 33 deletions

View File

@ -10,17 +10,13 @@ public class ReleaseIntegrationTest : IntegrationTest
[Test] [Test]
public void should_only_have_unknown_series_releases() public void should_only_have_unknown_series_releases()
{ {
var releases = Releases.All(); var releases = Releases.All();
var indexers = Indexers.All(); var indexers = Indexers.All();
releases.Should().OnlyContain(c => c.Rejections.Contains("Unknown Series")); releases.Should().OnlyContain(c => c.Rejections.Contains("Unknown Series"));
releases.Should().OnlyContain(c => BeValidRelease(c)); releases.Should().OnlyContain(c => BeValidRelease(c));
} }
private bool BeValidRelease(ReleaseResource releaseResource) private bool BeValidRelease(ReleaseResource releaseResource)
{ {
releaseResource.Age.Should().BeGreaterOrEqualTo(-1); releaseResource.Age.Should().BeGreaterOrEqualTo(-1);
@ -33,6 +29,5 @@ private bool BeValidRelease(ReleaseResource releaseResource)
return true; return true;
} }
} }
} }

View File

@ -8,14 +8,16 @@
<div class="validation-errors"></div> <div class="validation-errors"></div>
<div class="alert alert-info">Enter the path that contains some or all of your TV series, you will be able to choose which series you want to import<button type="button" class="close" data-dismiss="alert">×</button></div> <div class="alert alert-info">Enter the path that contains some or all of your TV series, you will be able to choose which series you want to import<button type="button" class="close" data-dismiss="alert">×</button></div>
<div class="input-group x-path form-group"> <div class="form-group">
<span class="input-group-addon">&nbsp;<i class="icon-folder-open"></i></span> <div class="input-group x-path">
<input class="col-md-9 form-control" type="text" validation-name="path" placeholder="Enter path to folder that contains your shows"> <span class="input-group-addon">&nbsp;<i class="icon-folder-open"></i></span>
<span class="input-group-btn "> <input class="col-md-9 form-control" type="text" validation-name="path" placeholder="Enter path to folder that contains your shows">
<button class="btn btn-success x-add"> <span class="input-group-btn ">
<i class="icon-ok"/> <button class="btn btn-success x-add">
</button> <i class="icon-ok"/>
</span> </button>
</span>
</div>
</div> </div>
{{#if items}} {{#if items}}

View File

@ -130,4 +130,8 @@ li.add-new:hover {
overflow: auto; overflow: auto;
max-height: 300px; max-height: 300px;
} }
.validation-errors {
display: none;
}
} }

View File

@ -12,12 +12,18 @@ define(
var originalBeforeClose = this.prototype.onBeforeClose; var originalBeforeClose = this.prototype.onBeforeClose;
var errorHandler = function (response) { 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) { var validatedSync = function (method, model, options) {
model.trigger('validation:sync'); model.trigger('validation:sync');
// this.$el.removeAllErrors();
arguments[2].isValidatedCall = true; arguments[2].isValidatedCall = true;
return model._originalSync.apply(this, arguments).fail(errorHandler.bind(this)); 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.prototype.onRender = function () {
this.listenTo(this.model, 'validation:sync', function () { if (this.model) {
this.$el.removeAllErrors(); this.listenTo(this.model, 'validation:sync', function () {
}); this.$el.removeAllErrors();
});
this.listenTo(this.model, 'validation:failed', function (response) { this.listenTo(this.model, 'validation:failed', validationFailed);
if (response.status === 400) { }
var view = this; else {
var validationErrors = JSON.parse(response.responseText); this.listenTo(this, 'validation:sync', function () {
_.each(validationErrors, function (error) { this.$el.removeAllErrors();
view.$el.processServerError(error); });
});
} this.listenTo(this, 'validation:failed', validationFailed);
}); }
Validation.bind(this); Validation.bind(this);
this.bindToModelValidation = bindToModel.bind(this); this.bindToModelValidation = bindToModel.bind(this);

View File

@ -30,10 +30,6 @@ define([
this.targetCollection = options.targetCollection; this.targetCollection = options.targetCollection;
}, },
onBeforeClose: function () {
window.alert('closing down!');
},
_save: function () { _save: function () {
var self = this; var self = this;
var promise = this.model.save(); var promise = this.model.save();

View File

@ -9,7 +9,7 @@ define(
var validationName = error.propertyName.toLowerCase(); var validationName = error.propertyName.toLowerCase();
this.find('.validation-errors') this.find('.validation-errors')
.addClass('alert alert-error') .addClass('alert alert-danger')
.append('<div><i class="icon-exclamation-sign"></i>' + error.errorMessage + '</div>'); .append('<div><i class="icon-exclamation-sign"></i>' + error.errorMessage + '</div>');
var input = this.find('[name]').filter(function () { var input = this.find('[name]').filter(function () {
@ -65,7 +65,7 @@ define(
$.fn.removeAllErrors = function () { $.fn.removeAllErrors = function () {
this.find('.error').removeClass('error'); 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(); this.find('.validation-error').remove();
return this.find('.help-inline.error-message').remove(); return this.find('.help-inline.error-message').remove();
}; };