[REF] web_editor, mass_mailing: abstract convert_inline function calls

This adds a `toInline` function that replaces the code that was
duplicated between convert_inline and mass_mailing_widget. The
duplication was confusing and error prone.

X-original-commit: 916582af2d707fc1aa462c6feffa3f5defda75a2
Part-of: odoo/odoo#81540
This commit is contained in:
Antoine Guenet
2021-12-16 15:58:23 +00:00
parent 770ea95b5b
commit bd884ae51d
2 changed files with 38 additions and 39 deletions
@@ -72,26 +72,7 @@ var MassMailingFieldHtml = FieldHtml.extend({
self._isDirty = self.wysiwyg.isDirty();
self._doAction();
// fix outlook image rendering bug (this change will be kept in both
// fields)
_.each(['width', 'height'], function (attribute) {
$editable.find('img').attr(attribute, function () {
return $(this)[attribute]();
}).css(attribute, function () {
return $(this).get(0).style[attribute] || attribute === 'width' ? $(this)[attribute]() + 'px' : '';
});
});
convertInline.attachmentThumbnailToLinkImg($editable);
convertInline.fontToImg($editable);
convertInline.classToStyle($editable, self.cssRules);
convertInline.bootstrapToTable($editable);
convertInline.cardToTable($editable);
convertInline.listGroupToTable($editable);
convertInline.addTables($editable);
convertInline.formatTables($editable);
convertInline.normalizeColors($editable);
convertInline.normalizeRem($editable);
convertInline.toInline($editable, self.cssRules);
self.trigger_up('field_changed', {
dataPointID: self.dataPointID,
@@ -323,6 +323,42 @@ function classToStyle($editable, cssRules) {
}
});
}
/**
* Convert the contents of an editable area (as a JQuery element) into content
* that is widely compatible with email clients. If no CSS Rules are given, they
* will be computed for the editable element's owner document.
*
* @param {JQuery} $editable
* @param {Object[]} [cssRules] Array<{selector: string;
* style: {[styleName]: string};
* specificity: number;}>
*/
function toInline($editable, cssRules) {
if (!cssRules) {
cssRules = getCSSRules($editable[0].ownerDocument);
}
// Fix outlook image rendering bug (this change will be kept in both
// fields).
_.each(['width', 'height'], function (attribute) {
$editable.find('img').attr(attribute, function () {
return $(this)[attribute]();
}).css(attribute, function () {
return $(this).get(0).style[attribute] || attribute === 'width' ? $(this)[attribute]() + 'px' : '';
});
});
attachmentThumbnailToLinkImg($editable);
fontToImg($editable);
classToStyle($editable, cssRules);
bootstrapToTable($editable);
cardToTable($editable);
listGroupToTable($editable);
addTables($editable);
formatTables($editable);
normalizeColors($editable);
normalizeRem($editable);
}
/**
* Convert font icons to images.
*
@@ -953,25 +989,7 @@ FieldHtml.include({
$odooEditor.removeClass('odoo-editor');
$editable.html(html);
attachmentThumbnailToLinkImg($editable);
fontToImg($editable);
classToStyle($editable, this.cssRules);
bootstrapToTable($editable);
cardToTable($editable);
listGroupToTable($editable);
addTables($editable);
formatTables($editable);
normalizeColors($editable);
normalizeRem($editable);
// fix outlook image rendering bug
_.each(['width', 'height'], function(attribute) {
$editable.find('img').attr(attribute, function(){
return $(this)[attribute]();
}).css(attribute, function(){
return $(this).get(0).style[attribute] || attribute === 'width' ? $(this)[attribute]() + 'px' : '';
});
});
toInline($editable, this.cssRules);
$odooEditor.addClass('odoo-editor');
this.wysiwyg.setValue($editable.html(), {