summaryrefslogtreecommitdiff
path: root/addons/purchase/static/src/js/purchase_toaster_button.js
blob: 542858188dccffd5262f2a5c56830c321aa49faa (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
odoo.define('purchase.ToasterButton', function (require) {
    'use strict';

    const widgetRegistry = require('web.widget_registry');
    const Widget = require('web.Widget');


    const ToasterButton = Widget.extend({
        template: 'purchase.ToasterButton',
        xmlDependencies: ['/purchase/static/src/xml/purchase_toaster_button.xml'],
        events: Object.assign({}, Widget.prototype.events, {
            'click .fa-info-circle': '_onClickButton',
        }),

        init: function (parent, data, node) {
            this._super(...arguments);
            this.button_name = node.attrs.button_name;
            this.title = node.attrs.title;
            this.id = data.res_id;
            this.model = data.model;
        },

        //--------------------------------------------------------------------------
        // Handlers
        //--------------------------------------------------------------------------
        _onClickButton: function (ev) {
            this._rpc({
                method: this.button_name,
                model: this.model,
                args: [[this.id]],
            }).then(res => {
                if (res) {
                    this.do_notify(false, res.toast_message);
                }
            })
        },
    });

    widgetRegistry.add('toaster_button', ToasterButton);

    return ToasterButton;
});