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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
odoo.define('website_mass_mailing.editor', function (require) {
'use strict';
var core = require('web.core');
var rpc = require('web.rpc');
var WysiwygMultizone = require('web_editor.wysiwyg.multizone');
var WysiwygTranslate = require('web_editor.wysiwyg.multizone.translate');
var options = require('web_editor.snippets.options');
var wUtils = require('website.utils');
const qweb = core.qweb;
var _t = core._t;
options.registry.mailing_list_subscribe = options.Class.extend({
popup_template_id: "editor_new_mailing_list_subscribe_button",
popup_title: _t("Add a Newsletter Subscribe Button"),
//--------------------------------------------------------------------------
// Options
//--------------------------------------------------------------------------
/**
* Allows to select mailing list.
*
* @see this.selectClass for parameters
*/
select_mailing_list: function (previewMode, value) {
var self = this;
var def = wUtils.prompt({
'id': this.popup_template_id,
'window_title': this.popup_title,
'select': _t("Newsletter"),
'init': function (field, dialog) {
return rpc.query({
model: 'mailing.list',
method: 'name_search',
args: ['', [['is_public', '=', true]]],
context: self.options.recordInfo.context,
}).then(function (data) {
$(dialog).find('.btn-primary').prop('disabled', !data.length);
var list_id = self.$target.attr("data-list-id");
$(dialog).on('show.bs.modal', function () {
if (list_id !== "0"){
$(dialog).find('select').val(list_id);
};
});
return data;
});
},
});
def.then(function (result) {
self.$target.attr("data-list-id", result.val);
});
return def;
},
/**
* @override
*/
onBuilt: function () {
var self = this;
this._super();
this.select_mailing_list('click').guardedCatch(function () {
self.getParent()._onRemoveClick($.Event( "click" ));
});
},
});
options.registry.recaptchaSubscribe = options.Class.extend({
xmlDependencies: ['/google_recaptcha/static/src/xml/recaptcha.xml'],
/**
* Toggle the recaptcha legal terms
*/
toggleRecaptchaLegal: function (previewMode, value, params) {
const recaptchaLegalEl = this.$target[0].querySelector('.o_recaptcha_legal_terms');
if (recaptchaLegalEl) {
recaptchaLegalEl.remove();
} else {
const template = document.createElement('template');
template.innerHTML = qweb.render("google_recaptcha.recaptcha_legal_terms");
this.$target[0].appendChild(template.content.firstElementChild);
}
},
//----------------------------------------------------------------------
// Private
//----------------------------------------------------------------------
/**
* @override
*/
_computeWidgetState: function (methodName, params) {
switch (methodName) {
case 'toggleRecaptchaLegal':
return !this.$target[0].querySelector('.o_recaptcha_legal_terms') || '';
}
return this._super(...arguments);
},
});
options.registry.newsletter_popup = options.registry.mailing_list_subscribe.extend({
popup_template_id: "editor_new_mailing_list_subscribe_popup",
popup_title: _t("Add a Newsletter Subscribe Popup"),
/**
* @override
*/
start: function () {
this.$target.on('hidden.bs.modal.newsletter_popup_option', () => {
this.trigger_up('snippet_option_visibility_update', {show: false});
});
return this._super(...arguments);
},
/**
* @override
*/
onTargetShow: function () {
// Open the modal
this.$target.data('quick-open', true);
return this._refreshPublicWidgets();
},
/**
* @override
*/
onTargetHide: function () {
// Close the modal
const $modal = this.$('.modal');
if ($modal.length && $modal.is('.modal_shown')) {
$modal.modal('hide');
}
},
/**
* @override
*/
cleanForSave: function () {
var self = this;
var content = this.$target.data('content');
if (content) {
this.trigger_up('get_clean_html', {
$layout: $('<div/>').html(content),
callback: function (html) {
self.$target.data('content', html);
},
});
}
this._super.apply(this, arguments);
},
/**
* @override
*/
destroy: function () {
this.$target.off('.newsletter_popup_option');
this._super.apply(this, arguments);
},
//--------------------------------------------------------------------------
// Options
//--------------------------------------------------------------------------
/**
* @override
*/
select_mailing_list: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
self.$target.data('quick-open', true);
self.$target.removeData('content');
return self._refreshPublicWidgets();
});
},
});
WysiwygMultizone.include({
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @override
*/
_saveElement: function (outerHTML, recordInfo, editable) {
var self = this;
var defs = [this._super.apply(this, arguments)];
var $popups = $(editable).find('.o_newsletter_popup');
_.each($popups, function (popup) {
var $popup = $(popup);
var content = $popup.data('content');
if (content) {
defs.push(self._rpc({
route: '/website_mass_mailing/set_content',
params: {
'newsletter_id': parseInt($popup.attr('data-list-id')),
'content': content,
},
}));
}
});
return Promise.all(defs);
},
});
WysiwygTranslate.include({
/**
* @override
*/
start: function () {
this.$target.on('click.newsletter_popup_option', '.o_edit_popup', function (ev) {
alert(_t('Website popups can only be translated through mailing list configuration in the Email Marketing app.'));
});
this._super.apply(this, arguments);
},
});
});
|