Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
4680 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Autor

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 Odpovědi Zobrazení Aktivita
3
čvc 18
3876
2
čvc 17
4551
0
kvě 24
2058
1
srp 23
3631
1
srp 23
11193