Commit b920a106 authored by Boris Kocherov's avatar Boris Kocherov

render all fields unrequired too. simple mark schema as circular.

parent 033e144f
...@@ -149,8 +149,9 @@ ...@@ -149,8 +149,9 @@
} }
} }
function loadJSONSchema(g, url, path) { function loadJSONSchema(g, $ref, path) {
var protocol, var protocol,
url,
download_url, download_url,
hash, hash,
schema_url_map; schema_url_map;
...@@ -158,7 +159,7 @@ ...@@ -158,7 +159,7 @@
if (!path) { if (!path) {
path = "/"; path = "/";
} }
url = convertUrlToAbsolute(g, path, url, window.location); url = convertUrlToAbsolute(g, path, $ref, window.location);
download_url = url.origin + url.pathname; download_url = url.origin + url.pathname;
schema_url_map = { schema_url_map = {
"http://json-schema.org/draft-04/schema": "json-schema/schema4.json", "http://json-schema.org/draft-04/schema": "json-schema/schema4.json",
...@@ -219,7 +220,16 @@ ...@@ -219,7 +220,16 @@
} }
schemaPushSchemaPart(g.props.schema, path, JSON.parse(JSON.stringify(schema_part))); schemaPushSchemaPart(g.props.schema, path, JSON.parse(JSON.stringify(schema_part)));
// console.log(g.props.schema[""]); // console.log(g.props.schema[""]);
return schema_part; return expandSchema(g, schema_part, path, $ref);
})
.push(function (schema_arr) {
// if length array > 1 form rendered on demand already
// so not needed circular detection
if (schema_arr.length === 1) {
// XXX need smart circular detection in this place
schema_arr[0].circular = true;
}
return schema_arr;
}); });
} }
...@@ -308,7 +318,7 @@ ...@@ -308,7 +318,7 @@
for (i = 0; i < arr.length; i += 1) { for (i = 0; i < arr.length; i += 1) {
for (z = 0; z < arr[i].length; z += 1) { for (z = 0; z < arr[i].length; z += 1) {
if (arr[i][z].schema === true) { if (arr[i][z].schema === true) {
// or(any, restricted, restricted) simplify to any // or(any, restricted, restricted, .. ) simplify to any
return [arr[i][z]]; return [arr[i][z]];
} }
schema_arr.push(arr[i][z]); schema_arr.push(arr[i][z]);
...@@ -332,10 +342,7 @@ ...@@ -332,10 +342,7 @@
return allOf(g, schema.allOf, schema_path); return allOf(g, schema.allOf, schema_path);
} }
if (schema.$ref) { if (schema.$ref) {
return loadJSONSchema(g, schema.$ref, schema_path) return loadJSONSchema(g, schema.$ref, schema_path);
.push(function (schema_part) {
return expandSchema(g, schema_part, schema_path, schema.$ref);
});
} }
return RSVP.Queue() return RSVP.Queue()
.push(function () { .push(function () {
...@@ -527,7 +534,10 @@ ...@@ -527,7 +534,10 @@
var schema_url = options.schema_url || var schema_url = options.schema_url ||
(options.value && options.value.$schema); (options.value && options.value.$schema);
if (schema_url) { if (schema_url) {
return loadJSONSchema(g, schema_url); return loadJSONSchema(g, schema_url)
.push(function (schema_arr) {
return schema_arr[0].schema;
});
} }
return {}; return {};
}) })
......
...@@ -144,6 +144,7 @@ ...@@ -144,6 +144,7 @@
return form_gadget.renderForm({ return form_gadget.renderForm({
type: options.type, type: options.type,
required: options.required, required: options.required,
delete_button: options.delete_button,
schema: options.schema_part, schema: options.schema_part,
schema_path: options.schema_path, schema_path: options.schema_path,
document: options.default_dict, document: options.default_dict,
...@@ -615,7 +616,7 @@ ...@@ -615,7 +616,7 @@
div.setAttribute("class", "jsonformfield ui-field-contain"); div.setAttribute("class", "jsonformfield ui-field-contain");
div.title = json_field.description; div.title = json_field.description;
// if (key && !first_path) { // if (key && !first_path) {
if (options.required !== true) { if (options.delete_button === true) {
delete_button = document.createElement("span"); delete_button = document.createElement("span");
delete_button.setAttribute("class", delete_button.setAttribute("class",
"ui-shadow-inset ui-btn ui-btn-inline ui-corner-all" + "ui-shadow-inset ui-btn ui-btn-inline ui-corner-all" +
...@@ -623,11 +624,18 @@ ...@@ -623,11 +624,18 @@
gadget.props.delete_button = delete_button; gadget.props.delete_button = delete_button;
div.appendChild(delete_button); div.appendChild(delete_button);
} else if (options.top !== true) { } else if (options.top !== true) {
delete_button = document.createElement("span"); if (options.required) {
delete_button.setAttribute("class", delete_button = document.createElement("span");
"ui-shadow-inset ui-btn ui-btn-inline ui-corner-all" + delete_button.setAttribute("class",
" ui-btn-icon-top ui-icon-btn ui-icon-circle"); "ui-shadow-inset ui-btn ui-btn-inline ui-corner-all" +
div.appendChild(delete_button); " ui-btn-icon-top ui-icon-btn ui-icon-circle");
div.appendChild(delete_button);
} else {
delete_button = document.createElement("span");
delete_button.innerHTML = "&emsp;";
div.appendChild(delete_button);
}
} }
if (false) { if (false) {
// XXX; // XXX;
...@@ -856,20 +864,27 @@ ...@@ -856,20 +864,27 @@
if (properties.hasOwnProperty(key)) { if (properties.hasOwnProperty(key)) {
schema_arr = properties[key]; schema_arr = properties[key];
s_o = schemaArrFilteredByDocument(schema_arr, default_dict[key]); s_o = schemaArrFilteredByDocument(schema_arr, default_dict[key]);
if (required.indexOf(key) >= 0 && checkSchemaArrOneChoise(schema_arr)) { if (checkSchemaArrOneChoise(schema_arr)) {
used_properties[key] = false; if (required.indexOf(key) >= 0) {
q.push(render_field.bind(g, g, key, path, used_properties[key] = false;
s_o.schema, default_dict[key], root, s_o.schema_path, {required: true}) q.push(render_field.bind(g, g, key, path,
); s_o.schema, default_dict[key], root, s_o.schema_path, {required: true})
);
}
if (!used_properties.hasOwnProperty(key) &&
!schema_editor &&
(checkSchemaSimpleType(s_o.schema) || !s_o.circular)
) {
used_properties[key] = false;
q.push(render_field.bind(g, g, key, path,
s_o.schema, default_dict[key], root, s_o.schema_path, {
required: false,
delete_button: false
}));
}
} }
if (!used_properties.hasOwnProperty(key) && if (!used_properties.hasOwnProperty(key) &&
(default_dict.hasOwnProperty(key) || default_dict.hasOwnProperty(key)) {
(!schema_editor &&
checkSchemaArrOneChoise(schema_arr) &&
s_o.schema &&
checkSchemaSimpleType(s_o.schema)
)
)) {
used_properties[key] = ""; used_properties[key] = "";
q.push( q.push(
addSubForm.bind(g, { addSubForm.bind(g, {
...@@ -1338,6 +1353,13 @@ ...@@ -1338,6 +1353,13 @@
if (!root) { if (!root) {
root = g.element; root = g.element;
} }
if (options.delete_button === undefined) {
if (options.top) {
options.delete_button = false;
} else {
options.delete_button = !options.required;
}
}
while (root.firstChild) { while (root.firstChild) {
root.removeChild(root.firstChild); root.removeChild(root.firstChild);
} }
...@@ -1346,6 +1368,7 @@ ...@@ -1346,6 +1368,7 @@
{ {
type: options.type, type: options.type,
required: options.required, required: options.required,
delete_button: options.delete_button,
top: options.top top: options.top
}) })
.push(function () { .push(function () {
......
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