1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
odoo.define('mass_mailing.snippets.options', function (require) {
"use strict";
var options = require('web_editor.snippets.options');
// Snippet option for resizing image and column width inline like excel
options.registry.mass_mailing_sizing_x = options.Class.extend({
/**
* @override
*/
start: function () {
var def = this._super.apply(this, arguments);
this.containerWidth = this.$target.parent().closest("td, table, div").width();
var self = this;
var offset, sib_offset, target_width, sib_width;
this.$overlay.find(".o_handle.e, .o_handle.w").removeClass("readonly");
this.isIMG = this.$target.is("img");
if (this.isIMG) {
this.$overlay.find(".o_handle.w").addClass("readonly");
}
var $body = $(this.ownerDocument.body);
this.$overlay.find(".o_handle").on('mousedown', function (event) {
event.preventDefault();
var $handle = $(this);
var compass = false;
_.each(['n', 's', 'e', 'w'], function (handler) {
if ($handle.hasClass(handler)) { compass = handler; }
});
if (self.isIMG) { compass = "image"; }
$body.on("mousemove.mass_mailing_width_x", function (event) {
event.preventDefault();
offset = self.$target.offset().left;
target_width = self.get_max_width(self.$target);
if (compass === 'e' && self.$target.next().offset()) {
sib_width = self.get_max_width(self.$target.next());
sib_offset = self.$target.next().offset().left;
self.change_width(event, self.$target, target_width, offset, true);
self.change_width(event, self.$target.next(), sib_width, sib_offset, false);
}
if (compass === 'w' && self.$target.prev().offset()) {
sib_width = self.get_max_width(self.$target.prev());
sib_offset = self.$target.prev().offset().left;
self.change_width(event, self.$target, target_width, offset, false);
self.change_width(event, self.$target.prev(), sib_width, sib_offset, true);
}
if (compass === 'image') {
self.change_width(event, self.$target, target_width, offset, true);
}
});
$body.one("mouseup", function () {
$body.off('.mass_mailing_width_x');
});
});
return def;
},
change_width: function (event, target, target_width, offset, grow) {
target.css("width", grow ? (event.pageX - offset) : (offset + target_width - event.pageX));
this.trigger_up('cover_update');
},
get_int_width: function (el) {
return parseInt($(el).css("width"), 10);
},
get_max_width: function ($el) {
return this.containerWidth - _.reduce(_.map($el.siblings(), this.get_int_width), function (memo, w) { return memo + w; });
},
onFocus: function () {
this._super.apply(this, arguments);
if (this.$target.is("td, th")) {
this.$overlay.find(".o_handle.e, .o_handle.w").toggleClass("readonly", this.$target.siblings().length === 0);
}
},
});
options.registry.mass_mailing_table_item = options.Class.extend({
onClone: function (options) {
this._super.apply(this, arguments);
// If we cloned a td or th element...
if (options.isCurrent && this.$target.is("td, th")) {
// ... and that the td or th element was alone on its row ...
if (this.$target.siblings().length === 1) {
var $tr = this.$target.parent();
$tr.clone().empty().insertAfter($tr).append(this.$target); // ... move the clone in a new row instead
return;
}
// ... if not, if the clone neighbor is an empty cell, remove this empty cell (like if the clone content had been put in that cell)
var $next = this.$target.next();
if ($next.length && $next.text().trim() === "") {
$next.remove();
return;
}
// ... if not, insert an empty col in each other row, at the index of the clone
var width = this.$target.width();
var $trs = this.$target.closest("table").children("thead, tbody, tfoot").addBack().children("tr").not(this.$target.parent());
_.each($trs.children(":nth-child(" + this.$target.index() + ")"), function (col) {
$(col).after($("<td/>", {style: "width: " + width + "px;"}));
});
}
},
onRemove: function () {
this._super.apply(this, arguments);
// If we are removing a td or th element which was not alone on its row ...
if (this.$target.is("td, th") && this.$target.siblings().length > 0) {
var $trs = this.$target.closest("table").children("thead, tbody, tfoot").addBack().children("tr").not(this.$target.parent());
if ($trs.length) { // ... if there are other rows in the table ...
var $last_tds = $trs.children(":last-child");
if (_.reduce($last_tds, function (memo, td) { return memo + (td.innerHTML || ""); }, "").trim() === "") {
$last_tds.remove(); // ... remove the potential full empty column in the table
} else {
this.$target.parent().append("<td/>"); // ... else, if there is no full empty column, append an empty col in the current row
}
}
}
},
});
// Adding compatibility for the outlook compliance of mailings.
// Commit of such compatibility : a14f89c8663c9cafecb1cc26918055e023ecbe42
options.registry.BackgroundImage = options.registry.BackgroundImage.extend({
start: function () {
this._super();
if (this.snippets && this.snippets.split('.')[0] === "mass_mailing") {
var $table_target = this.$target.find('table:first');
if ($table_target.length) {
this.$target = $table_target;
}
}
}
});
// TODO remove in master when removing the XML div. The option has been disabled
// in 14.0 because of tricky problems to resolve that require refactoring:
// the ability to clean snippet without saving and reloading the page.
options.registry.SnippetSave.include({
async saveSnippet(previewMode, widgetValue, params) {},
async _computeVisibility() {
return false;
},
});
});
|