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,13 +201,59 @@
}
function render_object(gadget, json_field, default_dict, root, path) {
var div_input,
key,
div,
input,
var key,
default_used_list = [],
queue = RSVP.Queue();
function addAdditional(schema) {
var div,
div_input,
input;
div = document.createElement("div");
div.setAttribute("class", "subfield");
div.title = json_field.description;
div_input = document.createElement("div");
div_input.setAttribute("class", "input");
input = document.createElement("input");
input.type = "text";
div_input.appendChild(input);
input = document.createElement("button");
input.setAttribute("class", "add-sub-form");
input.type = "button";
input.name = path;
input.textContent = "Add";
gadget.props.add_buttons.push({
element: input,
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);
queue
.push(
addSubForm.bind(gadget, gadget, {
key: key,
path: path,
element: input,
schema_part: schema,
default_dict: default_dict[key]
})
);
}
}
queue.push(function () {
root.appendChild(div);
});
}
if (default_dict === undefined) {
default_dict = {};
}
......@@ -226,50 +272,14 @@
}
if (json_field.patternProperties !== undefined) {
if (json_field.patternProperties['.*'] !== undefined) {
div = document.createElement("div");
div.setAttribute("class", "subfield");
div.title = json_field.description;
div_input = document.createElement("div");
div_input.setAttribute("class", "input");
input = document.createElement("input");
input.type = "text";
div_input.appendChild(input);
input = document.createElement("button");
input.setAttribute("class", "add-sub-form");
input.type = "button";
input.name = path;
input.textContent = "Add";
gadget.props.add_buttons.push({
element: input,
schema_part: json_field.patternProperties['.*']
});
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);
queue
.push(
addSubForm.bind(gadget, gadget, {
key: key,
path: path,
element: input,
schema_part: json_field.patternProperties['.*'],
default_dict: default_dict[key]
})
);
}
}
root.appendChild(div);
addAdditional(json_field.patternProperties['.*']);
}
}
if (json_field.additionalProperties !== undefined && json_field.additionalProperties.type) {
addAdditional(json_field.additionalProperties);
}
for (key in default_dict) {
if (default_dict.hasOwnProperty(key)) {
if (default_used_list.indexOf(key) < 0 ) {
......@@ -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