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