Commit cbf9ccf6 authored by Boris Kocherov's avatar Boris Kocherov

button for remove additionalProperties/arrayItems/paternProperties added

parent 0df2f3ed
...@@ -79,7 +79,7 @@ Below is the list of JSON Schema validation properties and current supported sta ...@@ -79,7 +79,7 @@ Below is the list of JSON Schema validation properties and current supported sta
- rendering is not supported - rendering is not supported
* `patternProperties` * `patternProperties`
- **fixed** values can be only `object` types - **fixed** values can be only `object` types
- add buttons for remove existed `patternProperties` - **done** add buttons for remove existed `patternProperties`
- **fixed** can not be mixed with `properties` - **fixed** can not be mixed with `properties`
- only regex .* in keys is supported - only regex .* in keys is supported
* `properties` * `properties`
......
...@@ -435,22 +435,14 @@ ...@@ -435,22 +435,14 @@
return g.declareGadget('gadget_json_generated_form.html', {scope: scope}) return g.declareGadget('gadget_json_generated_form.html', {scope: scope})
.push(function (form_gadget) { .push(function (form_gadget) {
var div = document.createElement("div");
form_gadget.element.setAttribute("data-json-parent", parent_path); form_gadget.element.setAttribute("data-json-parent", parent_path);
if (options.parent_type === "array") { if (options.parent_type === "array") {
g.props.arrays[parent_path] = 1; g.props.arrays[parent_path] = 1;
} else { } else {
g.props.subforms[scope] = form_gadget; g.props.subforms[scope] = form_gadget;
} }
div.setAttribute("class", "slapos-parameter-dict-key");
div.appendChild(form_gadget.element);
// add after button
// element.parentNode.parentNode.insertBefore(div, element.parentNode.parentNode.children[1]);
// add to end of list // add to end of list
element.parentNode.appendChild(div); element.parentNode.appendChild(form_gadget.element);
return form_gadget.renderForm({ return form_gadget.renderForm({
schema: options.schema_part, schema: options.schema_part,
document: options.default_dict, document: options.default_dict,
...@@ -476,6 +468,23 @@ ...@@ -476,6 +468,23 @@
}); });
}) })
.declareAcquiredMethod("deleteChildrenParent", "deleteChildren")
.allowPublicAcquisition("deleteChildren", function (scope) {
var arrays = this.props.arrays,
subforms = this.props.subforms,
element = this.element.querySelector("div[data-gadget-scope='" + scope + "']");
if (!arrays.hasOwnProperty(element.getAttribute('data-json-parent'))) {
if (subforms.hasOwnProperty(scope)) {
delete subforms[scope].element;
delete subforms[scope];
}
}
element.parentNode.removeChild(element);
})
.declareMethod("selfRemove", function () {
return this.deleteChildrenParent(this.element.getAttribute('data-gadget-scope'));
})
.declareAcquiredMethod("processValidationParent", "processValidation") .declareAcquiredMethod("processValidationParent", "processValidation")
.allowPublicAcquisition("processValidation", function (json_dict) { .allowPublicAcquisition("processValidation", function (json_dict) {
return this.processValidation(undefined, json_dict); return this.processValidation(undefined, json_dict);
...@@ -548,7 +557,8 @@ ...@@ -548,7 +557,8 @@
.declareMethod('renderForm', function (options) { .declareMethod('renderForm', function (options) {
var g = this, var g = this,
key = options.key, key = options.key,
schema = options.schema; schema = options.schema,
delete_button;
g.props.inputs = []; g.props.inputs = [];
g.props.add_buttons = []; g.props.add_buttons = [];
g.props.arrays = {}; g.props.arrays = {};
...@@ -566,6 +576,14 @@ ...@@ -566,6 +576,14 @@
while (g.element.firstChild) { while (g.element.firstChild) {
g.element.removeChild(g.element.firstChild); g.element.removeChild(g.element.firstChild);
} }
if (!g.props.toplevel) {
delete_button = document.createElement("button");
delete_button.type = "button";
delete_button.name = options.path;
delete_button.textContent = "Delete";
g.props.delete_button = delete_button;
g.element.appendChild(delete_button);
}
return render_field(g, key, "", schema, options.document, g.element) return render_field(g, key, "", schema, options.document, g.element)
.push(function () { .push(function () {
g.listenEvents(); g.listenEvents();
...@@ -576,6 +594,7 @@ ...@@ -576,6 +594,7 @@
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var g = this, var g = this,
queue; queue;
g.props.toplevel = true;
g.options = options; g.options = options;
if (!options.value) { if (!options.value) {
options.value = {}; options.value = {};
...@@ -610,6 +629,15 @@ ...@@ -610,6 +629,15 @@
i, i,
promise_list = []; promise_list = [];
if (g.props.delete_button) {
promise_list.push(loopEventListener(
g.props.delete_button,
'click',
false,
g.selfRemove.bind(g)
));
}
for (i = 0; i < field_list.length; i = i + 1) { for (i = 0; i < field_list.length; i = i + 1) {
promise_list.push(loopEventListener( promise_list.push(loopEventListener(
field_list[i], field_list[i],
......
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