summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js
blob: c8f128569a69617496e6d8ec11288b7a8e8365b3 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
odoo.define('mail/static/src/models/suggested_recipient_info/suggested_recipient_info.js', function (require) {
'use strict';

const { registerNewModel } = require('mail/static/src/model/model_core.js');
const { attr, many2one } = require('mail/static/src/model/model_field.js');

function factory(dependencies) {

    class SuggestedRecipientInfo extends dependencies['mail.model'] {

        //----------------------------------------------------------------------
        // private
        //----------------------------------------------------------------------

        /**
         * @private
         * @returns {string}
         */
        _computeEmail() {
            return this.partner && this.partner.email || this.email;
        }

        /**
         * Prevents selecting a recipient that does not have a partner.
         *
         * @private
         * @returns {boolean}
         */
        _computeIsSelected() {
            return this.partner ? this.isSelected : false;
        }

        /**
         * @private
         * @returns {string}
         */
        _computeName() {
            return this.partner && this.partner.nameOrDisplayName || this.name;
        }

    }

    SuggestedRecipientInfo.fields = {
        /**
         * Determines the email of `this`. It serves as visual clue when
         * displaying `this`, and also serves as default partner email when
         * creating a new partner from `this`.
         */
        email: attr({
            compute: '_computeEmail',
            dependencies: [
                'email',
                'partnerEmail',
            ],
        }),
        /**
         * Determines whether `this` will be added to recipients when posting a
         * new message on `this.thread`.
         */
        isSelected: attr({
            compute: '_computeIsSelected',
            default: true,
            dependencies: [
                'isSelected',
                'partner',
            ],
        }),
        /**
         * Determines the name of `this`. It serves as visual clue when
         * displaying `this`, and also serves as default partner name when
         * creating a new partner from `this`.
         */
        name: attr({
            compute: '_computeName',
            dependencies: [
                'name',
                'partnerNameOrDisplayName',
            ],
        }),
        /**
         * Determines the optional `mail.partner` associated to `this`.
         */
        partner: many2one('mail.partner'),
        /**
         * Serves as compute dependency.
         */
        partnerEmail: attr({
            related: 'partner.email'
        }),
        /**
         * Serves as compute dependency.
         */
        partnerNameOrDisplayName: attr({
            related: 'partner.nameOrDisplayName'
        }),
        /**
         * Determines why `this` is a suggestion for `this.thread`. It serves as
         * visual clue when displaying `this`.
         */
        reason: attr(),
        /**
         * Determines the `mail.thread` concerned by `this.`
         */
        thread: many2one('mail.thread', {
            inverse: 'suggestedRecipientInfoList',
        }),
    };

    SuggestedRecipientInfo.modelName = 'mail.suggested_recipient_info';

    return SuggestedRecipientInfo;
}

registerNewModel('mail.suggested_recipient_info', factory);

});