summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/static/src/js/PosComponent.js
blob: ae2873ba82850b5eae34f4ca270f90fef4ebd3b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
odoo.define('point_of_sale.PosComponent', function (require) {
    'use strict';

    const { Component } = owl;

    class PosComponent extends Component {
        /**
         * This function is available to all Components that inherit this class.
         * The goal of this function is to show an awaitable dialog (popup) that
         * returns a response after user interaction. See the following for quick
         * demonstration:
         *
         * ```
         * async getUserName() {
         *   const userResponse = await this.showPopup(
         *     'TextInputPopup',
         *     { title: 'What is your name?' }
         *   );
         *   // at this point, the TextInputPopup is displayed. Depending on how the popup is defined,
         *   // say the input contains the name, the result of the interaction with the user is
         *   // saved in `userResponse`.
         *   console.log(userResponse); // logs { confirmed: true, payload: <name> }
         * }
         * ```
         *
         * @param {String} name Name of the popup component
         * @param {Object} props Object that will be used to render to popup
         */
        showPopup(name, props) {
            return new Promise((resolve) => {
                this.trigger('show-popup', { name, props, resolve });
            });
        }
        showTempScreen(name, props) {
            return new Promise((resolve) => {
                this.trigger('show-temp-screen', { name, props, resolve });
            });
        }
        showScreen(name, props) {
            this.trigger('show-main-screen', { name, props });
        }
        /**
         * @param {String} name 'bell' | 'error'
         */
        playSound(name) {
            this.trigger('play-sound', name);
        }
        /**
         * Control the SyncNotification component.
         * @param {String} status 'connected' | 'connecting' | 'disconnected' | 'error'
         * @param {String} pending number of pending orders to sync
         */
        setSyncStatus(status, pending) {
            this.trigger('set-sync-status', { status, pending });
        }
    }

    return PosComponent;
});