summaryrefslogtreecommitdiff
path: root/addons/website_sale/static/src/js/website_sale_payment.js
blob: 4d6abd9848d836c4e33da6a233c91f5a5862518e (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
odoo.define('website_sale.payment', function (require) {
'use strict';

var publicWidget = require('web.public.widget');

publicWidget.registry.WebsiteSalePayment = publicWidget.Widget.extend({
    selector: '#wrapwrap:has(#checkbox_cgv)',
    events: {
        'change #checkbox_cgv': '_onCGVCheckboxClick',
    },

    /**
     * @override
     */
    start: function () {
        this.$checkbox = this.$('#checkbox_cgv');
        this.$payButton = $('button#o_payment_form_pay');
        this.$checkbox.trigger('change');
        return this._super.apply(this, arguments);
    },

    //--------------------------------------------------------------------------
    // Private
    //--------------------------------------------------------------------------

    /**
     * @private
     */
    _adaptPayButton: function () {
        var disabledReasons = this.$payButton.data('disabled_reasons') || {};
        disabledReasons.cgv = !this.$checkbox.prop('checked');
        this.$payButton.data('disabled_reasons', disabledReasons);

        this.$payButton.prop('disabled', _.contains(disabledReasons, true));
    },

    //--------------------------------------------------------------------------
    // Handlers
    //--------------------------------------------------------------------------

    /**
     * @private
     */
    _onCGVCheckboxClick: function () {
        this._adaptPayButton();
    },
});
});