[IMP] website, website_mass_mailing: make btn-primary close popup
Before this commit, only the cross icon "x" top right of the popup would be able to properly close the popup and set a cookie to prevent that popup to open again later. There is no way through the UI to make a button in the popup do the same behavior. This commit now add this behavior to any `.btn-primary` element inside the popup, except a few ones like the newsletter input group button and the website form submit one. Note that we have a way in stable to do that, but it's through code. People have to add the `js_close_popup` class to the button. This class is there for this reason, but it's obviously limited to tech people only or our support. task-3377306 opw-3328135 closes odoo/odoo#124432 Signed-off-by: Arthur Detroux (ard) <ard@odoo.com>
This commit is contained in:
@@ -72,6 +72,7 @@ const PopupWidget = publicWidget.Widget.extend({
|
||||
selector: '.s_popup',
|
||||
events: {
|
||||
'click .js_close_popup': '_onCloseClick',
|
||||
'click .btn-primary': '_onBtnPrimaryClick',
|
||||
'hide.bs.modal': '_onHideModal',
|
||||
'show.bs.modal': '_onShowModal',
|
||||
},
|
||||
@@ -174,6 +175,19 @@ const PopupWidget = publicWidget.Widget.extend({
|
||||
this._showPopup();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Checks if the given primary button should allow or not to close the
|
||||
* modal.
|
||||
*
|
||||
* @private
|
||||
* @param {HTMLElement} primaryBtnEl
|
||||
*/
|
||||
_canBtnPrimaryClosePopup(primaryBtnEl) {
|
||||
return !(
|
||||
primaryBtnEl.classList.contains("s_website_form_send")
|
||||
|| primaryBtnEl.classList.contains("o_website_form_send")
|
||||
);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Handlers
|
||||
@@ -185,6 +199,14 @@ const PopupWidget = publicWidget.Widget.extend({
|
||||
_onCloseClick: function () {
|
||||
this._hidePopup();
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_onBtnPrimaryClick(ev) {
|
||||
if (this._canBtnPrimaryClosePopup(ev.target)) {
|
||||
this._hidePopup();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,15 @@ PopupWidget.include({
|
||||
}
|
||||
return this._super(...arguments);
|
||||
},
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
_canBtnPrimaryClosePopup(primaryBtnEl) {
|
||||
if (primaryBtnEl.classList.contains('js_subscribe_btn')) {
|
||||
return false;
|
||||
}
|
||||
return this._super(...arguments);
|
||||
},
|
||||
});
|
||||
|
||||
export default PopupWidget;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
'views/snippets/snippets.xml',
|
||||
'views/snippets/s_add_to_cart.xml',
|
||||
'views/snippets/s_dynamic_snippet_products.xml',
|
||||
'views/snippets/s_popup.xml',
|
||||
'views/res_config_settings_views.xml',
|
||||
'views/website_sale_visitor_views.xml',
|
||||
'views/website_base_unit_views.xml',
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import PopupWidget from 'website.s_popup';
|
||||
|
||||
PopupWidget.include({
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Checks if the given primary button should allow or not to close the
|
||||
* modal.
|
||||
*
|
||||
* @override
|
||||
*/
|
||||
_canBtnPrimaryClosePopup(primaryBtnEl) {
|
||||
return (
|
||||
this._super(...arguments)
|
||||
&& !primaryBtnEl.classList.contains("js_add_cart")
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default PopupWidget;
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="website_sale.s_popup_000_js" model="ir.asset">
|
||||
<field name="name">Popup 000 JS Website Sale Override</field>
|
||||
<field name="bundle">web.assets_frontend</field>
|
||||
<field name="path">website_sale/static/src/snippets/s_popup/000.js</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user