Commit 35627702 authored by Rafael Monnerat's avatar Rafael Monnerat Committed by root

slapos_web: Support multiple forms for same software type and allow use textareas

Allows to use multiple entries forms the same software type (simple,advanced,slave).
Implement a way to render text area for some string fields.
parent 476bddaf
...@@ -157,12 +157,12 @@ ...@@ -157,12 +157,12 @@
option.selected = "selected";\n option.selected = "selected";\n
}\n }\n
input.appendChild(option);\n input.appendChild(option);\n
for (option_index in json_field.enum) {\n for (option_index in json_field[\'enum\']) {\n
if (json_field.enum.hasOwnProperty(option_index)) {\n if (json_field[\'enum\'].hasOwnProperty(option_index)) {\n
optionz = document.createElement("option");\n optionz = document.createElement("option");\n
optionz.value = json_field.enum[option_index];\n optionz.value = json_field[\'enum\'][option_index];\n
optionz.textContent = json_field.enum[option_index];\n optionz.textContent = json_field[\'enum\'][option_index];\n
if (json_field.enum[option_index] === default_value) {\n if (json_field[\'enum\'][option_index] === default_value) {\n
optionz.selected = "selected";\n optionz.selected = "selected";\n
}\n }\n
input.appendChild(optionz);\n input.appendChild(optionz);\n
...@@ -170,8 +170,8 @@ ...@@ -170,8 +170,8 @@
}\n }\n
return input;\n return input;\n
}\n }\n
\n \n
function render_textarea(json_field, default_value) {\n function render_textarea(json_field, default_value, data_format) {\n
var input = document.createElement("textarea");\n var input = document.createElement("textarea");\n
if (default_value !== undefined) {\n if (default_value !== undefined) {\n
if (default_value instanceof Array) {\n if (default_value instanceof Array) {\n
...@@ -180,22 +180,27 @@ ...@@ -180,22 +180,27 @@
input.value = default_value;\n input.value = default_value;\n
}\n }\n
}\n }\n
input["data-format"] = data_format;\n
return input;\n return input;\n
}\n }\n
\n \n
function render_field(json_field, default_value) {\n function render_field(json_field, default_value) {\n
\n \n
if (json_field.enum !== undefined) {\n if (json_field[\'enum\'] !== undefined) {\n
return render_selection(json_field, default_value);\n return render_selection(json_field, default_value);\n
}\n }\n
\n \n
if (json_field.type === "boolean") {\n if (json_field.type === "boolean") {\n
json_field.enum = [true, false];\n json_field[\'enum\'] = [true, false];\n
return render_selection(json_field, default_value);\n return render_selection(json_field, default_value);\n
}\n }\n
\n \n
if (json_field.type === "array") {\n if (json_field.type === "array") {\n
return render_textarea(json_field, default_value);\n return render_textarea(json_field, default_value, "array");\n
}\n
\n
if (json_field.type === "string" && json_field.textarea === true) {\n
return render_textarea(json_field, default_value, "string");\n
}\n }\n
\n \n
var input = document.createElement("input");\n var input = document.createElement("input");\n
...@@ -204,11 +209,9 @@ ...@@ -204,11 +209,9 @@
input.value = default_value;\n input.value = default_value;\n
}\n }\n
\n \n
switch (json_field.type) {\n if (json_field.type === "integer") {\n
case "integer":\n
input.type = "number";\n input.type = "number";\n
break;\n } else {\n
default:\n
input.type = "text";\n input.type = "text";\n
}\n }\n
\n \n
...@@ -306,9 +309,9 @@ ...@@ -306,9 +309,9 @@
input.setAttribute("class", "slapos-parameter");\n input.setAttribute("class", "slapos-parameter");\n
div_input.appendChild(input);\n div_input.appendChild(input);\n
}\n }\n
if (json_field.properties[key].default !== undefined) {\n if (json_field.properties[key][\'default\'] !== undefined) {\n
span_info = document.createElement("span");\n span_info = document.createElement("span");\n
span_info.textContent = \'(default = \' + json_field.properties[key].default + \')\';\n span_info.textContent = \'(default = \' + json_field.properties[key][\'default\'] + \')\';\n
div_input.appendChild(span_info);\n div_input.appendChild(span_info);\n
}\n }\n
span_error = document.createElement("span");\n span_error = document.createElement("span");\n
...@@ -335,7 +338,11 @@ ...@@ -335,7 +338,11 @@
} else if (input.value === "false") {\n } else if (input.value === "false") {\n
json_dict[input.name] = false;\n json_dict[input.name] = false;\n
} else if (input.tagName === "TEXTAREA") {\n } else if (input.tagName === "TEXTAREA") {\n
if (input["data-format"] === "string") {\n
json_dict[input.name] = input.value;\n
} else {\n
json_dict[input.name] = input.value.split(\'\\n\');\n json_dict[input.name] = input.value.split(\'\\n\');\n
}\n
} else {\n } else {\n
json_dict[input.name] = input.value;\n json_dict[input.name] = input.value;\n
}\n }\n
...@@ -374,11 +381,10 @@ ...@@ -374,11 +381,10 @@
\n \n
function collapseParameter(element) {\n function collapseParameter(element) {\n
$(element).parent().children("div").toggle(300);\n $(element).parent().children("div").toggle(300);\n
if ($(element).hasClass("slapos-⁠parameter-⁠dict-⁠key-⁠colapse")) {\n if ($(element).hasClass("slapos-parameter-dict-key-colapse")) {\n
$(element).removeClass("slapos-⁠parameter-⁠dict-⁠key-⁠colapse");\n $(element).removeClass("slapos-parameter-dict-key-colapse");\n
}\n } else {\n
else {\n $(element).addClass("slapos-parameter-dict-key-colapse");\n
$(element).addClass("slapos-⁠parameter-⁠dict-⁠key-⁠colapse");\n
}\n }\n
return element;\n return element;\n
}\n }\n
...@@ -602,19 +608,21 @@ ...@@ -602,19 +608,21 @@
throw new Error("undefined json_url");\n throw new Error("undefined json_url");\n
}\n }\n
var g = this,\n var g = this,\n
softwaretype;\n softwaretype,\n
softwaretypeindex;\n
\n \n
this.options = options;\n this.options = options;\n
\n \n
function updateParameterForm(evt) {\n function updateParameterForm(evt) {\n
options.parameter.softwaretype = evt.srcElement.value;\n options.parameter.softwaretype = evt.srcElement.value;\n
options.parameter.softwaretypeindex = evt.srcElement.selectedOptions[0]["data-id"];\n
return g.render(options);\n return g.render(options);\n
}\n }\n
\n \n
return g.loadSoftwareJSON(g.options.json_url).push(function (json) {\n return g.loadSoftwareJSON(g.options.json_url).push(function (json) {\n
var option_index,\n var option_index,\n
option,\n option,\n
option_selected = options.parameter.softwaretype,\n option_selected = options.parameter.softwaretypeindex,\n
input = g.props.element.querySelector(\'select.slapos-software-type\'),\n input = g.props.element.querySelector(\'select.slapos-software-type\'),\n
s_input = g.props.element.querySelector(\'input.slapos-serialisation-type\');\n s_input = g.props.element.querySelector(\'input.slapos-serialisation-type\');\n
\n \n
...@@ -622,7 +630,12 @@ ...@@ -622,7 +630,12 @@
for (option_index in json[\'software-type\']) {\n for (option_index in json[\'software-type\']) {\n
if (json[\'software-type\'].hasOwnProperty(option_index)) {\n if (json[\'software-type\'].hasOwnProperty(option_index)) {\n
option = document.createElement("option");\n option = document.createElement("option");\n
if (json[\'software-type\'][option_index][\'software-type\'] !== undefined) {\n
option.value = json[\'software-type\'][option_index][\'software-type\'];\n
} else {\n
option.value = option_index;\n option.value = option_index;\n
}\n
option[\'data-id\'] = option_index;\n
option.textContent = json[\'software-type\'][option_index].title;\n option.textContent = json[\'software-type\'][option_index].title;\n
// option.index = json[\'software-type\'][option_index].index;\n // option.index = json[\'software-type\'][option_index].index;\n
\n \n
...@@ -738,6 +751,7 @@ ...@@ -738,6 +751,7 @@
}\n }\n
\n \n
g.options.parameter.softwaretype = e.value;\n g.options.parameter.softwaretype = e.value;\n
g.options.parameter.softwaretypeindex = e.selectedOptions[0]["data-id"];\n
return g.render(g.options)\n return g.render(g.options)\n
.push(function () {\n .push(function () {\n
return loadEventList(g);\n return loadEventList(g);\n
...@@ -908,7 +922,7 @@ ...@@ -908,7 +922,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>943.22522.16130.42513</string> </value> <value> <string>950.20387.46343.57497</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -926,7 +940,7 @@ ...@@ -926,7 +940,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1432912068.83</float> <float>1459876241.06</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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