Debian Codegraph @

addons/point_of_sale/static/src/app/components/navbar/navbar.js

raw symbols SCIP
1 import { usePos } from "@point_of_sale/app/hooks/pos_hook";
2 import { useService } from "@web/core/utils/hooks";
3 import { isDisplayStandalone } from "@web/core/browser/feature_detection";
4
5 import { CashierName } from "@point_of_sale/app/components/navbar/cashier_name/cashier_name";
6 import { ProxyStatus } from "@point_of_sale/app/components/navbar/proxy_status/proxy_status";
7 import { SyncPopup } from "@point_of_sale/app/components/popups/sync_popup/sync_popup";
8 import {
9 SaleDetailsButton,
10 handleSaleDetails,
11 } from "@point_of_sale/app/components/navbar/sale_details_button/sale_details_button";
12 import { Component, onMounted, useState, useExternalListener } from "@odoo/owl";
13 import { Input } from "@point_of_sale/app/components/inputs/input/input";
14 import { isBarcodeScannerSupported } from "@web/core/barcode/barcode_video_scanner";
15 import { barcodeService } from "@barcodes/barcode_service";
16 import { Dropdown } from "@web/core/dropdown/dropdown";
17 import { DropdownItem } from "@web/core/dropdown/dropdown_item";
18 import { user } from "@web/core/user";
19 import { OrderTabs } from "@point_of_sale/app/components/order_tabs/order_tabs";
20 import { _t } from "@web/core/l10n/translation";
21 import { uuidv4 } from "@point_of_sale/utils";
22 import { QrCodeCustomerDisplay } from "@point_of_sale/app/customer_display/customer_display_qr_code_popup";
23 import { useAsyncLockedMethod } from "@point_of_sale/app/hooks/hooks";
24 import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
25
26 export class Navbar extends Component {
27 static template = "point_of_sale.Navbar";
28 static components = {
29 // FIXME POSREF remove some of these components
30 CashierName,
31 ProxyStatus,
32 SaleDetailsButton,
33 Input,
34 Dropdown,
35 DropdownItem,
36 SyncPopup,
37 OrderTabs,
38 };
39 static props = {};
40 setup() {
41 this.pos = usePos();
42 this.ui = useService("ui");
43 this.state = useState({ searchBarOpen: false });
44 this.dialog = useService("dialog");
45 this.notification = useService("notification");
46 this.hardwareProxy = useService("hardware_proxy");
47 this.dialog = useService("dialog");
48 this.isDisplayStandalone = isDisplayStandalone();
49 this.isBarcodeScannerSupported = isBarcodeScannerSupported;
50 this.timeout = null;
51 this.bufferedInput = "";
52 onMounted(async () => {
53 this.isSystemUser = await user.hasGroup("base.group_system");
54 });
55 useExternalListener(document, "keydown", this.handleKeydown.bind(this));
56 this.openPresetTiming = useAsyncLockedMethod(this.openPresetTiming);
57 }
58
59 openLnaPopup() {
60 this.dialog.add(AlertDialog, {
61 title: _t("LNA Permission status"),
62 body: this.pos.lnaState.message,
63 });
64 }
65
66 handleKeydown(event) {
67 const isEndCharacter = event.key?.match(/(Enter|Tab)/);
68 const isSpecialKey =
69 !["Control", "Alt"].includes(event.key) && (event.key?.length > 1 || event.metaKey);
70
71 clearTimeout(this.timeout);
72 if (isEndCharacter) {
73 this.checkInput(event);
74 } else {
75 if (!isSpecialKey) {
76 this.bufferedInput += event.key;
77 }
78 if (document.activeElement == this.inputRef?.el) {
79 this.checkInput(event);
80 } else {
81 this.timeout = setTimeout(() => {
82 this.checkInput(event);
83 }, barcodeService.maxTimeBetweenKeysInMs);
84 }
85 }
86 }
87
88 checkInput(event) {
89 if (
90 !this.ui.isSmall &&
91 this.inputRef?.el &&
92 document.activeElement !== this.inputRef.el &&
93 !this.pos.getOrder()?.getSelectedOrderline() &&
94 this.noOpenDialogs() &&
95 event.key?.length == 1 &&
96 this.bufferedInput.length < 3
97 ) {
98 this.inputRef.el.focus();
99 this.inputRef.el.value = this.bufferedInput;
100 event.preventDefault();
101 }
102 this.bufferedInput = "";
103 }
104
105 onClickRegister() {
106 let order = this.pos.getOrder();
107
108 if (!order) {
109 order = this.pos.addNewOrder();
110 }
111
112 this.pos.navigateToOrderScreen(order);
113 }
114
115 noOpenDialogs() {
116 return document.querySelectorAll(".modal-dialog, .debug-widget").length === 0;
117 }
118 onClickScan() {
119 if (!this.pos.scanning) {
120 const screenName = this.pos.router.state.current;
121 if (["ProductScreen", "TicketScreen"].includes(screenName)) {
122 const params =
123 screenName === "ProductScreen" ? { orderUuid: this.pos.getOrder().uuid } : {};
124 this.pos.navigate(screenName, params);
125 }
126 }
127 this.pos.ticket_screen_mobile_pane = this.pos.scanning ? "left" : "right";
128 this.pos.mobile_pane = "right";
129 this.pos.scanning = !this.pos.scanning;
130 }
131 get showCashMoveButton() {
132 return this.pos.showCashMoveButton;
133 }
134 getOrderTabs() {
135 return this.pos.getOpenOrders().filter((order) => !order.table_id);
136 }
137
138 get appUrl() {
139 return `/scoped_app?app_id=point_of_sale&app_name=${encodeURIComponent(
140 this.pos.config.display_name
141 )}&path=${encodeURIComponent(`pos/ui/${this.pos.config.id}`)}`;
142 }
143
144 async reloadProducts() {
145 this.dialog.add(SyncPopup, {
146 title: _t("Reload Data"),
147 confirm: (fullReload) => this.pos.reloadData(fullReload),
148 });
149 }
150
151 openCustomerDisplay() {
152 const getDeviceUuid = () => {
153 if (!localStorage.getItem("device_uuid")) {
154 localStorage.setItem("device_uuid", uuidv4());
155 }
156 return localStorage.getItem("device_uuid");
157 };
158 const customer_display_url = `/pos_customer_display/${
159 this.pos.config.id
160 }/${getDeviceUuid()}`;
161
162 this.dialog.add(QrCodeCustomerDisplay, {
163 customerDisplayURL: `${this.pos.config._base_url}${customer_display_url}`,
164 });
165 }
166
167 get showCreateProductButton() {
168 return this.isSystemUser;
169 }
170
171 get shouldDisplayPresetTime() {
172 return this.pos.getOrder()?.preset_id?.use_timing;
173 }
174
175 async showSaleDetails() {
176 await handleSaleDetails(this.pos, this.hardwareProxy, this.dialog);
177 }
178
179 async openPresetTiming() {
180 await this.pos.openPresetTiming();
181 }
182
183 get mainButton() {
184 const screens = ["ProductScreen", "PaymentScreen", "ReceiptScreen", "TipScreen"];
185 return screens.includes(this.pos.router.state.current) ? "register" : "order";
186 }
187 }