Commit 11fa88e4 authored by Łukasz Nowak's avatar Łukasz Nowak

slapos_jio: Support list of elements expressed with oneOf

By following feature of JSON Schema Draft-06 render a structure like:

  "element": {
    "oneOf": [
      {
        "const": "value1",
        "title": "Description1"
      },
      {
        "const": "value2",
        "title": "Description2"
      }
    ]
  }

To:

  <select size="1">
    <option value=""></option>
    <option value="value1">Description1</option>
    <option value="value2">Description2</option>
  </select>

JSON Schema types array and object are stringified to be safely represented
as option keys.
parent 24729059
......@@ -122,6 +122,37 @@
return input;
}
function render_selection_oneof(json_field, default_value) {
var input = document.createElement("select"),
option = document.createElement("option"),
optionz;
input.size = 1;
option.value = "";
if (default_value === undefined) {
option.selected = "selected";
}
input.appendChild(option);
json_field.oneOf.forEach(function (element, index) {
if ((element['const'] !== undefined) && (element.title !== undefined)) {
var value;
if ((json_field.type == 'array') || (json_field.type == 'object')) {
// Support for unusual types
value = JSON.stringify(element['const']);
} else {
value = element['const'];
}
optionz = document.createElement("option");
optionz.value = value;
optionz.textContent = element.title;
if (value === default_value) {
optionz.selected = "selected";
}
input.appendChild(optionz);
}
});
return input;
}
function render_textarea(json_field, default_value, data_format) {
var input = document.createElement("textarea");
if (default_value !== undefined) {
......@@ -141,6 +172,10 @@
return render_selection(json_field, default_value);
}
if (json_field.oneOf !== undefined) {
return render_selection_oneof(json_field, default_value);
}
if (json_field.type === "boolean") {
json_field['enum'] = [true, false];
if (default_value === "true") {
......
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