summaryrefslogtreecommitdiff
path: root/addons/website_event_meet/static/src/js/customize_options.js
blob: 4d8ccbd3ab7e90c71deedec48fb82d601abfd492 (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
60
61
62
63
64
65
66
67
68
69
odoo.define('website_event_meet.set_customize_options', function (require) {
"use strict";

let EventSpecificOptions = require('website_event.set_customize_options').EventSpecificOptions;

EventSpecificOptions.include({
    xmlDependencies: (EventSpecificOptions.prototype.xmlDependencies || [])
        .concat([
            '/website_event_meet/static/src/xml/customize_options.xml',
        ]),

    events: _.extend({}, EventSpecificOptions.prototype.events, {
        'change #allow-room-creation': '_onAllowRoomCreationChange',
    }),

    start: function () {
        this.$allowRoomCreationInput = this.$('#allow-room-creation');
        this._super.apply(this, arguments);
    },

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

    _onAllowRoomCreationChange: function () {
        let checkboxValue = this.$allowRoomCreationInput.is(':checked');
        this._toggleAllowRoomCreation(checkboxValue);
    },

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

    _getCheckboxFields: function () {
        let fields = this._super();
        fields = _.union(fields, ['meeting_room_allow_creation']);
        return fields;
    },

    _getCheckboxFieldMatch: function (checkboxField) {
        if (checkboxField === 'meeting_room_allow_creation') {
            return this.$allowRoomCreationInput;
        }
        return this._super(checkboxField);
    },

    _initCheckboxCallback: function (rpcData) {
        this._super(rpcData);
        if (rpcData[0]['meeting_room_allow_creation']) {
            let submenuInput = this._getCheckboxFieldMatch('meeting_room_allow_creation');
            submenuInput.attr('checked', 'checked');
        }
    },

    _toggleAllowRoomCreation: async function (val) {
        await this._rpc({
            model: this.modelName,
            method: 'write',
            args: [[this.eventId], {
                meeting_room_allow_creation: val
            }],
        });

        this._reloadEventPage();
    },

});

});