Skip to Content
Menu
This question has been flagged

I develop a website and I use Newsletter module. By default, it shows success message (Thanks for subscribing!) when you click to Subscribe button. I don't want to see these toast messages for Newsletter module.


I see that this toast message comes from the code below of the website_mass_mailing.js file. 


self.displayNotification({ 
    type: toastType, 
    title: toastType === 'success' ? _t('Success') : _t('Error'), 
    message: result.toast_content, 
    sticky: true,
});


When I comment out this part, it doesn't show the toast message. But I want to do it with inheriting this file and not changing the original one. I tried to inherit it but, I couldn't succeed. Any suggestion how to do it?

Avatar
Discard
Best Answer

Hi George, 

Please check with the below code snippet.

To add the changes, you'll basically have to override the existing function by monkeypatching the code.

odoo.define('your_module.name', function (require){

var publicWidget = require('web.public.widget');

publicWidget.registry.subscribe.include({
_onSubscribeClick: async function () {
var self = this;
var $email = this.$(".js_subscribe_email:visible");

if ($email.length && !$email.val().match(/.+@.+/)) {
this.$target.addClass('o_has_error').find('.form-control').addClass('is-invalid');
return false;
}
this.$target.removeClass('o_has_error').find('.form-control').removeClass('is-invalid');
let tokenObj = null;
if (this._recaptcha) {
tokenObj = await this._recaptcha.getToken('website_mass_mailing_subscribe');
if (tokenObj.error) {
self.displayNotification({
type: 'danger',
title: _t("Error"),
message: tokenObj.error,
sticky: true,
});
return false;
}
}
const params = {
'list_id': this.$target.data('list-id'),
'email': $email.length ? $email.val() : false,
};
if (this._recaptcha) {
params['recaptcha_token_response'] = tokenObj.token;
}
this._rpc({
route: '/website_mass_mailing/subscribe',
params: params,
}).then(function (result) {
let toastType = result.toast_type;
if (toastType === 'success') {
self.$(".js_subscribe_btn").addClass('d-none');
self.$(".js_subscribed_btn").removeClass('d-none');
self.$('input.js_subscribe_email').prop('disabled', !!result);
if (self.$popup.length) {
self.$popup.modal('hide');
}
}
// make the changes you need accordingly or comment out the below code.
self.displayNotification({
type: toastType,
title: toastType === 'success' ? _t('Success') : _t('Error'),
message: result.toast_content,
sticky: true,
});
});
},

})

})

Regards

Avatar
Discard
Author

Hi Cybrosys Techno Solutions Pvt.Ltd,

thanks for the answer. It was giving an error like this:

Traceback:
ReferenceError: _t is not defined
at http://localhost:8069/web/content/635-0ce3d45/1/web.assets_frontend_lazy.js:372:57

So I add `var _t = core._t;` before `var publicWidget` line and it worked. Appreciate!

Related Posts Replies Views Activity
3
Jul 18
2604
2
Jul 17
3602
0
May 24
504
1
Aug 23
2476
1
Aug 23
10148