Commit abdd8a67 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Fix boolean and values outsite enum for parameter editor

   Boolean should be handled as boolean not as strings.
   Selection should include default value even if they are outside the enum list.
parent 8477ed06
......@@ -46,26 +46,40 @@
selected: (default_value === undefined)
})],
option_index,
selected,
is_selected = (default_value === undefined),
data_format = "string";
if (json_field.type === "integer" || json_field.type === "number") {
data_format = "number";
} else if (json_field.type === "boolean") {
data_format = "boolean";
}
if (default_value === undefined) {
default_value = ""
default_value = "";
}
for (option_index in json_field['enum']) {
if (json_field['enum'].hasOwnProperty(option_index)) {
selected = (json_field['enum'][option_index].toString() === default_value.toString());
is_selected = (is_selected || selected);
option_list.push(domsugar('option', {
value: json_field['enum'][option_index],
text: json_field['enum'][option_index],
"data-format": data_format,
selected: (
json_field['enum'][option_index].toString() === default_value.toString()
)
selected: true
}));
}
}
if (!is_selected) {
// The default value should be included even if it is
// outside the enum.
option_list.push(domsugar('option', {
value: default_value,
text: default_value,
"data-format": data_format,
selected: selected
}));
}
return domsugar('select', {
size: 1,
"data-format": data_format
......@@ -344,20 +358,16 @@
entry_list,
multi_level_dict = {};
$(element.querySelectorAll(".slapos-parameter")).each(function (key, input) {
var index_e;
var index_e, data_format = input.getAttribute("data-format");
if (input.value !== "") {
if (input.type === 'number') {
json_dict[input.name] = parseFloat(input.value);
} else if (input.value === "true") {
json_dict[input.name] = true;
} else if (input.value === "false") {
json_dict[input.name] = false;
} else if (input.tagName === "TEXTAREA") {
if (input.getAttribute("data-format") === "string") {
if (data_format === "string") {
json_dict[input.name] = input.value;
} else if (input.getAttribute("data-format") === "array") {
} else if (data_format === "array") {
json_dict[input.name] = input.value.split('\n');
} else if (input.getAttribute("data-format") === "array-number") {
} else if (data_format === "array-number") {
json_dict[input.name] = [];
entry_list = input.value.split("\n");
for (index_e in entry_list) {
......@@ -373,12 +383,20 @@
json_dict[input.name] = input.value.split('\n');
}
} else if (input.tagName === "SELECT") {
if (input.getAttribute("data-format") === "number") {
json_dict[input.name] = parseFloat(input.value);
} else if (input.getAttribute("data-format") === "integer") {
// Don't use parseInt since it will round the value, modifing the
// use input. So we keep it the value.
json_dict[input.name] = parseFloat(input.value);
if (data_format === "number" || data_format === "integer") {
// Integer must use parseFloat, otherwise the value is rounded
// loosing user's input.
if (isNaN(parseFloat(input.value))) {
json_dict[input.name] = input.value;
} else {
json_dict[input.name] = parseFloat(input.value);
}
} else if (input.getAttribute("data-format") === "boolean") {
if (input.value === "true" || input.value === "false") {
json_dict[input.name] = Boolean(input.value);
} else {
json_dict[input.name] = input.value;
}
} else {
json_dict[input.name] = input.value;
}
......
......@@ -280,7 +280,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1000.13719.19212.614</string> </value>
<value> <string>1000.14042.12571.63982</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -298,7 +298,7 @@
</tuple>
<state>
<tuple>
<float>1652455568.82</float>
<float>1652712920.56</float>
<string>UTC</string>
</tuple>
</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