[FIX] website: not save the "bg-" class as a cover properties value

Since [1], when editing a cover, if no "bg-X" class was selected (like
only selecting a "o_ccX"), the broken "bg-" class was saved. It had no
effect but better not accumulate non-existing classes as database
values.

However, fixing this bug actually reveals code inconsistency... which
creates other bugs. Some code were preventing to reset the color class
value. All that code apparently became useless since [2] as explained
in details at [3].

[1]: https://github.com/odoo/odoo/commit/ad59cbd33e0eaf5c7c77f9e5c0b0435917e2c155
[2]: https://github.com/odoo/odoo/commit/e1632434378fd9b550274c2f40261ad48fb77e6d
[3]: https://github.com/odoo/odoo/pull/87206#issuecomment-1088619834

Discovered with task-2792006

closes odoo/odoo#88482

X-original-commit: 35ac2fa584fa7304015a9b44573622cb820d390a
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
qsm-odoo
2022-04-11 19:02:02 +02:00
parent 65ee7ed131
commit 3c82e624e3
@@ -2651,9 +2651,7 @@ options.registry.CoverProperties = options.Class.extend({
*/
_updateColorDataset(bgColorStyle = '', bgColorClass = '') {
this.$target[0].dataset.bgColorStyle = bgColorStyle;
if (bgColorClass) {
this.$target[0].dataset.bgColorClass = bgColorClass;
}
this.$target[0].dataset.bgColorClass = bgColorClass;
},
/**
* Updates the cover properties dataset used for saving.
@@ -2662,15 +2660,6 @@ options.registry.CoverProperties = options.Class.extend({
*/
_updateSavingDataset(colorValue) {
const [colorPickerWidget, sizeWidget, textAlignWidget] = this._requestUserValueWidgets('bg_color_opt', 'size_opt', 'text_align_opt');
if (!colorPickerWidget) {
// Saving without closing the color palette, but the last picked
// color was already taken into account (we still need to update the
// dataset when a custom color is selected).
if (colorValue) {
this._updateColorDataset(`background-color: ${colorValue};`);
}
return;
}
// TODO: `o_record_has_cover` should be handled using model field, not
// resize_class to avoid all of this.
// Get values from DOM (selected values in options are only available
@@ -2703,7 +2692,7 @@ options.registry.CoverProperties = options.Class.extend({
if (ccValue) {
colorNames.push(ccValue);
}
if (!isGradient && !isCSSColor) {
if (colorOrGradient && !isGradient && !isCSSColor) {
colorNames.push(colorOrGradient);
}
const bgColorClass = weUtils.computeColorClasses(colorNames).join(' ');