Commit 94269625 authored by Boris Kocherov's avatar Boris Kocherov

now rendering use queue it need for subgadget

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