From e927d1e89bc124002bb5e0b69dee711ea0d8147c Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Fri, 17 Jan 2020 17:37:25 +0000 Subject: [PATCH] [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) --- .../static/src/js/editor/snippets.options.js | 13 +++++++++++-- 1 file 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);