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