Commit 186c60f4 authored by Boris Kocherov's avatar Boris Kocherov

disable preset schema.default

parent 48b4dabe
......@@ -21,11 +21,12 @@
});
}
function render_form(gadget, scope, schema) {
function render_form(gadget, scope, schema, value) {
return gadget.getDeclaredGadget(scope)
.push(function (g) {
return g.render({
schema: schema
schema: schema,
value: value
});
});
}
......@@ -42,9 +43,8 @@
function render_document_selection_form(gadget) {
return render_form(gadget, "document", {
default: gadget.props.documents[0],
enum: gadget.props.documents
});
}, gadget.props.documents[0]);
}
function updateTextContent(g) {
......@@ -107,9 +107,8 @@
return RSVP.all([
render_form(g, "schema", {
type: "string",
default: g.props.schemas[0],
enum: g.props.schemas
}),
}, g.props.schemas[0]),
render_document_selection_form(g)
]);
});
......
......@@ -121,7 +121,7 @@
return schema;
}
function render_enum(g, schema, json_document) {
function render_enum(schema, json_document) {
var input = document.createElement("select"),
option,
i,
......@@ -129,19 +129,12 @@
selected = false,
enum_arr = schema['enum'];
input.size = 1;
if (schema.default) {
if (json_document === undefined) {
json_document = 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 < enum_arr.length; i += 1) {
if (enum_arr.hasOwnProperty(i)) {
option = document.createElement("option");
......@@ -178,7 +171,7 @@
return input;
}
function render_enum_with_title(g, schema_arr, json_document, selected_schema) {
function render_enum_with_title(schema_arr, json_document, selected_schema) {
var input = document.createElement("select"),
option,
i,
......@@ -188,19 +181,12 @@
if (json_document === undefined && selected_schema !== undefined) {
json_document = selected_schema.schema.const;
}
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
......@@ -237,7 +223,7 @@
return input;
}
function render_boolean(g, schema, json_document) {
function render_boolean(json_document) {
var input,
schema_for_selection = {
type: "boolean",
......@@ -250,10 +236,7 @@
if (json_document === "false") {
json_document = false;
}
if (getDocumentType(schema.default) === "boolean") {
schema_for_selection.default = schema.default;
}
input = render_enum(g, schema_for_selection, json_document);
input = render_enum(schema_for_selection, json_document);
input.setAttribute('data-json-type', "boolean");
return input;
}
......@@ -698,29 +681,22 @@
var input,
is_items_arr = schema.items instanceof Array,
minItems = schema.minItems || 0;
if (schema.default === undefined &&
json_document === undefined) {
div_input.setAttribute("data-undefined", "true");
if (json_document instanceof Array &&
json_document.length === 0) {
div_input.setAttribute("data-json-empty-array", "true");
}
function element_append(child) {
if (child) {
input.parentNode.insertBefore(child, input);
div_input.removeAttribute("data-undefined");
div_input.removeAttribute("data-json-empty-array");
}
}
function div_append(child) {
if (child) {
div_input.appendChild(child);
div_input.removeAttribute("data-undefined");
}
}
if (json_document === undefined) {
if (schema.hasOwnProperty('default')) {
json_document = schema.default;
gadget.props.changed = true;
div_input.removeAttribute("data-json-empty-array");
}
}
......@@ -923,13 +899,13 @@
// render input begin
if (!input && schema_arr[0].is_arr_of_const && schema_arr.length > 1) {
input = render_enum_with_title(gadget, schema_arr, json_document, options.selected_schema);
input = render_enum_with_title(schema_arr, json_document, options.selected_schema);
}
if (!input && schema.const !== undefined) {
input = render_const(gadget, schema, json_document);
}
if (!input && schema.enum !== undefined) {
input = render_enum(gadget, schema, json_document);
input = render_enum(schema, json_document);
// XXX take in account existing type with enum
type_changed = false;
}
......@@ -939,7 +915,7 @@
}
if (!input && type === "boolean") {
input = render_boolean(gadget, schema, json_document);
input = render_boolean(json_document);
}
if (!input && ["string", "integer", "number", "null"].indexOf(type) >= 0) {
......@@ -956,10 +932,6 @@
}
if (type === "integer" || type === "number") {
if (json_document === undefined && typeof schema.default === "number") {
input.value = schema.default;
gadget.props.changed = true;
}
input.setAttribute("data-json-type", type);
if (json_document === undefined || json_document === null ||
typeof json_document === "number") {
......@@ -991,10 +963,6 @@
input.max = schema.maximum;
}
} else {
if (json_document === undefined && typeof schema.default === "string") {
input.value = schema.default;
gadget.props.changed = true;
}
input.type = "text";
if (schema.pattern) {
input.pattern = schema.pattern;
......@@ -1012,10 +980,6 @@
}
}
}
if (schema.default !== undefined) {
input.setAttribute('data-default-value', JSON.stringify(schema.default));
input.placeholder = schema.default;
}
}
// render input end
......@@ -1326,19 +1290,9 @@
root.appendChild(child);
}
if (JSON.stringify(schema.default) === '{}') {
// save default value as attribute only for empty values
root.parentElement.setAttribute("data-default-value", '{}');
}
if (json_document === undefined) {
if (schema.hasOwnProperty('default')) {
json_document = schema.default;
g.props.changed = true;
} else {
json_document = {};
}
}
return expandProperties(g, schema.properties, schema_path + '/properties/', required)
.push(function (ret) {
......@@ -1601,9 +1555,6 @@
g.element.getAttribute("data-gadget-scope") + "']");
for (i = 0; i < array.length; i += 1) {
path = array[i].getAttribute("data-json-path").slice(0, -1);
if (array[i].getAttribute("data-default-value") === "{}") {
convertOnMultiLevel(multi_level_dict, path, {});
}
}
for (path in options.arrays) {
......@@ -1612,7 +1563,7 @@
.querySelectorAll("div[data-gadget-parent-scope='" + g.element.getAttribute("data-gadget-scope") + "']");
len = array.length;
if (len === 0 &&
!options.arrays[path].hasAttribute('data-undefined')) {
options.arrays[path].hasAttribute('data-json-empty-array')) {
convertOnMultiLevel(multi_level_dict, path.slice(0, -1), []);
}
for (i = 0; i < len; i = i + 1) {
......@@ -1670,8 +1621,6 @@
} else {
json_dict[input.name] = input.value;
}
} else if (input.hasAttribute('data-default-value')) {
json_dict[input.name] = JSON.parse(input.getAttribute('data-default-value'));
}
}
});
......
......@@ -134,12 +134,6 @@
"allOf with base schema: mismatch second allOf": {
invert_valid: true,
changed: true
},
// schema.default used for field if field undefined so json_document changed after
// render() and valid status inverted
"invalid string value for default: still valid when the invalid default is used": {
invert_valid: true,
changed: true
}
};
......
......@@ -26,11 +26,12 @@
});
}
function render_form(gadget, scope, schema) {
function render_form(gadget, scope, schema, value) {
return gadget.getDeclaredGadget(scope)
.push(function (g) {
return g.render({
schema: schema
schema: schema,
value: value
});
});
}
......@@ -101,6 +102,7 @@
m,
schema,
t;
g.props.schemas.push("");
for (i = 0; i < list.length; i += 1) {
for (k = 0; k < list[i].length; k += 1) {
m = list[i][k];
......@@ -131,9 +133,8 @@
return RSVP.all([
render_form(g, "schema", {
type: "string",
default: g.props.schemas[0],
enum: g.props.schemas
})
}, g.props.schemas[0])
]);
});
})
......
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