Commit 94269625 authored by Boris Kocherov's avatar Boris Kocherov

now rendering use queue it need for subgadget

parent e4a50931
......@@ -42,13 +42,14 @@
return input;
}
function render_field(gadget, key, path, json_field, default_value) {
function render_field(gadget, key, path, json_field, default_value, root) {
var div,
label,
div_input,
span_info,
span_error,
input;
input,
queue = RSVP.Queue();
// var input = document.createElement("input");
......@@ -99,12 +100,15 @@
}
if (json_field.type === "object") {
render_object(
queue
.push(function () {
return render_object(
gadget,
json_field,
default_value,
div_input,
path + "/" + key);
});
}
if (input) {
......@@ -126,7 +130,11 @@
div_input.appendChild(span_error);
div.appendChild(div_input);
return queue
.push(function () {
root.appendChild(div);
return div;
});
}
function render_object(gadget, json_field, default_dict, root, path) {
......@@ -134,7 +142,8 @@
key,
div,
input,
default_used_list = [];
default_used_list = [],
queue = RSVP.Queue();
if (default_dict === undefined) {
default_dict = {};
......@@ -172,13 +181,17 @@
for (key in default_dict) {
if (default_dict.hasOwnProperty(key)) {
default_used_list.push(key);
div_input = document.createElement("div");
div_input.setAttribute("class", "slapos-parameter-dict-key");
div_input.appendChild(
render_field(gadget, key, path, json_field.patternProperties['.*'], default_dict[key])
// div.appendChild(div_input);
queue
.push(
addSubForm.bind(gadget, gadget, {
key: key,
path: path,
element: input,
schema_part: json_field.patternProperties['.*'],
default_dict: default_dict[key]
})
);
div.appendChild(div_input);
}
}
root.appendChild(div);
......@@ -187,26 +200,29 @@
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 + ')';
}
div = render_field(gadget, key, path, json_field.properties[key], default_dict[key]);
root.appendChild(div);
default_used_list.push(key);
queue
.push(render_field.bind(gadget, gadget, key, path,
json_field.properties[key], default_dict[key], root)
);
}
}
for (key in default_dict) {
if (default_dict.hasOwnProperty(key)) {
if (default_used_list.indexOf(key) < 0 ) {
div = render_field(gadget, key, path, {
queue
.push(render_field.bind(gadget, gadget, key, path, {
"type": "string",
"info": "(Not part of the schema)"
}, default_dict[key]);
root.appendChild(div);
}, default_dict[key], root)
);
}
}
}
return root;
return queue;
}
function getFormValuesAsJSONDict(g) {
......@@ -286,8 +302,9 @@
function addSubForm(g, options) {
var element = options.element,
key = element.parentNode.querySelector("input[type='text']").value,
scope = element.name + "/" + key;
key = options.key ||
element.parentNode.querySelector("input[type='text']").value,
scope = (options.path || element.name) + "/" + key;
if (!key || g.props.subforms.hasOwnProperty(scope)) {
return false;
......@@ -302,7 +319,7 @@
div.setAttribute("class", "slapos-parameter-dict-key");
div.appendChild(form_gadget.element);
element.parentNode.parentNode.insertBefore(div, element.parentNode.parentNode.children[1]);
return form_gadget.renderParameterForm(options.schema_part, {}, key, scope);
return form_gadget.renderParameterForm(options.schema_part, options.default_dict, key, scope);
});
}
......@@ -446,9 +463,11 @@
while (g.element.firstChild) {
g.element.removeChild(g.element.firstChild);
}
g.element.appendChild(render_field(g, key, "", schema, default_dict));
return render_field(g, key, "", schema, default_dict, g.element)
.push(function () {
g.listenEvents();
return g.element;
});
})
.declareMethod('renderFailoverTextArea', function (content, error) {
......
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