Commit 5960365a authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Select the lowest index as default on parameter editor

This fix up the default selected when no software type is pre-defined.
parent 01984d6b
...@@ -248,7 +248,8 @@ ...@@ -248,7 +248,8 @@
default_dict[default_value], default_dict[default_value],
default_div, default_div,
path + "/" + default_value, path + "/" + default_value,
restricted); restricted
);
div.appendChild(default_div); div.appendChild(default_div);
} }
} }
...@@ -748,13 +749,27 @@ ...@@ -748,13 +749,27 @@
parameter_shared = gadget.element.querySelector('input.parameter_shared'), parameter_shared = gadget.element.querySelector('input.parameter_shared'),
parameter_schema_url = gadget.element.querySelector('input.parameter_schema_url'), parameter_schema_url = gadget.element.querySelector('input.parameter_schema_url'),
s_input = gadget.element.querySelector('input.slapos-serialisation-type'), s_input = gadget.element.querySelector('input.slapos-serialisation-type'),
selection_option_list = []; selection_option_list = [],
lowest_index = 999,
if (option_selected === undefined) { lowest_option_index;
option_selected = options.value.parameter.softwaretype;
}
if (input.children.length === 0) { if (input.children.length === 0) {
if (option_selected === undefined) {
// search by the lowest index
for (option_index in json['software-type']) {
if (json['software-type'].hasOwnProperty(option_index)) {
if (json['software-type'][option_index].index === undefined) {
json['software-type'][option_index].index = 999;
}
if (json['software-type'][option_index].index < lowest_index) {
lowest_index = json['software-type'][option_index].index;
lowest_option_index = option_index;
}
}
}
}
for (option_index in json['software-type']) { for (option_index in json['software-type']) {
if (json['software-type'].hasOwnProperty(option_index)) { if (json['software-type'].hasOwnProperty(option_index)) {
option = document.createElement("option"); option = document.createElement("option");
...@@ -771,23 +786,22 @@ ...@@ -771,23 +786,22 @@
option.textContent = json['software-type'][option_index].title; option.textContent = json['software-type'][option_index].title;
if (json['software-type'][option_index].index) { if (json['software-type'][option_index].index) {
option['data-index'] = json['software-type'][option_index].index; option['data-index'] = json['software-type'][option_index].index;
} else {
option['data-index'] = 999;
} }
if (options.value.parameter.shared === undefined) {
options.value.parameter.shared = false; if (option_index === lowest_option_index) {
}
if (option_selected === undefined) {
option_selected = option.value; option_selected = option.value;
option.selected = "selected";
option_selected_index = option_index; option_selected_index = option_index;
if (json['software-type'][option_index].shared === true) { if (json['software-type'][option_index].shared === true) {
parameter_shared.value = true; parameter_shared.value = true;
} else { } else {
parameter_shared.value = false; parameter_shared.value = false;
} }
} if (options.value.parameter.shared === undefined) {
options.value.parameter.shared = parameter_shared.value;
if (softwaretype === undefined) { }
softwaretype = option_selected;
} }
if (json['software-type'][option_index].shared === undefined) { if (json['software-type'][option_index].shared === undefined) {
...@@ -795,7 +809,7 @@ ...@@ -795,7 +809,7 @@
} }
option['data-shared'] = json['software-type'][option_index].shared; option['data-shared'] = json['software-type'][option_index].shared;
if ((option_selected_index === undefined) && if ((option_selected_index === undefined) &&
(option.value === option_selected) && (option.value === option_selected) &&
(options.value.parameter.shared == json['software-type'][option_index].shared)) { (options.value.parameter.shared == json['software-type'][option_index].shared)) {
...@@ -820,7 +834,7 @@ ...@@ -820,7 +834,7 @@
} }
} }
} }
selection_option_list.sort(function (a, b) { selection_option_list.sort(function (a, b) {
return a["data-index"] - b["data-index"]; return a["data-index"] - b["data-index"];
}); });
......
...@@ -275,7 +275,7 @@ ...@@ -275,7 +275,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>982.28162.53454.25088</string> </value> <value> <string>984.8983.16389.42973</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -293,7 +293,7 @@ ...@@ -293,7 +293,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1583838932.3</float> <float>1590470140.21</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