summaryrefslogtreecommitdiff
path: root/addons/hr/static/src/js/many2one_avatar_employee.js
blob: 0d5a245aaa270c80cf7cda788f3e2cb742a0e169 (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
odoo.define('hr.Many2OneAvatarEmployee', function (require) {
    "use strict";

    // This module defines a variant of the Many2OneAvatarUser field widget,
    // to support many2one fields pointing to 'hr.employee'. It also defines the
    // kanban version of this widget.
    //
    // Usage:
    //   <field name="employee_id" widget="many2one_avatar_employee"/>

    const fieldRegistry = require('web.field_registry');
    const { Many2OneAvatarUser, KanbanMany2OneAvatarUser } = require('mail.Many2OneAvatarUser');

    const { Component } = owl;

    const Many2OneAvatarEmployeeMixin = {
        supportedModels: ['hr.employee', 'hr.employee.public'],

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

        /**
         * @override
         */
        async _onAvatarClicked(ev) {
            ev.stopPropagation(); // in list view, prevent from opening the record
            const env = Component.env;
            await env.messaging.openChat({ employeeId: this.value.res_id });
        }
    };

    const Many2OneAvatarEmployee = Many2OneAvatarUser.extend(Many2OneAvatarEmployeeMixin);
    const KanbanMany2OneAvatarEmployee = KanbanMany2OneAvatarUser.extend(Many2OneAvatarEmployeeMixin);

    fieldRegistry.add('many2one_avatar_employee', Many2OneAvatarEmployee);
    fieldRegistry.add('kanban.many2one_avatar_employee', KanbanMany2OneAvatarEmployee);

    return {
        Many2OneAvatarEmployee,
        KanbanMany2OneAvatarEmployee,
    };
});