Commit 2690e7d8 authored by Boris Kocherov's avatar Boris Kocherov

add render object.additionalProperties

parent cf7bf0b7
......@@ -70,7 +70,7 @@ Below is the list of JSON Schema validation properties and current supported sta
**object**
* `additionalProperties`
- rendering is not supported
- **fixed** rendering is not supported
* `dependencies`
- rendering is not supported
* `maxProperties`
......
......@@ -201,31 +201,14 @@
}
function render_object(gadget, json_field, default_dict, root, path) {
var div_input,
key,
div,
input,
var key,
default_used_list = [],
queue = RSVP.Queue();
if (default_dict === undefined) {
default_dict = {};
}
for (key in json_field.properties) {
if (json_field.properties.hasOwnProperty(key)) {
default_used_list.push(key);
if (json_field.properties[key].default !== undefined) {
json_field.properties[key].info = '(default = ' + json_field.properties[key].default + ')';
}
queue
.push(render_field.bind(gadget, gadget, key, path,
json_field.properties[key], default_dict[key], root)
);
}
}
if (json_field.patternProperties !== undefined) {
if (json_field.patternProperties['.*'] !== undefined) {
function addAdditional(schema) {
var div,
div_input,
input;
div = document.createElement("div");
div.setAttribute("class", "subfield");
......@@ -245,12 +228,12 @@
input.textContent = "Add";
gadget.props.add_buttons.push({
element: input,
schema_part: json_field.patternProperties['.*']
schema_part: schema
});
div_input.appendChild(input);
div.appendChild(div_input);
for (key in default_dict) {
if (default_dict.hasOwnProperty(key) && default_used_list.indexOf(key) < 0) {
default_used_list.push(key);
......@@ -260,14 +243,41 @@
key: key,
path: path,
element: input,
schema_part: json_field.patternProperties['.*'],
schema_part: schema,
default_dict: default_dict[key]
})
);
}
}
queue.push(function () {
root.appendChild(div);
});
}
if (default_dict === undefined) {
default_dict = {};
}
for (key in json_field.properties) {
if (json_field.properties.hasOwnProperty(key)) {
default_used_list.push(key);
if (json_field.properties[key].default !== undefined) {
json_field.properties[key].info = '(default = ' + json_field.properties[key].default + ')';
}
queue
.push(render_field.bind(gadget, gadget, key, path,
json_field.properties[key], default_dict[key], root)
);
}
}
if (json_field.patternProperties !== undefined) {
if (json_field.patternProperties['.*'] !== undefined) {
addAdditional(json_field.patternProperties['.*']);
}
}
if (json_field.additionalProperties !== undefined && json_field.additionalProperties.type) {
addAdditional(json_field.additionalProperties);
}
for (key in default_dict) {
......@@ -286,7 +296,7 @@
}
function getFormValuesAsJSONDict(g) {
var multi_level_dict = {},
var multi_level_dict = {"":{}},
scope,
options = g.props,
array,
......@@ -295,14 +305,10 @@
queue = RSVP.Queue();
function convertOnMultiLevel(d, key, value) {
var orig_d = d,
i,
var i,
kk,
key_list = key.split("/");
if (key === "") {
return value;
}
for (i = 1; i < key_list.length; i += 1) {
for (i = 0; i < key_list.length; i += 1) {
kk = key_list[i];
if (i === key_list.length - 1) {
if (value === undefined) {
......@@ -317,7 +323,6 @@
d = d[kk];
}
}
return orig_d;
}
function recursiveGetContent(gadget, scope) {
......@@ -340,7 +345,7 @@
})
.push(function (jdict) {
var array = convertOnMultiLevel(multi_level_dict, parent_scope);
if (!array) {
if (!(array instanceof Array)) {
array = [];
convertOnMultiLevel(multi_level_dict, parent_scope, array);
}
......@@ -394,10 +399,10 @@
});
for (key in json_dict) {
if (json_dict.hasOwnProperty(key)) {
multi_level_dict = convertOnMultiLevel(multi_level_dict, key, json_dict[key]);
convertOnMultiLevel(multi_level_dict, key, json_dict[key]);
}
}
return multi_level_dict;
return multi_level_dict[""];
});
}
......@@ -435,7 +440,7 @@
// add after button
// element.parentNode.parentNode.insertBefore(div, element.parentNode.parentNode.children[1]);
// add to end of list
element.parentNode.parentNode.appendChild(div);
element.parentNode.appendChild(div);
return form_gadget.renderForm({
schema: options.schema_part,
......
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