Commit a00855c7 authored by Boris Kocherov's avatar Boris Kocherov

split renderForm() and rerender()

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