Debian Codegraph @

addons/sale_management/static/src/interactions/sale_update_line_button.js

raw
1 import { Interaction } from "@web/public/interaction";
2 import { registry } from "@web/core/registry";
3
4 import { rpc } from "@web/core/network/rpc";
5
6 export class SaleUpdateLineButton extends Interaction {
7 static selector = ".o_portal_sale_sidebar";
8 dynamicContent = {
9 "a.js_update_line_json": {
10 "t-on-click.prevent.withTarget": this.onUpdateLineClick,
11 },
12 ".js_quantity": {
13 "t-on-change.prevent.withTarget": this.onQuantityChange,
14 },
15 };
16
17 setup() {
18 this.orderDetail = this.el.querySelector("table#sales_order_table").dataset;
19 }
20
21 /**
22 * @param {number} orderId
23 * @param {Object} params
24 */
25 callUpdateLineRoute(orderId, params) {
26 return rpc("/my/orders/" + orderId + "/update_line_dict", params);
27 }
28
29 refreshOrderUI() {
30 window.location.reload();
31 }
32
33 /**
34 * @param {MouseEvent} ev
35 * @param {HTMLElement} currentTargetEl
36 */
37 async onQuantityChange(ev, currentTargetEl) {
38 const quantity = parseInt(currentTargetEl.value);
39 await this.waitFor(this.callUpdateLineRoute(this.orderDetail.orderId, {
40 "access_token": this.orderDetail.token,
41 "input_quantity": quantity >= 0 ? quantity : false,
42 "line_id": currentTargetEl.dataset.lineId,
43 }));
44 this.refreshOrderUI();
45 }
46
47 /**
48 * @param {MouseEvent} ev
49 * @param {HTMLElement} currentTargetEl
50 */
51 async onUpdateLineClick(ev, currentTargetEl) {
52 await this.waitFor(this.callUpdateLineRoute(this.orderDetail.orderId, {
53 "access_token": this.orderDetail.token,
54 "line_id": currentTargetEl.dataset.lineId,
55 "remove": currentTargetEl.dataset.remove,
56 }));
57 this.refreshOrderUI();
58 }
59 }
60
61 registry
62 .category("public.interactions")
63 .add("sale_management.sale_update_line_button", SaleUpdateLineButton);