Fix #1578 Checks field source validation

This commit is contained in:
Nicolas Le Goff
2013-11-08 16:26:22 +01:00
committed by Romain Neutron
parent 35b20ba9f2
commit b24b4fdb00
2 changed files with 50 additions and 27 deletions

View File

@@ -134,13 +134,30 @@ define([
return this;
},
tagFieldChangedAction: function(e) {
var $this = this;
var fieldTag = $(e.target);
var fieldTagId = fieldTag.attr("id");
var fieldTagValue = fieldTag.val();
var notValid = "" === fieldTagValue;
// check for format tag
if (notValid) {
var onFieldValid = function() {
if (fieldTag.closest(".control-group").hasClass("error")) {
// remove error
AdminFieldApp.errorManager.removeModelFieldError(
$this.model, fieldTagId
);
fieldTag
.closest(".control-group")
.removeClass("error")
.find(".help-block")
.empty();
} else {
$this.fieldChangedAction(e);
}
}
if ("" !== fieldTagValue) {
var jqxhr = $.get( "/admin/fields/tags/"+fieldTagValue, onFieldValid).fail(function() {
fieldTag
.closest(".control-group")
.addClass("error")
@@ -149,23 +166,11 @@ define([
.append(i18n.t("validation_tag_invalid"));
// add error
AdminFieldApp.errorManager.addModelFieldError(new Error(
this.model, fieldTagId, i18n.t("validation_tag_invalid")
$this.model, fieldTagId, i18n.t("validation_tag_invalid")
));
} else if (fieldTag.closest(".control-group").hasClass("error")) {
// remove error
AdminFieldApp.errorManager.removeModelFieldError(
this.model, fieldTagId
);
fieldTag
.closest(".control-group")
.removeClass("error")
.find(".help-block")
.empty();
}
if (!notValid) {
this.fieldChangedAction(e);
});
} else {
onFieldValid();
}
},
deleteAction: function() {

View File

@@ -208,6 +208,23 @@ define([
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
this.view = new EditView({"model": model});
AdminFieldApp.fieldsCollection.reset();
AdminFieldApp.fieldsCollection.add({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
AdminFieldApp.dcFieldsCollection.add({
"label": "Contributor",
"definition": "An entity responsible for making contributions to the resource.",
"URI": "http://dublincore.org/documents/dces/#contributor"
});
AdminFieldApp.saveView = new SaveView();
AdminFieldApp.fieldErrorView = new FieldErrorView();
AdminFieldApp.fieldListView = new ListItemView({
collection: AdminFieldApp.fieldsCollection,
el: AdminFieldApp.$leftBlock
});
// render views
AdminFieldApp.saveView.render();
AdminFieldApp.fieldListView.render();
});
it("render() should return the view object", function() {
@@ -218,12 +235,12 @@ define([
this.view.render().el.nodeName.should.equal("DIV");
});
it("should render an error message if provided tag is empty", function() {
it("should rnot ender an error message if provided tag is empty", function() {
var view = this.view.render();
view.$('input#tag').val("").blur();
assert.isTrue(view.$('input#tag').closest(".control-group").hasClass("error"));
assert.isFalse(view.$('input#tag').closest(".control-group").hasClass("error"));
});
it("should uncheck vocabulary restricted if provided vocabulary is empty", function() {
@@ -288,6 +305,7 @@ define([
describe("Edge cases", function() {
beforeEach(function() {
AdminFieldApp.fieldsCollection.reset();
AdminFieldApp.fieldsCollection.add({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
AdminFieldApp.dcFieldsCollection.add({
"label": "Contributor",