Commit 393ece50 authored by Boris Kocherov's avatar Boris Kocherov

support if schema.items is array of schema

parent 8efcc991
......@@ -286,6 +286,21 @@
});
}
function expandItems(g, items, schema_path, minItems) {
if (!(items instanceof Array)) {
return g.expandSchema(items, schema_path, minItems !== 0);
}
var i,
tasks = [];
for (i = 0; i < items.length; i += 1) {
tasks.push(g.expandSchema(items[i], schema_path + '/' + i, i < minItems));
}
return RSVP.Queue()
.push(function () {
return RSVP.all(tasks);
});
}
function expandProperties(g, properties, schema_path, required) {
var ret_obj = {};
return RSVP.Queue()
......@@ -600,6 +615,7 @@
function render_array(gadget, schema, json_document, div_input, path, schema_path) {
var input,
is_items_arr = schema.items instanceof Array,
minItems = schema.minItems || 0;
if (schema.default === undefined &&
json_document === undefined) {
......@@ -622,20 +638,39 @@
// XXX add failback rendering if json_document not array
// input = render_textarea(schema, default_value, "array");
return gadget.expandSchema(schema.items, schema_path + '/items', minItems !== 0)
.push(function (schema_arr) {
return RSVP.Queue()
.push(function () {
return RSVP.all([
expandItems(gadget, schema.items, schema_path + '/items', minItems),
gadget.expandSchema(schema.additionalItems, schema_path + '/additionalItems', false)
]);
})
.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,
len = 0;
// XXX rewrite loading document for anyOf schema
if (json_document) {
for (i = 0; i < json_document.length; i = i + 1) {
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
.push(
addSubForm.bind(gadget, {
gadget: gadget,
parent_type: 'array',
schema_path: schema_path + '/items',
schema_path: schema_path_item,
schema_part: schema_arr,
default_dict: json_document[i],
required: i < minItems
......@@ -646,34 +681,78 @@
len = json_document.length;
}
if (checkSchemaArrOneChoise(schema_arr) && minItems > len) {
for (i = 0; i < (minItems - len); i += 1) {
queue
.push(
addSubForm.bind(gadget, {
gadget: gadget,
parent_type: 'array',
schema_path: schema_arr[0].schema_path,
schema_part: schema_arr[0].schema,
required: true
})
)
.push(div_append);
if (is_items_arr) {
if (minItems > len) {
for (i; i < (minItems - len); i += 1) {
if (i < schema_arr_arr.length) {
schema_arr = schema_arr_arr[i];
} else {
schema_arr = additionalItems;
}
if (!checkSchemaArrOneChoise(schema_arr)) {
break;
}
queue
.push(
addSubForm.bind(gadget, {
gadget: gadget,
parent_type: 'array',
schema_path: schema_arr[0].schema_path,
schema_part: schema_arr[0].schema,
required: true
})
)
.push(div_append);
}
}
if (i < schema_arr_arr.length) {
schema_arr = schema_arr_arr[i];
} else {
schema_arr = additionalItems;
}
// XXX rerender on next item in schema.items
queue.push(render_schema_selector.bind(gadget,
gadget, "add item to array",
schema_arr, function (value) {
return addSubForm({
gadget: gadget,
parent_type: 'array',
type: value.type,
schema_path: value.schema_path,
schema_part: value.schema
})
.push(element_append);
}));
} else {
if (minItems > len && checkSchemaArrOneChoise(schema_arr)) {
for (i = 0; i < (minItems - len); i += 1) {
queue
.push(
addSubForm.bind(gadget, {
gadget: gadget,
parent_type: 'array',
schema_path: schema_arr[0].schema_path,
schema_part: schema_arr[0].schema,
required: true
})
)
.push(div_append);
}
}
}
queue.push(render_schema_selector.bind(gadget,
gadget, "add item to array",
schema_arr, function (value) {
return addSubForm({
gadget: gadget,
parent_type: 'array',
type: value.type,
schema_path: value.schema_path,
schema_part: value.schema
})
.push(element_append);
}));
queue.push(render_schema_selector.bind(gadget,
gadget, "add item to array",
schema_arr, function (value) {
return addSubForm({
gadget: gadget,
parent_type: 'array',
type: value.type,
schema_path: value.schema_path,
schema_part: value.schema
})
.push(element_append);
}));
}
return queue;
})
.push(function (element) {
......
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