[REF] web_editor: review left-panel unknown dependency behavior

Left panel widgets can define the widgets they depend on to be visible.
Up to now, if such a dependency was defined but that the related widget
was not found, the dependency was considered as not met. Now, it acts
as if that particular dependency was not defined at all.

This is useful for controlling the visibility of a generic option in the
case of a specific snippet without having to duplicate and restrict that
generic option.

E.g. There is a generic "color" option on all snippets. For my snippet
"hello" I only want that generic "color" option to be visible if my
"world" option is enabled. I then add `data-dependencies="world"` on the
generic "color" option. In the case, any other snippet than "hello" is
used, since the "world" option does not exist there, the "color" option
acts as if it had no dependency.

closes odoo/odoo#43511

Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2020-01-20 09:50:16 +00:00
parent 41be5fbcae
commit e927d1e89b
@@ -1742,7 +1742,8 @@ const SnippetOptionWidget = Widget.extend({
}
const dependencies = widget.getDependencies();
const dependenciesOK = !dependencies.length || dependencies.some(depName => {
const dependenciesData = [];
dependencies.forEach(depName => {
const toBeActive = (depName[0] !== '!');
if (!toBeActive) {
depName = depName.substr(1);
@@ -1753,7 +1754,15 @@ const SnippetOptionWidget = Widget.extend({
name: depName,
onSuccess: _widget => widget = _widget,
});
return widget && (widget.isActive() === toBeActive);
if (widget) {
dependenciesData.push({
widget: widget,
toBeActive: toBeActive,
});
}
});
const dependenciesOK = !dependenciesData.length || dependenciesData.some(depData => {
return (depData.widget.isActive() === depData.toBeActive);
});
widget.toggleVisibility(dependenciesOK);