Commit eca3154f authored by Boris Kocherov's avatar Boris Kocherov

make code better understandable and use is_arr_of_const marker

checkSchemaSimpleType() use schema_arr option instead schema
schemaArrFilteredByDocument() return schema_arr instead schema_object
parent b2f97275
......@@ -594,7 +594,20 @@
required_stack = [];
}
g.props.schema_required_urls[schema_path] = required_stack;
return expandSchema(g, schema, schema_path);
return expandSchema(g, schema, schema_path)
.push(function (schema_arr) {
var i;
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;
});
}
rJS(window)
......
......@@ -345,11 +345,18 @@
}
return true;
}
if (schema_arr[0].is_arr_of_const) {
return true;
}
return false;
}
function checkSchemaSimpleType(schema) {
return [
function checkSchemaSimpleType(schema_arr) {
// return true if rendering are not recursive
var schema = schema_arr[0].schema;
return schema_arr[0].is_arr_of_const ||
schema.hasOwnProperty('const') ||
[
'string',
'integer',
'number',
......@@ -385,10 +392,12 @@
function schemaArrFilteredByDocument(schema_arr, json_document) {
var i,
flag,
circular = schema_arr[0].circular,
ret_arr = [],
schema;
if (schema_arr.length === 1) {
return schema_arr[0];
if (schema_arr.length === 1 ||
schema_arr[0].is_arr_of_const) {
return schema_arr;
}
if (json_document !== undefined) {
for (i = 0; i < schema_arr.length; i += 1) {
......@@ -406,11 +415,12 @@
}
if (ret_arr.length === 0) {
// XXX find schema more compatible with document
return schema_arr[0];
return schema_arr;
}
ret_arr[0].circular = circular;
return ret_arr;
}
// XXX if (ret_arr.length > 1) notify user
return ret_arr[0];
return schema_arr;
}
function render_schema_selector(gadget, title, schema_arr, event, rerender) {
......@@ -782,7 +792,8 @@
type_changed,
queue = RSVP.Queue();
schema = schemaArrFilteredByDocument(schema_arr, json_document);
// XXX if (ret_arr.length > 1) notify user
schema = schemaArrFilteredByDocument(schema_arr, json_document)[0];
schema_path = schema.schema_path;
schema = schema.schema;
......@@ -1238,28 +1249,28 @@
.push(function (ret) {
var schema_arr,
q = RSVP.Queue(),
s_o,
filtered_schema_arr,
key;
properties = ret;
for (key in properties) {
if (properties.hasOwnProperty(key)) {
schema_arr = properties[key];
s_o = schemaArrFilteredByDocument(schema_arr, json_document[key]);
filtered_schema_arr = schemaArrFilteredByDocument(schema_arr, json_document[key]);
// XXX need schema merge with patternProperties passed key
if (checkSchemaArrOneChoise(schema_arr)) {
if (required.indexOf(key) >= 0) {
used_properties[key] = false;
q.push(render_field.bind(g, g, key, path,
[s_o], json_document[key], root, {required: true})
filtered_schema_arr, json_document[key], root, {required: true})
);
}
if (!used_properties.hasOwnProperty(key) &&
!schema_editor &&
(checkSchemaSimpleType(s_o.schema) || !s_o.circular)
(checkSchemaSimpleType(filtered_schema_arr) || !filtered_schema_arr[0].circular)
) {
used_properties[key] = false;
q.push(render_field.bind(g, g, key, path,
[s_o], json_document[key], root, {
filtered_schema_arr, json_document[key], root, {
required: false,
delete_button: false
}));
......@@ -1273,7 +1284,7 @@
gadget: g,
property_name: key,
path: path,
schema_arr: [s_o],
schema_arr: filtered_schema_arr,
json_document: json_document[key]
})
)
......
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