diff --git a/addons/laundry_management/static/src/js/popups/laundry_order_attribute_popup.js b/addons/laundry_management/static/src/js/popups/laundry_order_attribute_popup.js new file mode 100644 index 0000000..c9abbce --- /dev/null +++ b/addons/laundry_management/static/src/js/popups/laundry_order_attribute_popup.js @@ -0,0 +1,51 @@ +/** @odoo-module */ +import { Component, useState } from "@odoo/owl"; +import { Dialog } from "@web/core/dialog/dialog"; +import { _t } from "@web/core/l10n/translation"; + +export class LaundryOrderAttributePopup extends Component { + static components = { Dialog }; + static template = "laundry_management.LaundryOrderAttributePopup"; + static props = { + attributes: { type: Array }, + preselectedIds: { type: Array, optional: true }, + title: { type: String, optional: true }, + getPayload: { type: Function }, + close: { type: Function }, + }; + static defaultProps = { + preselectedIds: [], + title: _t("Select Attributes"), + }; + + setup() { + const initial = new Set(this.props.preselectedIds); + this.state = useState({ + selected: initial, + }); + } + + toggle(attrId) { + if (this.state.selected.has(attrId)) { + this.state.selected.delete(attrId); + } else { + this.state.selected.add(attrId); + } + } + + isSelected(attrId) { + return this.state.selected.has(attrId); + } + + confirm() { + const ids = [...this.state.selected]; + const chosen = this.props.attributes.filter((a) => ids.includes(a.id)); + this.props.getPayload(chosen); + this.props.close(); + } + + skip() { + this.props.getPayload([]); + this.props.close(); + } +}