[FIX] web_editor: properly allow to select a bg color for badges
Before this commit, the badges' background color was not possible to edit: the previews were done correctly but the background color was removed after final selection. This was because the background color property is animated on badges, messing with the related edition function. Closes https://github.com/odoo/odoo/issues/59337 closes odoo/odoo#60820 X-original-commit: 34238b77ace7e6feeb1f9e693d7cd3b12786505d Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
@@ -2038,6 +2038,14 @@ const SnippetOptionWidget = Widget.extend({
|
||||
* @returns {Promise|undefined}
|
||||
*/
|
||||
selectStyle: async function (previewMode, widgetValue, params) {
|
||||
// Disable all transitions for the duration of the method as many
|
||||
// comparisons will be done on the element to know if applying a
|
||||
// property has an effect or not. Also, changing a css property via the
|
||||
// editor should not show any transition as previews would not be done
|
||||
// immediately, which is not good for the user experience.
|
||||
this.$target[0].classList.add('o_we_force_no_transition');
|
||||
const _restoreTransitions = () => this.$target[0].classList.remove('o_we_force_no_transition');
|
||||
|
||||
if (params.cssProperty === 'background-color') {
|
||||
this.$target.trigger('background-color-event', previewMode);
|
||||
}
|
||||
@@ -2063,6 +2071,7 @@ const SnippetOptionWidget = Widget.extend({
|
||||
// Those are the special color combinations classes. Just have
|
||||
// to add it (and adding the potential extra class) then leave.
|
||||
this.$target[0].classList.add('o_cc', `o_cc${widgetValue}`, params.extraClass);
|
||||
_restoreTransitions();
|
||||
if (previewMode === false) await this.updateChangesInWysiwyg();
|
||||
return;
|
||||
}
|
||||
@@ -2075,6 +2084,7 @@ const SnippetOptionWidget = Widget.extend({
|
||||
// property we are editing, nothing more has to be done.
|
||||
// (except adding the extra class)
|
||||
this.$target.addClass(params.extraClass);
|
||||
_restoreTransitions();
|
||||
if (previewMode === false) await this.updateChangesInWysiwyg();
|
||||
return;
|
||||
}
|
||||
@@ -2132,6 +2142,7 @@ const SnippetOptionWidget = Widget.extend({
|
||||
this.$target.toggleClass(params.extraClass, hasUserValue);
|
||||
}
|
||||
|
||||
_restoreTransitions();
|
||||
if (previewMode === false) await this.updateChangesInWysiwyg();
|
||||
},
|
||||
|
||||
@@ -2425,6 +2436,12 @@ const SnippetOptionWidget = Widget.extend({
|
||||
}
|
||||
}
|
||||
|
||||
// Disable all transitions for the duration of the style check
|
||||
// as we want to know the final value of a property to properly
|
||||
// update the UI.
|
||||
this.$target[0].classList.add('o_we_force_no_transition');
|
||||
const _restoreTransitions = () => this.$target[0].classList.remove('o_we_force_no_transition');
|
||||
|
||||
const styles = window.getComputedStyle(this.$target[0]);
|
||||
const cssProps = weUtils.CSS_SHORTHANDS[params.cssProperty] || [params.cssProperty];
|
||||
const cssValues = cssProps.map(cssProp => {
|
||||
@@ -2447,6 +2464,9 @@ const SnippetOptionWidget = Widget.extend({
|
||||
if (cssValues.length === 2 && weUtils.areCssValuesEqual(cssValues[1], cssValues[0], params.cssProperty, this.$target)) {
|
||||
cssValues.pop();
|
||||
}
|
||||
|
||||
_restoreTransitions();
|
||||
|
||||
return cssValues.join(' ');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1998,3 +1998,11 @@ we-select.o_we_shape_menu {
|
||||
.o_main_sidebar:not(.o_loaded) #oe_snippets {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.o_we_force_no_transition {
|
||||
// Note: this is forced through a CSS class instead of inline style to avoid
|
||||
// overridding existing inline styles or forgetting to restore them as the
|
||||
// code evolves. We may need to increase the CSS priority of this. It will
|
||||
// also not work to override important inline style... this is a limitation.
|
||||
transition: none !important;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user