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

disable preset schema.default

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