| 1 |
import { Component, useState } from "@odoo/owl"; |
| 2 |
import { usePos } from "@point_of_sale/app/hooks/pos_hook"; |
| 3 |
import { useService } from "@web/core/utils/hooks"; |
| 4 |
import { SIZES, utils } from "@web/core/ui/ui_service"; |
| 5 |
import { |
| 6 |
getButtons, |
| 7 |
EMPTY, |
| 8 |
ZERO, |
| 9 |
BACKSPACE, |
| 10 |
Numpad, |
| 11 |
} from "@point_of_sale/app/components/numpad/numpad"; |
| 12 |
|
| 13 |
export class NumpadDropdown extends Component { |
| 14 |
static template = "pos_restaurant.NumpadDropdown"; |
| 15 |
static props = {}; |
| 16 |
static components = { Numpad }; |
| 17 |
|
| 18 |
setup() { |
| 19 |
this.pos = usePos(); |
| 20 |
this.ui = useService("ui"); |
| 21 |
this.numberBuffer = useService("number_buffer"); |
| 22 |
this.numberBuffer.use({ |
| 23 |
triggerAtEnter: () => this.pos.searchOrder(this.state.buffer), |
| 24 |
triggerAtInput: ({ buffer }) => this.checkIsValid(buffer), |
| 25 |
}); |
| 26 |
this.state = useState({ |
| 27 |
buffer: "", |
| 28 |
isValidBuffer: true, |
| 29 |
}); |
| 30 |
} |
| 31 |
|
| 32 |
get numpadButtons() { |
| 33 |
const colorClassMap = { |
| 34 |
[BACKSPACE.value]: "o_colorlist_item_numpad_color_1", |
| 35 |
}; |
| 36 |
|
| 37 |
return getButtons([{ ...EMPTY, disabled: true }, ZERO, BACKSPACE]).map((button, index) => ({ |
| 38 |
...button, |
| 39 |
class: ` |
| 40 |
${button.class} |
| 41 |
${colorClassMap[button.value] || ""} |
| 42 |
`, |
| 43 |
})); |
| 44 |
} |
| 45 |
|
| 46 |
searchOrder() { |
| 47 |
if (this.state.isValidBuffer) { |
| 48 |
this.pos.searchOrder(this.state.buffer); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
toggleTableSelector() { |
| 53 |
this.pos.tableSelectorState = !this.pos.tableSelectorState; |
| 54 |
} |
| 55 |
|
| 56 |
get isSmall() { |
| 57 |
return utils.getSize() <= SIZES.SM; |
| 58 |
} |
| 59 |
|
| 60 |
checkIsValid(buffer) { |
| 61 |
this.state.buffer = buffer; |
| 62 |
const res = this.pos.findTable(buffer); |
| 63 |
this.state.isValidBuffer = Boolean(res); |
| 64 |
} |
| 65 |
} |