Commit 077403f5 authored by Boris Kocherov's avatar Boris Kocherov

add render_enum_with_title()

parent eca3154f
......@@ -584,18 +584,7 @@
});
};
function expandSchemaForField(g, schema, schema_path, for_required) {
var required_stack,
prev_field_path;
if (for_required) {
prev_field_path = getMaxPathInDict(g.props.schema_required_urls, schema_path);
required_stack = g.props.schema_required_urls[prev_field_path];
} else {
required_stack = [];
}
g.props.schema_required_urls[schema_path] = required_stack;
return expandSchema(g, schema, schema_path)
.push(function (schema_arr) {
function schema_arr_marker(schema_arr) {
var i;
for (i = 0; i < schema_arr.length; i += 1) {
if (!schema_arr[i].schema.hasOwnProperty('const')) {
......@@ -607,7 +596,20 @@
}
}
return schema_arr;
});
}
function expandSchemaForField(g, schema, schema_path, for_required) {
var required_stack,
prev_field_path;
if (for_required) {
prev_field_path = getMaxPathInDict(g.props.schema_required_urls, schema_path);
required_stack = g.props.schema_required_urls[prev_field_path];
} else {
required_stack = [];
}
g.props.schema_required_urls[schema_path] = required_stack;
return expandSchema(g, schema, schema_path)
.push(schema_arr_marker);
}
rJS(window)
......@@ -821,7 +823,8 @@
schema_url = g.state.schema_url ||
(json_document && json_document.$schema);
if (schema_url) {
queue = loadJSONSchema(g, schema_url);
queue = loadJSONSchema(g, schema_url)
.push(schema_arr_marker);
}
}
if (queue) {
......
......@@ -178,6 +178,62 @@
return input;
}
function render_enum_with_title(g, schema_arr, json_document) {
var input = document.createElement("select"),
option,
i,
ser_value,
selected = false;
input.size = 1;
if (schema_arr[0].schema.default) {
if (json_document === undefined) {
json_document = schema_arr[0].schema.default;
g.props.changed = true;
}
} else {
option = document.createElement("option");
option.value = "";
if (json_document === undefined) {
option.selected = true;
}
input.appendChild(option);
}
for (i = 0; i < schema_arr.length; i += 1) {
option = document.createElement("option");
// XXX use number id for speedup
ser_value = JSON.stringify(schema_arr[i].schema.const);
option.value = ser_value;
if (schema_arr[i].schema.title) {
option.textContent = schema_arr[i].schema.title;
} else if (typeof schema_arr[i].schema.const === "string") {
option.textContent = schema_arr[i].schema.const;
} else {
option.textContent = ser_value;
}
if (deepEqual(schema_arr[i].schema.const, json_document)) {
option.selected = true;
selected = true;
}
input.appendChild(option);
}
if (json_document !== undefined && !selected) {
// save original json_document even if it
// not support with schema
// XXX element should be removed on first user interact
option = document.createElement("option");
ser_value = JSON.stringify(json_document);
option.value = ser_value;
if (typeof json_document === "string") {
option.textContent = json_document;
} else {
option.textContent = ser_value;
}
option.selected = true;
input.appendChild(option);
}
return input;
}
function render_boolean(g, schema, json_document) {
var input,
schema_for_selection = {
......@@ -890,9 +946,15 @@
div_input.setAttribute("id", gadget.element.getAttribute("data-gadget-scope") + first_path + '/');
div_input.setAttribute("class", "input");
if (schema.const !== undefined) {
// render input begin
if (!input && schema_arr[0].is_arr_of_const) {
input = render_enum_with_title(gadget, schema_arr, json_document);
}
if (!input && schema.const !== undefined) {
input = render_const(gadget, schema, json_document);
} else if (schema.enum !== undefined) {
}
if (!input && schema.enum !== undefined) {
input = render_enum(gadget, schema, json_document);
// XXX take in account existing type with enum
type_changed = false;
......@@ -1020,6 +1082,8 @@
div.setAttribute("data-json-type", type);
}
// render input end
if (schema.info !== undefined) {
span_info = document.createElement("span");
span_info.textContent = schema.info;
......
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