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,31 +201,14 @@ ...@@ -201,31 +201,14 @@
} }
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();
if (default_dict === undefined) { function addAdditional(schema) {
default_dict = {}; var div,
} div_input,
input;
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) {
div = document.createElement("div"); div = document.createElement("div");
div.setAttribute("class", "subfield"); div.setAttribute("class", "subfield");
...@@ -245,12 +228,12 @@ ...@@ -245,12 +228,12 @@
input.textContent = "Add"; input.textContent = "Add";
gadget.props.add_buttons.push({ gadget.props.add_buttons.push({
element: input, element: input,
schema_part: json_field.patternProperties['.*'] schema_part: schema
}); });
div_input.appendChild(input); div_input.appendChild(input);
div.appendChild(div_input); div.appendChild(div_input);
for (key in default_dict) { for (key in default_dict) {
if (default_dict.hasOwnProperty(key) && default_used_list.indexOf(key) < 0) { if (default_dict.hasOwnProperty(key) && default_used_list.indexOf(key) < 0) {
default_used_list.push(key); default_used_list.push(key);
...@@ -260,14 +243,41 @@ ...@@ -260,14 +243,41 @@
key: key, key: key,
path: path, path: path,
element: input, element: input,
schema_part: json_field.patternProperties['.*'], schema_part: schema,
default_dict: default_dict[key] default_dict: default_dict[key]
}) })
); );
} }
} }
queue.push(function () {
root.appendChild(div); 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) { for (key in default_dict) {
...@@ -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