Commit 5b0256df authored by Boris Kocherov's avatar Boris Kocherov

erp5_json_form: update from...

erp5_json_form: update from rjs_json_form@e9d56210
parent cc7f2930
...@@ -901,29 +901,6 @@ ...@@ -901,29 +901,6 @@
.allowPublicAcquisition("expandSchema", function (arr) { .allowPublicAcquisition("expandSchema", function (arr) {
return expandSchemaForField(this, arr[0], arr[1], arr[2]); return expandSchemaForField(this, arr[0], arr[1], arr[2]);
}) })
.onEvent('click', function (evt) {
if (evt.target === this.props.delete_button) {
return this.selfRemove(evt);
}
var link = evt.target.getAttribute("data-error-link"),
button_list = this.props.add_buttons,
i;
if (link) {
location.href = link;
return;
}
for (i = 0; i < button_list.length; i = i + 1) {
if (evt.target === button_list[i].element) {
return button_list[i].event(evt);
}
}
})
.declareJob('listenEvents', function () {
// XXX Disable
return;
})
.onLoop(function () { .onLoop(function () {
var gadget = this; var gadget = this;
if (this.props.changed) { if (this.props.changed) {
......
...@@ -441,18 +441,22 @@ ...@@ -441,18 +441,22 @@
} }
function schemaArrFilteredByDocument(schema_arr, json_document) { function schemaArrFilteredByDocument(schema_arr, json_document) {
var i, var x,
i,
errors,
error,
flag, flag,
circular = schema_arr[0].circular, circular = schema_arr[0].circular,
ret_arr = [], ret_arr = [],
validation,
schema; schema;
if (schema_arr.length === 1 || if (schema_arr.length === 1 ||
schema_arr[0].is_arr_of_const) { schema_arr[0].is_arr_of_const) {
return schema_arr; return schema_arr;
} }
if (json_document !== undefined) { if (json_document !== undefined) {
for (i = 0; i < schema_arr.length; i += 1) { for (x = 0; x < schema_arr.length; x += 1) {
schema = schema_arr[i].schema; schema = schema_arr[x].schema;
if (schema === true) { if (schema === true) {
flag = true; flag = true;
} else if (schema === false) { } else if (schema === false) {
...@@ -461,11 +465,49 @@ ...@@ -461,11 +465,49 @@
flag = tv4.validate(json_document, schema); flag = tv4.validate(json_document, schema);
} }
if (flag) { if (flag) {
ret_arr.push(schema_arr[i]); ret_arr.push(schema_arr[x]);
}
}
if (ret_arr.length === 0) {
// currently try to find
// more compatible schema for current document
// XXX it may be need be more smart in future
// (every error has weigh, weigh depend from level...),
// may be not.
for (x = 0; x < schema_arr.length; x += 1) {
schema = schema_arr[x].schema;
if (schema !== false) {
validation = tv4.validateMultiple(json_document, schema);
errors = validation.errors;
flag = true;
for (i = 0; i < errors.length; i += 1) {
error = errors[i];
if (error.code === 0 || // INVALID_TYPE
error.code === 13 || // NOT_PASSED
error.code === 14 // BOOLEAN_SCHEMA_FALSE
) {
if (error.dataPath.split('/').length === 1) {
flag = false;
break;
}
}
if (error.code === 15 // CONST_NOT_EQUAL
) {
// take in account errors only on fist level
if (error.dataPath.split('/').length <= 2) {
flag = false;
break;
}
}
}
if (flag) {
ret_arr = [schema_arr[x]];
break;
}
}
} }
} }
if (ret_arr.length === 0) { if (ret_arr.length === 0) {
// XXX find schema more compatible with document
return schema_arr; return schema_arr;
} }
ret_arr[0].circular = circular; ret_arr[0].circular = circular;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment