summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/point_of_sale/static/src/js/Popups/SelectionPopup.js
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/point_of_sale/static/src/js/Popups/SelectionPopup.js')
-rw-r--r--addons/point_of_sale/static/src/js/Popups/SelectionPopup.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js b/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js
new file mode 100644
index 00000000..5321fdea
--- /dev/null
+++ b/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js
@@ -0,0 +1,57 @@
+odoo.define('point_of_sale.SelectionPopup', function (require) {
+ 'use strict';
+
+ const { useState } = owl.hooks;
+ const AbstractAwaitablePopup = require('point_of_sale.AbstractAwaitablePopup');
+ const Registries = require('point_of_sale.Registries');
+
+ // formerly SelectionPopupWidget
+ class SelectionPopup extends AbstractAwaitablePopup {
+ /**
+ * Value of the `item` key of the selected element in the Selection
+ * Array is the payload of this popup.
+ *
+ * @param {Object} props
+ * @param {String} [props.confirmText='Confirm']
+ * @param {String} [props.cancelText='Cancel']
+ * @param {String} [props.title='Select']
+ * @param {String} [props.body='']
+ * @param {Array<Selection>} [props.list=[]]
+ * Selection {
+ * id: integer,
+ * label: string,
+ * isSelected: boolean,
+ * item: any,
+ * }
+ */
+ constructor() {
+ super(...arguments);
+ this.state = useState({ selectedId: this.props.list.find((item) => item.isSelected) });
+ }
+ selectItem(itemId) {
+ this.state.selectedId = itemId;
+ this.confirm();
+ }
+ /**
+ * We send as payload of the response the selected item.
+ *
+ * @override
+ */
+ getPayload() {
+ const selected = this.props.list.find((item) => this.state.selectedId === item.id);
+ return selected && selected.item;
+ }
+ }
+ SelectionPopup.template = 'SelectionPopup';
+ SelectionPopup.defaultProps = {
+ confirmText: 'Confirm',
+ cancelText: 'Cancel',
+ title: 'Select',
+ body: '',
+ list: [],
+ };
+
+ Registries.Component.add(SelectionPopup);
+
+ return SelectionPopup;
+});