diff options
| author | qsm-odoo <qsm@odoo.com> | 2020-01-17 17:37:25 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2020-01-20 09:50:16 +0000 |
| commit | e927d1e89bc124002bb5e0b69dee711ea0d8147c (patch) | |
| tree | f14731ed9abdc35a74391903f61bf8840139a591 | |
| parent | 41be5fbcae7bef0a7a622959c0521b2428706038 (diff) | |
[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>
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.options.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 53a36008a56..fc27456f3b2 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -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); |
