Commit 424b799e authored by Boris Kocherov's avatar Boris Kocherov

render_array() use schema.minItems for display all required items

parent da8c0b3d
......@@ -374,6 +374,17 @@
});
}
function checkSchemaArrOneChoise(schema_arr) {
if (schema_arr.length === 1) {
if (schema_arr[0].type instanceof Array) {
return schema_arr[0].type.length <= 1;
} else {
return true;
}
}
return false;
}
function convertExpandedProperties2array(properties) {
var property_name,
arr = [],
......@@ -628,13 +639,9 @@
}
function render_array(gadget, schema, json_document, root, path, schema_path) {
var queue = RSVP.Queue(),
div,
var div,
div_input,
input,
item_schema,
i,
maxItems = schema.maxItems;
input;
div = document.createElement("div");
div.setAttribute("class", "subfield");
div.title = schema.description;
......@@ -648,13 +655,55 @@
}
}
item_schema = schema.items;
queue
.push(function () {
return expandSchema(gadget, item_schema, schema_path + '/items');
})
function div_append(child) {
if (child) {
div_input.appendChild(child);
}
}
// XXX add failback rendering if json_document not array
// input = render_textarea(schema, default_value, "array");
return expandSchema(gadget, schema.items, schema_path + '/items')
.push(function (schema_arr) {
return render_schema_selector(gadget, "add item to array",
var queue = RSVP.Queue(),
i,
minItems = schema.minItems || 0,
len = 0;
// XXX rewrite loading document for anyOf schema
if (json_document) {
for (i = 0; i < json_document.length; i = i + 1) {
queue
.push(
addSubForm.bind(gadget, {
gadget: gadget,
parent_type: 'array',
schema_path: schema_path + '/items',
schema_part: schema_arr,
default_dict: json_document[i]
})
)
.push(div_append);
}
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
})
)
.push(div_append);
}
}
queue.push(render_schema_selector.bind(gadget,
gadget, "add item to array",
schema_arr, function (value) {
return addSubForm({
gadget: gadget,
......@@ -664,36 +713,18 @@
schema_part: value.schema
})
.push(element_append);
});
}));
return queue;
})
.push(function (element) {
// var maxItems = schema.maxItems;
input = element;
// XXX update on every add/delete item
input.hidden = maxItems !== undefined && json_document.length >= maxItems;
// input.hidden = maxItems !== undefined && json_document.length >= maxItems;
div_input.appendChild(input);
div.appendChild(div_input);
root.appendChild(div);
});
// XXX rewrite loading document for anyOf schema
if (json_document) {
for (i = 0; i < json_document.length; i = i + 1) {
queue
.push(
addSubForm.bind(gadget, {
gadget: gadget,
parent_type: 'array',
schema_path: schema_path + '/items',
schema_part: item_schema,
default_dict: json_document[i]
})
)
.push(element_append);
}
}
// XXX add failback rendering if json_document not array
// input = render_textarea(schema, default_value, "array");
return queue;
}
function render_field(gadget, key, path, json_field, default_value, root, schema_path, options) {
......
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