Skip to content

Commit 0366fb2

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

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
@@ -110,12 +110,12 @@ export class CustomizeMailingPlugin extends Plugin {
110110
if (currentValue === "" && defaultValue !== "") {
111111
varRule.style.setProperty(variable, defaultValue);
112112
}
113-
this.refreshMailingVariableSelector(variable);
113+
this.refreshMailingVariableSelector(variable, true);
114114
}
115115
console.log(this.toRemove);
116116
}
117117

118-
refreshMailingVariableSelector(variable) {
118+
refreshMailingVariableSelector(variable, isSetup = false) {
119119
const toRemove = {};
120120
this.toRemove[variable] = toRemove;
121121
const options = CUSTOMIZE_MAILING_VARIABLES[variable];
@@ -128,7 +128,11 @@ export class CustomizeMailingPlugin extends Plugin {
128128
const rule = this.getRule(selector);
129129
for (const property of options.properties) {
130130
const important = PRIORITY_STYLES[selector]?.has(property) ? "important" : "";
131-
rule.style.setProperty(property, value, important);
131+
if (isSetup && rule.style.getPropertyValue(property)) {
132+
this.setVariable(variable, rule.style.getPropertyValue(property))
133+
} else {
134+
rule.style.setProperty(property, value, important);
135+
}
132136
}
133137
}
134138
// toremove
@@ -142,6 +146,28 @@ export class CustomizeMailingPlugin extends Plugin {
142146
}
143147
}
144148

149+
getVariableName(selector, property) {
150+
let prefix = "text";
151+
if (selector.includes("h1")) {
152+
prefix = "h1";
153+
} else if (selector.includes("h2")) {
154+
prefix = "h2";
155+
} else if (selector.includes("h3")) {
156+
prefix = "h3";
157+
} else if (/((\bp\b)|(\bp > \*)|(\bli\b)|(\bli > \*))/.test(selector)) {
158+
prefix = "text";
159+
} else if (/(a\..*\.btn\-.*\-?primary)/.test(selector)) {
160+
prefix = "btn-primary";
161+
} else if (/(a\..*\.btn\-.*\-?secondary)/.test(selector)) {
162+
prefix = "btn-secondary";
163+
} else if (/((a:not\(\.btn\))|(a\.btn\.btn\-link))/.test(selector)) {
164+
prefix = "link";
165+
} else if (/hr/.test(selector)) {
166+
prefix = "separator"
167+
}
168+
return `--${prefix}-${property}`;
169+
}
170+
145171
parseDesignElement(styleEl) {
146172
const rules = [...styleEl.sheet.cssRules];
147173
for (const rule of rules) {
@@ -221,6 +247,8 @@ export class CustomizeMailingPlugin extends Plugin {
221247
ruleStyle.getPropertyValue(property),
222248
ruleStyle.getPropertyPriority(property)
223249
);
250+
const variable = this.getVariableName(selector, property)
251+
this.getRule(this.cssPrefix).style.setProperty(variable, ruleStyle.getPropertyValue(property));
224252
}
225253
}
226254
}

0 commit comments

Comments
 (0)