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 @@ 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;
}
}
}

View File

@ -8,14 +8,16 @@
<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="input-group x-path form-group">
<span class="input-group-addon">&nbsp;<i class="icon-folder-open"></i></span>
<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-btn ">
<button class="btn btn-success x-add">
<i class="icon-ok"/>
</button>
</span>
<div class="form-group">
<div class="input-group x-path">
<span class="input-group-addon">&nbsp;<i class="icon-folder-open"></i></span>
<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-btn ">
<button class="btn btn-success x-add">
<i class="icon-ok"/>
</button>
</span>
</div>
</div>
{{#if items}}

View File

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

View File

@ -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', function (response) {
if (response.status === 400) {
this.listenTo(this.model, 'validation:failed', validationFailed);
}
var view = this;
var validationErrors = JSON.parse(response.responseText);
_.each(validationErrors, function (error) {
view.$el.processServerError(error);
});
}
});
else {
this.listenTo(this, 'validation:sync', function () {
this.$el.removeAllErrors();
});
this.listenTo(this, 'validation:failed', validationFailed);
}
Validation.bind(this);
this.bindToModelValidation = bindToModel.bind(this);

View File

@ -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();

View File

@ -9,7 +9,7 @@ define(
var validationName = error.propertyName.toLowerCase();
this.find('.validation-errors')
.addClass('alert alert-error')
.addClass('alert alert-danger')
.append('<div><i class="icon-exclamation-sign"></i>' + error.errorMessage + '</div>');
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();
};