Commit b9313a0c authored by Boris Kocherov's avatar Boris Kocherov

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

parent 0ff97d42
...@@ -346,6 +346,15 @@ ...@@ -346,6 +346,15 @@
x = {}; x = {};
} else if (!doesntcopy) { } else if (!doesntcopy) {
x = JSON.parse(JSON.stringify(x)); x = JSON.parse(JSON.stringify(x));
if (x.anyOf) {
delete x.anyOf;
}
if (x.oneOf) {
delete x.oneOf;
}
if (x.allOf) {
delete x.allOf;
}
} }
if (y === true) { if (y === true) {
y = {}; y = {};
...@@ -443,6 +452,7 @@ ...@@ -443,6 +452,7 @@
break; break;
case "allOf": case "allOf":
case "anyOf": case "anyOf":
case "oneOf":
case "$ref": case "$ref":
case "id": case "id":
case "$id": case "$id":
...@@ -456,6 +466,7 @@ ...@@ -456,6 +466,7 @@
switch (key) { switch (key) {
case "allOf": case "allOf":
case "anyOf": case "anyOf":
case "oneOf":
case "$ref": case "$ref":
break; break;
default: default:
...@@ -473,7 +484,7 @@ ...@@ -473,7 +484,7 @@
var i, var i,
arr = []; arr = [];
for (i = 0; i < schema_array.length; i += 1) { for (i = 0; i < schema_array.length; i += 1) {
arr.push(expandSchema(g, schema_array[i], schema_path + '/allOf/' + i.toString())); arr.push(expandSchema(g, schema_array[i], schema_path + '/' + i.toString()));
} }
return RSVP.all(arr); return RSVP.all(arr);
}) })
...@@ -507,14 +518,13 @@ ...@@ -507,14 +518,13 @@
}); });
} }
function anyOf(g, schema, schema_path) { function anyOf(g, schema_array, schema_path, base_schema) {
var schema_array = schema.anyOf;
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
var i, var i,
arr = []; arr = [];
for (i = 0; i < schema_array.length; i += 1) { for (i = 0; i < schema_array.length; i += 1) {
arr.push(expandSchema(g, mergeSchemas(schema_array[i], schema), schema_path + '/anyOf/' + i.toString())); arr.push(expandSchema(g, schema_array[i], schema_path + '/' + i.toString()));
} }
return RSVP.all(arr); return RSVP.all(arr);
}) })
...@@ -528,6 +538,13 @@ ...@@ -528,6 +538,13 @@
// or(any, restricted, restricted, .. ) simplify to any // or(any, restricted, restricted, .. ) simplify to any
return [arr[i][z]]; return [arr[i][z]];
} }
if (base_schema.title) {
arr[i][z].title = base_schema.title;
}
if (base_schema.description) {
arr[i][z].description = base_schema.description;
}
arr[i][z].schema = mergeSchemas(base_schema, arr[i][z].schema);
schema_arr.push(arr[i][z]); schema_arr.push(arr[i][z]);
} }
} }
...@@ -544,10 +561,13 @@ ...@@ -544,10 +561,13 @@
schema = true; schema = true;
} }
if (schema.anyOf !== undefined) { if (schema.anyOf !== undefined) {
return anyOf(g, schema, schema_path); return anyOf(g, schema.anyOf, schema_path + '/anyOf', schema);
}
if (schema.oneOf !== undefined) {
return anyOf(g, schema.oneOf, schema_path + '/oneOf', schema);
} }
if (schema.allOf !== undefined) { if (schema.allOf !== undefined) {
return allOf(g, schema.allOf, schema_path, schema); return allOf(g, schema.allOf, schema_path + '/allOf', schema);
} }
if (schema.$ref) { if (schema.$ref) {
return loadJSONSchema(g, schema.$ref, schema_path); return loadJSONSchema(g, schema.$ref, schema_path);
...@@ -573,13 +593,29 @@ ...@@ -573,13 +593,29 @@
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
return [{ return [{
title: ref || schema.title, title: schema.title,
ref: ref,
schema: schema, schema: schema,
schema_path: schema_path schema_path: schema_path
}]; }];
}); });
}; };
function schema_arr_marker(schema_arr) {
var i;
// XXX need cleanup false schema before
for (i = 0; i < schema_arr.length; i += 1) {
if (!schema_arr[i].schema.hasOwnProperty('const')) {
schema_arr[0].is_arr_of_const = false;
break;
}
if (i === schema_arr.length - 1) {
schema_arr[0].is_arr_of_const = true;
}
}
return schema_arr;
}
function expandSchemaForField(g, schema, schema_path, for_required) { function expandSchemaForField(g, schema, schema_path, for_required) {
var required_stack, var required_stack,
prev_field_path; prev_field_path;
...@@ -590,7 +626,8 @@ ...@@ -590,7 +626,8 @@
required_stack = []; required_stack = [];
} }
g.props.schema_required_urls[schema_path] = required_stack; g.props.schema_required_urls[schema_path] = required_stack;
return expandSchema(g, schema, schema_path); return expandSchema(g, schema, schema_path)
.push(schema_arr_marker);
} }
rJS(window) rJS(window)
...@@ -624,6 +661,7 @@ ...@@ -624,6 +661,7 @@
return json_document; return json_document;
}) })
.push(function (json_d) { .push(function (json_d) {
gadget.state.value = JSON.stringify(json_d);
return tv4.validateMultiple(json_d, gadget.props.schema[""]); return tv4.validateMultiple(json_d, gadget.props.schema[""]);
}) })
.push(function (validation) { .push(function (validation) {
...@@ -727,14 +765,17 @@ ...@@ -727,14 +765,17 @@
}) })
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
return this.changeState({ var z = {
key: options.key, key: options.key,
value: JSON.stringify(options.value),
schema: JSON.stringify(options.schema), schema: JSON.stringify(options.schema),
saveOrigValue: options.saveOrigValue, saveOrigValue: options.saveOrigValue,
schema_url: options.schema_url, schema_url: options.schema_url,
editable: options.editable === undefined ? true : options.editable editable: options.editable === undefined ? true : options.editable
}); };
if (options.value !== undefined) {
z.value = JSON.stringify(options.value);
}
return this.changeState(z);
}) })
.onStateChange(function () { .onStateChange(function () {
var g = this, var g = this,
...@@ -804,22 +845,21 @@ ...@@ -804,22 +845,21 @@
schema_url = g.state.schema_url || schema_url = g.state.schema_url ||
(json_document && json_document.$schema); (json_document && json_document.$schema);
if (schema_url) { if (schema_url) {
queue = loadJSONSchema(g, schema_url); queue = loadJSONSchema(g, schema_url)
.push(schema_arr_marker);
} }
} }
if (queue) { if (queue) {
return queue return queue;
.push(function (schema_arr) {
// XXX for root of form use first schema selection
return schema_arr[0].schema;
});
} }
return {}; return [{
schema: true,
schema_path: ""
}];
}) })
.push(function (schema) { .push(function (schema_arr) {
return g.props.form_gadget.renderForm({ return g.props.form_gadget.renderForm({
schema: schema, schema_arr: schema_arr,
schema_path: "",
document: json_document, document: json_document,
saveOrigValue: g.state.saveOrigValue, saveOrigValue: g.state.saveOrigValue,
required: true, required: true,
...@@ -836,6 +876,9 @@ ...@@ -836,6 +876,9 @@
}) })
.push(function () { .push(function () {
return g; return g;
})
.push(undefined, function (err) {
console.log(err);
}); });
}) })
.allowPublicAcquisition("expandSchema", function (arr) { .allowPublicAcquisition("expandSchema", function (arr) {
......
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