Commit b7a18928 authored by Boris Kocherov's avatar Boris Kocherov

add getGadgetByPath() and refactor getElementByPath() so use it

parent 5819ba7b
......@@ -682,6 +682,9 @@
.allowPublicAcquisition("checkValidity", function (arr) {
return this.checkValidity(arr[0]);
})
.declareMethod('getGadgetByPath', function (path) {
return this.props.form_gadget.getGadgetByPath(path || "/");
})
.declareMethod('checkValidity', function (json_document) {
// XXX need use local schema and local json document
// in every subgadget to take into account user anyOf choice
......
......@@ -1848,7 +1848,7 @@
});
})
.declareMethod('getElementByPath', function (data_path) {
.declareMethod('getGadgetByPath', function (data_path) {
var g = this,
array,
path,
......@@ -1878,7 +1878,7 @@
next_data_path = "/" + next_data_path.slice(1).join("/");
return g.getDeclaredGadget(array[idx].getAttribute('data-gadget-scope'))
.push(function (gadget) {
return gadget.getElementByPath(next_data_path);
return gadget.getGadgetByPath(next_data_path);
});
}
......@@ -1906,22 +1906,29 @@
if (scope === false) {
// gadget for this element absent
// so find element in current gadget
return document.getElementById(
g.element.getAttribute("data-gadget-scope") + bingo + key + '/'
);
return {
gadget: g,
path: bingo + key + '/'
};
}
if (scope) {
// get gadget by scope and use relative path for find element in gadget
return g.getDeclaredGadget(scope)
.push(function (gadget) {
return gadget.getElementByPath(next_data_path);
return gadget.getGadgetByPath(next_data_path);
});
}
}
return RSVP.Queue()
.push(function () {
return {
gadget: g,
path: data_path
};
})
.declareMethod('getElementByPath', function (data_path) {
return this.getGadgetByPath(data_path)
.push(function (ret) {
return document.getElementById(
g.element.getAttribute("data-gadget-scope") + data_path
ret.gadget.element.getAttribute("data-gadget-scope") + ret.path
);
});
})
......
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