Commit a00855c7 authored by Boris Kocherov's avatar Boris Kocherov

split renderForm() and rerender()

parent b7a18928
......@@ -1952,23 +1952,13 @@
.declareMethod('renderForm', function (options) {
var g = this,
property_name = g.element.getAttribute('data-json-property-name'),
schema = options.schema_arr !== undefined && options.schema_arr[0].schema,
root;
schema = options.schema_arr !== undefined && options.schema_arr[0].schema;
g.props.changed = false;
g.props.saveOrigValue = options.saveOrigValue;
g.props.inputs = [];
g.props.add_buttons = [];
g.props.add_custom_data = {};
g.props.arrays = {};
g.props.objects = {};
g.props.path = options.path; // self gadget scope
if (!property_name || !options.display_label) {
property_name = "";
}
root = g.element.querySelector('[data-json-path="/"]');
if (!root) {
root = g.element;
}
if (options.delete_button === undefined) {
if (options.top) {
options.delete_button = false;
......@@ -1982,23 +1972,41 @@
// used for empty document generation
g.props.type = (schema && typeof schema.type === "string" && schema.type) ||
options.type || getDocumentType(options.document);
while (root.firstChild) {
root.removeChild(root.firstChild);
}
if (checkSchemaIsMetaSchema(schema)) {
g.props.updatePropertySelectors = true;
g.props.current_document = options.document;
}
return render_field(g, property_name, "", options.schema_arr,
options.document, root,
{
type: options.type,
selected_schema: options.selected_schema,
required: options.required,
delete_button: options.delete_button,
top: options.top
})
g.props.property_name = property_name;
g.props.schema_arr = options.schema_arr;
g.props.render_opt = {
type: options.type,
selected_schema: options.selected_schema,
required: options.required,
delete_button: options.delete_button,
top: options.top
};
return g.rerender(options.document);
})
.declareMethod('rerender', function (document) {
var g = this,
for_delete,
root = g.element.querySelector('[data-json-path="/"]');
g.props.inputs = [];
g.props.add_buttons = [];
g.props.add_custom_data = {};
g.props.arrays = {};
g.props.objects = {};
if (!root) {
root = g.element;
}
for_delete = Array.from(root.childNodes);
return render_field(g, g.props.property_name, "", g.props.schema_arr,
document, root, g.props.render_opt)
.push(function () {
for (var i = 0; i < for_delete.length; i += 1) {
root.removeChild(for_delete[i]);
}
return g.element;
});
})
......
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