Commit 634dda81 authored by Boris Kocherov's avatar Boris Kocherov

notifyChange() now send action, scope and path changed subgadget

parent a9ac5818
...@@ -687,8 +687,13 @@ ...@@ -687,8 +687,13 @@
gadget.props.add_buttons.push({ gadget.props.add_buttons.push({
element: input, element: input,
event: function () { event: function () {
var notify = {
action: "add"
};
return event(schema_alternatives[0].value) return event(schema_alternatives[0].value)
.push(function () { .push(function (v) {
notify.scope = v.scope;
notify.path = v.path;
if (rerender) { if (rerender) {
return rerender(undefined, schema_alternatives); return rerender(undefined, schema_alternatives);
} }
...@@ -700,9 +705,7 @@ ...@@ -700,9 +705,7 @@
} else { } else {
input.removeAttribute("style"); input.removeAttribute("style");
} }
// XXX need path argument return gadget.rootNotifyChange(notify);
// absent in current context
return gadget.rootNotifyChange();
}); });
}, },
rerender: function () { rerender: function () {
...@@ -732,8 +735,23 @@ ...@@ -732,8 +735,23 @@
}); });
} }
function get_scope_path_from_element(gadget, element) {
var scope = element.getAttribute("data-gadget-scope");
return gadget.getDeclaredGadget(scope)
.push(function (g) {
return g.getJsonPath();
})
.push(function (path) {
return {
scope: scope,
path: path
};
});
}
function render_array(gadget, schema, json_document, div_input, path, schema_path) { function render_array(gadget, schema, json_document, div_input, path, schema_path) {
var input, var input,
array_path,
is_items_arr = schema.items instanceof Array, is_items_arr = schema.items instanceof Array,
minItems = schema.minItems || 0; minItems = schema.minItems || 0;
if (json_document instanceof Array && if (json_document instanceof Array &&
...@@ -741,10 +759,36 @@ ...@@ -741,10 +759,36 @@
div_input.setAttribute("data-json-empty-array", "true"); div_input.setAttribute("data-json-empty-array", "true");
} }
function current_array_length() {
var array = div_input
.querySelectorAll("div[data-gadget-parent-scope='" +
gadget.element.getAttribute("data-gadget-scope") +
"']");
return array.length;
}
function add_item_form(id, required) {
return function (value) {
return gadget.expandSchema(schema.items, schema_path + '/items', array_path + id, required)
.push(function (s_arr) {
return addSubForm({
gadget: gadget,
parent_type: 'array',
parent_path: path,
type: value && value.schema.type,
selected_schema: value,
schema_arr: s_arr,
required: required
});
});
};
}
function element_append(child) { function element_append(child) {
if (child) { if (child) {
input.parentNode.insertBefore(child, input); input.parentNode.insertBefore(child, input);
div_input.removeAttribute("data-json-empty-array"); div_input.removeAttribute("data-json-empty-array");
return get_scope_path_from_element(gadget, child);
} }
} }
...@@ -759,6 +803,7 @@ ...@@ -759,6 +803,7 @@
// input = render_textarea(schema, default_value, "array"); // input = render_textarea(schema, default_value, "array");
return gadget.getJsonPath(path) return gadget.getJsonPath(path)
.push(function (p) { .push(function (p) {
array_path = p;
return RSVP.all([ return RSVP.all([
expandItems(gadget, schema.items, schema_path + '/items', p, minItems), expandItems(gadget, schema.items, schema_path + '/items', p, minItems),
gadget.expandSchema(schema.additionalItems, schema_path + '/additionalItems', p, false) gadget.expandSchema(schema.additionalItems, schema_path + '/additionalItems', p, false)
...@@ -842,17 +887,9 @@ ...@@ -842,17 +887,9 @@
})); }));
} else { } else {
if (minItems > len && checkSchemaArrOneChoise(schema_arr)) { if (minItems > len && checkSchemaArrOneChoise(schema_arr)) {
for (i = 0; i < (minItems - len); i += 1) { for (i = len; i < minItems; i += 1) {
queue queue
.push( .push(add_item_form(i, true))
addSubForm.bind(gadget, {
gadget: gadget,
parent_type: 'array',
parent_path: path,
schema_arr: schema_arr,
required: true
})
)
.push(div_append); .push(div_append);
} }
} }
...@@ -860,14 +897,7 @@ ...@@ -860,14 +897,7 @@
queue.push(render_schema_selector.bind(gadget, queue.push(render_schema_selector.bind(gadget,
gadget, "add item to array", gadget, "add item to array",
schema_arr, function (value) { schema_arr, function (value) {
return addSubForm({ return add_item_form(current_array_length(), false)(value)
gadget: gadget,
parent_type: 'array',
parent_path: path,
type: value.type,
selected_schema: value,
schema_arr: schema_arr
})
.push(element_append); .push(element_append);
})); }));
} }
...@@ -1354,6 +1384,7 @@ ...@@ -1354,6 +1384,7 @@
if (child) { if (child) {
// insert additionalProperty before selector // insert additionalProperty before selector
selector.element.parentNode.insertBefore(child, selector.element); selector.element.parentNode.insertBefore(child, selector.element);
return get_scope_path_from_element(g, child);
} }
} }
...@@ -1756,15 +1787,16 @@ ...@@ -1756,15 +1787,16 @@
g.options = {}; g.options = {};
}) })
.declareAcquiredMethod("rNotifyChange", "rootNotifyChange") .declareAcquiredMethod("rNotifyChange", "rootNotifyChange")
.declareMethod("rootNotifyChange", function (path) { .declareMethod("rootNotifyChange", function (v) {
var g = this; var g = this;
this.props.needValidate = true; this.props.needValidate = true;
return g.getJsonPath(path) return g.getJsonPath(v.path)
.push(function (p) { .push(function (p) {
return g.rNotifyChange({ return g.rNotifyChange({
scope: g.element.getAttribute("data-gadget-scope"), scope: v.scope || g.element.getAttribute("data-gadget-scope"),
rel_path: path, rel_path: v.path,
path: p path: p,
action: v.action
}); });
}); });
}) })
...@@ -1784,7 +1816,10 @@ ...@@ -1784,7 +1816,10 @@
return RSVP.all(tasks); return RSVP.all(tasks);
}) })
.push(function () { .push(function () {
return g.deleteChildren(); return g.getJsonPath();
})
.push(function (path) {
return g.deleteChildren(path);
}); });
}) })
.declareAcquiredMethod("deleteChildren", "deleteChildren") .declareAcquiredMethod("deleteChildren", "deleteChildren")
...@@ -1792,6 +1827,7 @@ ...@@ -1792,6 +1827,7 @@
var g = this, var g = this,
key, key,
i, i,
path = arr[0],
button_list = this.props.add_buttons, button_list = this.props.add_buttons,
objects = this.props.objects, objects = this.props.objects,
element = getSubGadgetElement(g, scope), element = getSubGadgetElement(g, scope),
...@@ -1818,7 +1854,11 @@ ...@@ -1818,7 +1854,11 @@
return RSVP.all(tasks); return RSVP.all(tasks);
}) })
.push(function () { .push(function () {
return g.rootNotifyChange(); return g.rootNotifyChange({
scope: scope,
path: path,
action: "delete"
});
}) })
.push(function () { .push(function () {
// remove gadget at end otherwise // remove gadget at end otherwise
...@@ -1981,7 +2021,9 @@ ...@@ -1981,7 +2021,9 @@
if (event_object && evt.type === "change") { if (event_object && evt.type === "change") {
return event_object.event(); return event_object.event();
} }
return g.rootNotifyChange(evt.target.name); return g.rootNotifyChange({
path: evt.target.name
});
}) })
.declareMethod('renderForm', function (options) { .declareMethod('renderForm', function (options) {
var g = this, var g = this,
...@@ -2238,7 +2280,9 @@ ...@@ -2238,7 +2280,9 @@
} }
} }
if (changed) { if (changed) {
return gadget.rootNotifyChange(input.name); return gadget.rootNotifyChange({
path: input.name
});
} }
}) })
......
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