Skip to content

Commit 8f4b4bc

Browse files
thjo-odooabd-msyukyu-odoo
authored andcommitted
[FIX] mass_mailing_egg: TO DISCUSS set variable based on design-themes v1
1 parent be8cc87 commit 8f4b4bc

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

addons/mass_mailing_egg/static/src/builder/plugins/customize_mailing_plugin.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ export class CustomizeMailingPlugin extends Plugin {
109109
if (currentValue === "" && defaultValue !== "") {
110110
varRule.style.setProperty(variable, defaultValue);
111111
}
112-
this.refreshMailingVariableSelector(variable);
112+
this.refreshMailingVariableSelector(variable, true);
113113
}
114114
}
115115

116-
refreshMailingVariableSelector(variable) {
116+
refreshMailingVariableSelector(variable, isSetup = false) {
117117
const options = CUSTOMIZE_MAILING_VARIABLES[variable];
118118
const currentValue = this.getVariableValue(variable);
119119
let value = "";
@@ -124,11 +124,37 @@ export class CustomizeMailingPlugin extends Plugin {
124124
const rule = this.getRule(selector);
125125
for (const property of options.properties) {
126126
const important = PRIORITY_STYLES[selector]?.has(property) ? "important" : "";
127-
rule.style.setProperty(property, value, important);
127+
if (isSetup && rule.style.getPropertyValue(property)) {
128+
this.setVariable(variable, rule.style.getPropertyValue(property))
129+
} else {
130+
rule.style.setProperty(property, value, important);
131+
}
128132
}
129133
}
130134
}
131135

136+
getVariableName(selector, property) {
137+
let prefix = "text";
138+
if (selector.includes("h1")) {
139+
prefix = "h1";
140+
} else if (selector.includes("h2")) {
141+
prefix = "h2";
142+
} else if (selector.includes("h3")) {
143+
prefix = "h3";
144+
} else if (/((\bp\b)|(\bp > \*)|(\bli\b)|(\bli > \*))/.test(selector)) {
145+
prefix = "text";
146+
} else if (/(a\..*\.btn\-.*\-?primary)/.test(selector)) {
147+
prefix = "btn-primary";
148+
} else if (/(a\..*\.btn\-.*\-?secondary)/.test(selector)) {
149+
prefix = "btn-secondary";
150+
} else if (/((a:not\(\.btn\))|(a\.btn\.btn\-link))/.test(selector)) {
151+
prefix = "link";
152+
} else if (/hr/.test(selector)) {
153+
prefix = "separator"
154+
}
155+
return `--${prefix}-${property}`;
156+
}
157+
132158
parseDesignElement(styleEl) {
133159
const rules = [...styleEl.sheet.cssRules];
134160
for (const rule of rules) {
@@ -208,6 +234,8 @@ export class CustomizeMailingPlugin extends Plugin {
208234
ruleStyle.getPropertyValue(property),
209235
ruleStyle.getPropertyPriority(property)
210236
);
237+
const variable = this.getVariableName(selector, property)
238+
this.getRule(this.cssPrefix).style.setProperty(variable, ruleStyle.getPropertyValue(property));
211239
}
212240
}
213241
}

0 commit comments

Comments
 (0)