| 1 |
import { useService } from "@web/core/utils/hooks"; |
| 2 |
import { Component } from "@odoo/owl"; |
| 3 |
import { localization } from "@web/core/l10n/localization"; |
| 4 |
|
| 5 |
export const buttonsType = { |
| 6 |
type: Array, |
| 7 |
element: [ |
| 8 |
{ |
| 9 |
type: Object, |
| 10 |
shape: { |
| 11 |
value: String, |
| 12 |
text: { type: String, optional: true }, |
| 13 |
class: { type: String, optional: true }, |
| 14 |
disabled: { type: Boolean, optional: true }, |
| 15 |
}, |
| 16 |
}, |
| 17 |
Number, |
| 18 |
String, |
| 19 |
], |
| 20 |
}; |
| 21 |
|
| 22 |
export const DECIMAL = { |
| 23 |
get value() { |
| 24 |
return localization.decimalPoint; |
| 25 |
}, |
| 26 |
class: "o_colorlist_item_numpad_color_6", |
| 27 |
}; |
| 28 |
export const BACKSPACE = { |
| 29 |
value: "Backspace", |
| 30 |
text: "⌫", |
| 31 |
class: "o_colorlist_item_numpad_color_1", |
| 32 |
}; |
| 33 |
export const ZERO = { value: "0" }; |
| 34 |
export const SWITCHSIGN = { value: "-", text: "+/-" }; |
| 35 |
export const DEFAULT_LAST_ROW = [SWITCHSIGN, ZERO, DECIMAL]; |
| 36 |
export const EMPTY = { value: "" }; |
| 37 |
|
| 38 |
export function getButtons(lastRow, rightColumn) { |
| 39 |
return [ |
| 40 |
{ value: "1" }, |
| 41 |
{ value: "2" }, |
| 42 |
{ value: "3" }, |
| 43 |
...(rightColumn ? [rightColumn[0]] : []), |
| 44 |
{ value: "4" }, |
| 45 |
{ value: "5" }, |
| 46 |
{ value: "6" }, |
| 47 |
...(rightColumn ? [rightColumn[1]] : []), |
| 48 |
{ value: "7" }, |
| 49 |
{ value: "8" }, |
| 50 |
{ value: "9" }, |
| 51 |
...(rightColumn ? [rightColumn[2]] : []), |
| 52 |
...lastRow, |
| 53 |
...(rightColumn ? [rightColumn[3]] : []), |
| 54 |
]; |
| 55 |
} |
| 56 |
|
| 57 |
export function enhancedButtons() { |
| 58 |
return getButtons(DEFAULT_LAST_ROW, [ |
| 59 |
{ value: "+10" }, |
| 60 |
{ value: "+20" }, |
| 61 |
{ value: "+50" }, |
| 62 |
BACKSPACE, |
| 63 |
]); |
| 64 |
} |
| 65 |
|
| 66 |
export class Numpad extends Component { |
| 67 |
static template = "point_of_sale.Numpad"; |
| 68 |
static props = { |
| 69 |
class: { type: String, optional: true }, |
| 70 |
onClick: { type: Function, optional: true }, |
| 71 |
buttons: { type: buttonsType, optional: true }, |
| 72 |
}; |
| 73 |
static defaultProps = { |
| 74 |
class: "numpad", |
| 75 |
}; |
| 76 |
get buttons() { |
| 77 |
return this.props.buttons || getButtons([DECIMAL, ZERO, BACKSPACE]); |
| 78 |
} |
| 79 |
setup() { |
| 80 |
if (!this.props.onClick) { |
| 81 |
this.numberBuffer = useService("number_buffer"); |
| 82 |
this.onClick = (buttonValue) => this.numberBuffer.sendKey(buttonValue); |
| 83 |
} else { |
| 84 |
this.onClick = this.props.onClick; |
| 85 |
} |
| 86 |
} |
| 87 |
} |