mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
Fix #1578 Checks field source validation
This commit is contained in:

committed by
Romain Neutron

parent
35b20ba9f2
commit
b24b4fdb00
@@ -134,13 +134,30 @@ define([
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
tagFieldChangedAction: function(e) {
|
tagFieldChangedAction: function(e) {
|
||||||
|
var $this = this;
|
||||||
var fieldTag = $(e.target);
|
var fieldTag = $(e.target);
|
||||||
var fieldTagId = fieldTag.attr("id");
|
var fieldTagId = fieldTag.attr("id");
|
||||||
var fieldTagValue = fieldTag.val();
|
var fieldTagValue = fieldTag.val();
|
||||||
var notValid = "" === fieldTagValue;
|
|
||||||
|
|
||||||
// check for format tag
|
var onFieldValid = function() {
|
||||||
if (notValid) {
|
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
|
fieldTag
|
||||||
.closest(".control-group")
|
.closest(".control-group")
|
||||||
.addClass("error")
|
.addClass("error")
|
||||||
@@ -149,23 +166,11 @@ define([
|
|||||||
.append(i18n.t("validation_tag_invalid"));
|
.append(i18n.t("validation_tag_invalid"));
|
||||||
// add error
|
// add error
|
||||||
AdminFieldApp.errorManager.addModelFieldError(new 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
|
} else {
|
||||||
AdminFieldApp.errorManager.removeModelFieldError(
|
onFieldValid();
|
||||||
this.model, fieldTagId
|
|
||||||
);
|
|
||||||
|
|
||||||
fieldTag
|
|
||||||
.closest(".control-group")
|
|
||||||
.removeClass("error")
|
|
||||||
.find(".help-block")
|
|
||||||
.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!notValid) {
|
|
||||||
this.fieldChangedAction(e);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteAction: function() {
|
deleteAction: function() {
|
||||||
|
@@ -208,6 +208,23 @@ define([
|
|||||||
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
|
var model = new FieldModel({"id": 1, "sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
|
||||||
|
|
||||||
this.view = new EditView({"model": model});
|
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() {
|
it("render() should return the view object", function() {
|
||||||
@@ -218,12 +235,12 @@ define([
|
|||||||
this.view.render().el.nodeName.should.equal("DIV");
|
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();
|
var view = this.view.render();
|
||||||
|
|
||||||
view.$('input#tag').val("").blur();
|
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() {
|
it("should uncheck vocabulary restricted if provided vocabulary is empty", function() {
|
||||||
@@ -288,6 +305,7 @@ define([
|
|||||||
|
|
||||||
describe("Edge cases", function() {
|
describe("Edge cases", function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
AdminFieldApp.fieldsCollection.reset();
|
||||||
AdminFieldApp.fieldsCollection.add({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
|
AdminFieldApp.fieldsCollection.add({"sbas-id": sbasId, "name": "Categorie", "tag": "XMP:Categorie"});
|
||||||
AdminFieldApp.dcFieldsCollection.add({
|
AdminFieldApp.dcFieldsCollection.add({
|
||||||
"label": "Contributor",
|
"label": "Contributor",
|
||||||
|
Reference in New Issue
Block a user