From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../static/src/js/PopupControllerMixin.js | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 addons/point_of_sale/static/src/js/PopupControllerMixin.js (limited to 'addons/point_of_sale/static/src/js/PopupControllerMixin.js') diff --git a/addons/point_of_sale/static/src/js/PopupControllerMixin.js b/addons/point_of_sale/static/src/js/PopupControllerMixin.js new file mode 100644 index 00000000..446a514a --- /dev/null +++ b/addons/point_of_sale/static/src/js/PopupControllerMixin.js @@ -0,0 +1,44 @@ +odoo.define('point_of_sale.PopupControllerMixin', function(require) { + 'use strict'; + + const { useState } = owl; + const { useListener } = require('web.custom_hooks'); + + /** + * Allows the component declared with this mixin the ability show popup dynamically, + * provided the following: + * 1. The following element is declared in the template. It is where the Popup will be rendered. + * `` + * 2. The component should trigger `show-popup` event to show the popup and `close-popup` event + * to close. In PosComponent, `showPopup` is conveniently declared to satisfy this requirement. + * @param {Function} x class definition to mix with during extension + */ + const PopupControllerMixin = x => + class extends x { + constructor() { + super(...arguments); + useListener('show-popup', this.__showPopup); + useListener('close-popup', this.__closePopup); + + this.popup = useState({ isShown: false, name: null, component: null }); + this.popupProps = {}; // We want to avoid making the props to become Proxy! + } + __showPopup(event) { + const { name, props, resolve } = event.detail; + const popupConstructor = this.constructor.components[name]; + if (popupConstructor.dontShow) { + resolve(); + return; + } + this.popup.isShown = true; + this.popup.name = name; + this.popup.component = popupConstructor; + this.popupProps = Object.assign({}, props, { resolve }); + } + __closePopup() { + this.popup.isShown = false; + } + }; + + return PopupControllerMixin; +}); -- cgit v1.2.3