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