Commit 9ba0bebd authored by Boris Kocherov's avatar Boris Kocherov

not use json.parse json.stringify for generation button action

parent d13dae53
...@@ -119,11 +119,14 @@ ...@@ -119,11 +119,14 @@
div_input.appendChild(input); div_input.appendChild(input);
input = document.createElement("button"); input = document.createElement("button");
input.value = btoa(JSON.stringify(json_field.patternProperties['.*']));
input.setAttribute("class", "add-sub-form"); input.setAttribute("class", "add-sub-form");
input.type = "button"; input.type = "button";
input.name = path; input.name = path;
input.textContent = "Add"; input.textContent = "Add";
gadget.props.add_buttons.push({
element: input,
schema_part: json_field.patternProperties['.*']
});
div_input.appendChild(input); div_input.appendChild(input);
div.appendChild(div_input); div.appendChild(div_input);
...@@ -274,8 +277,9 @@ ...@@ -274,8 +277,9 @@
return gadget.processValidation(json_url); return gadget.processValidation(json_url);
} }
function addSubForm(g, element) { function addSubForm(g, options) {
var subform_json = JSON.parse(atob(element.value)), var element = options.element,
subform_json = options.schema_part,
input_text = element.parentNode.querySelector("input[type='text']"), input_text = element.parentNode.querySelector("input[type='text']"),
div = document.createElement("div"), div = document.createElement("div"),
label; label;
...@@ -301,7 +305,7 @@ ...@@ -301,7 +305,7 @@
function loadEventList(gadget) { function loadEventList(gadget) {
var g = gadget, var g = gadget,
field_list = g.props.inputs, field_list = g.props.inputs,
button_list = g.element.querySelectorAll('button.add-sub-form'), button_list = g.props.add_buttons,
label_list = g.element.querySelectorAll('label.slapos-parameter-dict-key'), label_list = g.element.querySelectorAll('label.slapos-parameter-dict-key'),
i, i,
promise_list = []; promise_list = [];
...@@ -317,7 +321,7 @@ ...@@ -317,7 +321,7 @@
for (i = 0; i < button_list.length; i = i + 1) { for (i = 0; i < button_list.length; i = i + 1) {
promise_list.push(loopEventListener( promise_list.push(loopEventListener(
button_list[i], button_list[i].element,
'click', 'click',
false, false,
addSubForm.bind(g, g, button_list[i]) addSubForm.bind(g, g, button_list[i])
...@@ -401,7 +405,8 @@ ...@@ -401,7 +405,8 @@
.declareMethod('renderParameterForm', function (schema, default_dict) { .declareMethod('renderParameterForm', function (schema, default_dict) {
var g = this, var g = this,
parent_element = document.createDocumentFragment(); parent_element = document.createDocumentFragment();
g.params.inputs = []; g.props.inputs = [];
g.props.add_buttons = [];
render_subform(g, schema, default_dict, parent_element); render_subform(g, schema, default_dict, parent_element);
while (g.element.firstChild) { while (g.element.firstChild) {
g.element.removeChild(g.element.firstChild); g.element.removeChild(g.element.firstChild);
......
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