summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/control_panel/control_panel_x2many.js
blob: 22b4ae565dab20e438188080851cd3608045c9d6 (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
odoo.define('web.ControlPanelX2Many', function (require) {

    const ControlPanel = require('web.ControlPanel');

    /**
     * Control panel (adaptation for x2many fields)
     *
     * Smaller version of the control panel with an abridged template (buttons and
     * pager only). We still extend the main version for the injection of `cp_content`
     * keys.
     * The pager of this control panel is only displayed if the amount of records
     * cannot be displayed in a single page.
     * @extends ControlPanel
     */
    class ControlPanelX2Many extends ControlPanel {

        /**
         * @private
         * @returns {boolean}
         */
        _shouldShowPager() {
            if (!this.props.pager || !this.props.pager.limit) {
                return false;
            }
            const { currentMinimum, limit, size } = this.props.pager;
            const maximum = Math.min(currentMinimum + limit - 1, size);
            const singlePage = (1 === currentMinimum) && (maximum === size);
            return !singlePage;
        }
    }

    ControlPanelX2Many.defaultProps = {};
    ControlPanelX2Many.props = {
        cp_content: { type: Object, optional: 1 },
        pager: Object,
    };
    ControlPanelX2Many.template = 'web.ControlPanelX2Many';

    return ControlPanelX2Many;
});