Commit 0ff97d42 authored by Boris Kocherov's avatar Boris Kocherov

erp5_json_form: update version from https://lab.nexedi.com/bk/rjs_json_form

parent c67dad31
...@@ -199,12 +199,15 @@ ...@@ -199,12 +199,15 @@
return input; return input;
} }
function render_const(schema, json_document) { function render_const(g, schema, json_document) {
var input = document.createElement("input"), var input = document.createElement("input"),
ser_doc = JSON.stringify(json_document), ser_doc = JSON.stringify(json_document),
ser_const = JSON.stringify(schema.const); ser_const = JSON.stringify(schema.const);
input.setAttribute('readonly', true); input.setAttribute('readonly', true);
if (json_document === undefined || deepEqual(json_document, schema.const)) { if (json_document === undefined || deepEqual(json_document, schema.const)) {
if (json_document === undefined) {
g.props.changed = true;
}
input.setAttribute('data-origin-value', ser_const); input.setAttribute('data-origin-value', ser_const);
input.value = ser_const; input.value = ser_const;
} else { } else {
...@@ -636,6 +639,13 @@ ...@@ -636,6 +639,13 @@
} }
} }
if (json_document === undefined) {
if (schema.hasOwnProperty('default')) {
json_document = schema.default;
gadget.props.changed = true;
}
}
// XXX add failback rendering if json_document not array // XXX add failback rendering if json_document not array
// input = render_textarea(schema, default_value, "array"); // input = render_textarea(schema, default_value, "array");
return RSVP.Queue() return RSVP.Queue()
...@@ -880,7 +890,7 @@ ...@@ -880,7 +890,7 @@
div_input.setAttribute("class", "input"); div_input.setAttribute("class", "input");
if (json_field.const !== undefined) { if (json_field.const !== undefined) {
input = render_const(json_field, default_value); input = render_const(gadget, json_field, default_value);
} else if (json_field.enum !== undefined) { } else if (json_field.enum !== undefined) {
input = render_enum(gadget, json_field, default_value); input = render_enum(gadget, json_field, default_value);
// XXX take in account existing type with enum // XXX take in account existing type with enum
...@@ -888,7 +898,7 @@ ...@@ -888,7 +898,7 @@
} }
if (!input && type === "null") { if (!input && type === "null") {
input = render_const({const: null}, default_value); input = render_const(gadget, {const: null}, default_value);
} }
if (!input && type === "boolean") { if (!input && type === "boolean") {
...@@ -1208,7 +1218,12 @@ ...@@ -1208,7 +1218,12 @@
} }
if (default_dict === undefined) { if (default_dict === undefined) {
default_dict = {}; if (json_field.hasOwnProperty('default')) {
default_dict = json_field.default;
g.props.changed = true;
} else {
default_dict = {};
}
} }
return expandProperties(g, json_field.properties, schema_path + '/properties/', required) return expandProperties(g, json_field.properties, schema_path + '/properties/', required)
...@@ -1222,6 +1237,7 @@ ...@@ -1222,6 +1237,7 @@
if (properties.hasOwnProperty(key)) { if (properties.hasOwnProperty(key)) {
schema_arr = properties[key]; schema_arr = properties[key];
s_o = schemaArrFilteredByDocument(schema_arr, default_dict[key]); s_o = schemaArrFilteredByDocument(schema_arr, default_dict[key]);
// XXX need schema merge with patternProperties passed key
if (checkSchemaArrOneChoise(schema_arr)) { if (checkSchemaArrOneChoise(schema_arr)) {
if (required.indexOf(key) >= 0) { if (required.indexOf(key) >= 0) {
used_properties[key] = false; used_properties[key] = false;
...@@ -1312,30 +1328,44 @@ ...@@ -1312,30 +1328,44 @@
}) })
.push(function () { .push(function () {
var queue = RSVP.Queue(), var queue = RSVP.Queue(),
key,
additionalProperties; additionalProperties;
// XXX for pattern properties needs schemas merge for
// all passed patterns
if (json_field.patternProperties !== undefined) { if (json_field.patternProperties !== undefined) {
// XXX need loop on any pattern properties for (key in json_field.patternProperties) {
if (json_field.patternProperties['.*'] !== undefined) { if (json_field.patternProperties.hasOwnProperty(key)) {
queue if (key === ".*" ||
.push(render_object_additionalProperty.bind(g, key === "^.*$" ||
key === ".*$" ||
key === "^.*"
) {
// additionalProperties nether used in this case
additionalProperties = false;
}
queue
.push(render_object_additionalProperty.bind(g,
g, g,
".* property", key + " property",
default_dict, default_dict,
path, path,
json_field.patternProperties['.*'], json_field.patternProperties[key],
schema_path + '/patternProperties/.*', schema_path + '/patternProperties/' + key,
used_properties, used_properties,
element_append element_append
)) ))
.push(root_append); .push(root_append);
}
} }
} }
if (json_field.additionalProperties === undefined) { if (additionalProperties === undefined) {
additionalProperties = true; if (json_field.additionalProperties === undefined) {
} else { additionalProperties = true;
additionalProperties = json_field.additionalProperties; } else {
additionalProperties = json_field.additionalProperties;
}
} }
if (additionalProperties !== false) { if (additionalProperties !== false) {
queue queue
......
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