Commit b2f97275 authored by Boris Kocherov's avatar Boris Kocherov

use one schema_arr option instead schema, schema_path

it modification make code better understandable and allow render more
complex fields which use whole schema_arr.
parent aea01d22
...@@ -812,18 +812,16 @@ ...@@ -812,18 +812,16 @@
} }
} }
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,
......
...@@ -273,8 +273,7 @@ ...@@ -273,8 +273,7 @@
type: options.type, type: options.type,
required: options.required, required: options.required,
delete_button: options.delete_button, delete_button: options.delete_button,
schema: options.schema_part, schema_arr: options.schema_arr,
schema_path: options.schema_path,
document: options.json_document, document: options.json_document,
display_label: options.parent_type !== "array", display_label: options.parent_type !== "array",
saveOrigValue: g.props.saveOrigValue, saveOrigValue: g.props.saveOrigValue,
...@@ -658,7 +657,6 @@ ...@@ -658,7 +657,6 @@
.push(function (arr) { .push(function (arr) {
var queue = RSVP.Queue(), var queue = RSVP.Queue(),
i, i,
schema_path_item = schema_path + '/items',
schema_arr_arr = arr[0], schema_arr_arr = arr[0],
additionalItems = arr[1], additionalItems = arr[1],
schema_arr = schema_arr_arr, schema_arr = schema_arr_arr,
...@@ -669,10 +667,8 @@ ...@@ -669,10 +667,8 @@
if (is_items_arr) { if (is_items_arr) {
if (i < schema_arr_arr.length) { if (i < schema_arr_arr.length) {
schema_arr = schema_arr_arr[i]; schema_arr = schema_arr_arr[i];
schema_path_item = schema_path + '/items/' + i;
} else { } else {
schema_arr = additionalItems; schema_arr = additionalItems;
schema_path_item = schema_path + '/additionalItems';
} }
} }
queue queue
...@@ -680,8 +676,7 @@ ...@@ -680,8 +676,7 @@
addSubForm.bind(gadget, { addSubForm.bind(gadget, {
gadget: gadget, gadget: gadget,
parent_type: 'array', parent_type: 'array',
schema_path: schema_path_item, schema_arr: schema_arr,
schema_part: schema_arr,
json_document: json_document[i], json_document: json_document[i],
required: i < minItems required: i < minItems
}) })
...@@ -707,8 +702,7 @@ ...@@ -707,8 +702,7 @@
addSubForm.bind(gadget, { addSubForm.bind(gadget, {
gadget: gadget, gadget: gadget,
parent_type: 'array', parent_type: 'array',
schema_path: schema_arr[0].schema_path, schema_arr: schema_arr,
schema_part: schema_arr[0].schema,
required: true required: true
}) })
) )
...@@ -728,8 +722,7 @@ ...@@ -728,8 +722,7 @@
gadget: gadget, gadget: gadget,
parent_type: 'array', parent_type: 'array',
type: value.type, type: value.type,
schema_path: value.schema_path, schema_arr: [value]
schema_part: value.schema
}) })
.push(element_append); .push(element_append);
})); }));
...@@ -741,8 +734,7 @@ ...@@ -741,8 +734,7 @@
addSubForm.bind(gadget, { addSubForm.bind(gadget, {
gadget: gadget, gadget: gadget,
parent_type: 'array', parent_type: 'array',
schema_path: schema_arr[0].schema_path, schema_arr: schema_arr,
schema_part: schema_arr[0].schema,
required: true required: true
}) })
) )
...@@ -757,8 +749,7 @@ ...@@ -757,8 +749,7 @@
gadget: gadget, gadget: gadget,
parent_type: 'array', parent_type: 'array',
type: value.type, type: value.type,
schema_path: value.schema_path, schema_arr: [value]
schema_part: value.schema
}) })
.push(element_append); .push(element_append);
})); }));
...@@ -775,7 +766,7 @@ ...@@ -775,7 +766,7 @@
}); });
} }
function render_field(gadget, key, path, schema, json_document, root, schema_path, options) { function render_field(gadget, key, path, schema_arr, json_document, root, options) {
var type, var type,
div, div,
delete_button, delete_button,
...@@ -785,14 +776,18 @@ ...@@ -785,14 +776,18 @@
span_info, span_info,
error_message, error_message,
input, input,
schema,
schema_path,
first_path, first_path,
type_changed, type_changed,
queue = RSVP.Queue(); queue = RSVP.Queue();
if (schema instanceof Array) { schema = schemaArrFilteredByDocument(schema_arr, json_document);
schema = schemaArrFilteredByDocument(schema, json_document); schema_path = schema.schema_path;
schema_path = schema.schema_path; schema = schema.schema;
schema = schema.schema;
if (schema_path === '/') {
schema_path = '';
} }
options = options || {}; options = options || {};
...@@ -1062,8 +1057,7 @@ ...@@ -1062,8 +1057,7 @@
gadget: g, gadget: g,
property_name: property_name, property_name: property_name,
path: path, path: path,
schema_path: schema_path, schema_arr: schema_arr,
schema_part: schema_arr,
json_document: json_document[property_name] json_document: json_document[property_name]
}) })
) )
...@@ -1077,8 +1071,7 @@ ...@@ -1077,8 +1071,7 @@
element: input, element: input,
path: path, path: path,
type: value.type, type: value.type,
schema_path: value.schema_path, schema_arr: [value]
schema_part: value.schema
}) })
.push(element_append); .push(element_append);
}); });
...@@ -1257,7 +1250,7 @@ ...@@ -1257,7 +1250,7 @@
if (required.indexOf(key) >= 0) { if (required.indexOf(key) >= 0) {
used_properties[key] = false; used_properties[key] = false;
q.push(render_field.bind(g, g, key, path, q.push(render_field.bind(g, g, key, path,
s_o.schema, json_document[key], root, s_o.schema_path, {required: true}) [s_o], json_document[key], root, {required: true})
); );
} }
if (!used_properties.hasOwnProperty(key) && if (!used_properties.hasOwnProperty(key) &&
...@@ -1266,7 +1259,7 @@ ...@@ -1266,7 +1259,7 @@
) { ) {
used_properties[key] = false; used_properties[key] = false;
q.push(render_field.bind(g, g, key, path, q.push(render_field.bind(g, g, key, path,
s_o.schema, json_document[key], root, s_o.schema_path, { [s_o], json_document[key], root, {
required: false, required: false,
delete_button: false delete_button: false
})); }));
...@@ -1280,8 +1273,7 @@ ...@@ -1280,8 +1273,7 @@
gadget: g, gadget: g,
property_name: key, property_name: key,
path: path, path: path,
schema_path: s_o.schema_path, schema_arr: [s_o],
schema_part: s_o.schema,
json_document: json_document[key] json_document: json_document[key]
}) })
) )
...@@ -1300,8 +1292,7 @@ ...@@ -1300,8 +1292,7 @@
property_name: value.property_name, property_name: value.property_name,
path: path, path: path,
type: value.type, type: value.type,
schema_path: value.schema_path, schema_arr: [value]
schema_part: value.schema
}) })
.push(function (element) { .push(function (element) {
var s_e = selector.element; var s_e = selector.element;
...@@ -1411,8 +1402,10 @@ ...@@ -1411,8 +1402,10 @@
gadget: g, gadget: g,
property_name: key, property_name: key,
path: path, path: path,
schema_path: "", schema_arr: [{
schema_part: undefined, schema: undefined,
schema_path: ""
}],
json_document: json_document[key] json_document: json_document[key]
}) })
) )
...@@ -1729,7 +1722,7 @@ ...@@ -1729,7 +1722,7 @@
.declareMethod('renderForm', function (options) { .declareMethod('renderForm', function (options) {
var g = this, var g = this,
property_name = g.element.getAttribute('data-json-property-name'), property_name = g.element.getAttribute('data-json-property-name'),
schema = options.schema, schema = options.schema_arr !== undefined && options.schema_arr[0].schema,
root; root;
g.props.changed = false; g.props.changed = false;
g.props.saveOrigValue = options.saveOrigValue; g.props.saveOrigValue = options.saveOrigValue;
...@@ -1766,8 +1759,8 @@ ...@@ -1766,8 +1759,8 @@
g.props.updatePropertySelectors = true; g.props.updatePropertySelectors = true;
g.props.current_document = options.document; g.props.current_document = options.document;
} }
return render_field(g, property_name, "", schema, return render_field(g, property_name, "", options.schema_arr,
options.document, root, options.schema_path, options.document, root,
{ {
type: options.type, type: options.type,
required: options.required, required: options.required,
......
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