summaryrefslogtreecommitdiff
path: root/hr_organizational_chart/static/src/js/organizational_view.js
blob: a0942a3c0ee29f5245829a716c50a7e3c88a7ee1 (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
odoo.define('hr_organizational_chart.view_chart', function (require){
"use strict";
var AbstractAction = require('web.AbstractAction');
var ajax = require('web.ajax');
var core = require('web.core');
var rpc = require('web.rpc');
var ActionManager = require('web.ActionManager');
var _t = core._t;


var EmployeeOrganizationalChart =  AbstractAction.extend({

    contentTemplate: 'OrganizationalEmployeeChart',
    events: {
        'click img': '_getChild_data',
        'click .employee_name': 'view_employee',
    },

    init: function(parent, context) {
        this._super(parent, context);
        this.renderEmployeeDetails();
    },
    renderEmployeeDetails: function (){
        var employee_id = 1
        var self = this;
        this._rpc({
            route: '/get/parent/employee',
        }).then(function (result) {
            self.parent_len = result[1];
            $.ajax({
                url: '/get/parent/child',
                type: 'POST',
                data: JSON.stringify(result[0]),
                success: function (value) {
                        $('#o_parent_employee').append(value);
                        },
            });

        });

    },
    _getChild_data: function(events){
        console.log(events)
        if(events.target.parentElement.className){
            var self = this
            this.id = events.target.parentElement.id;
            this.check_child =  $( "#"+this.id+".o_level_1" );
            if (this.check_child[0]){
                this.colspan_td = this.check_child[0].parentElement.parentElement
                this.tbody_child = this.colspan_td.parentElement.parentElement
                var child_length = this.tbody_child.children.length
                if (child_length == 1){
                    this._rpc({
                        route: '/get/parent/colspan',
                        params: {
                            emp_id: parseInt(this.id),
                        },
                    }).then(function (col_val){
                        if (col_val){
                            self.colspan_td.colSpan = col_val;
                        }
                    });
                    this._rpc({
                        route: '/get/child/data',
                        params: {
                            click_id: parseInt(this.id),
                        },
                    }).then(function (result){
                        if (result){
                        $(result).appendTo(self.tbody_child);
                        }
                    });
                }
                else{
                    for(var i = 0;i < 3; i++){
                        this.tbody_child.children[1].remove();
                    }
                    self.colspan_td.colSpan = 2;
                }

            }
        }
    },
    view_employee: function(ev){
        if (ev.target.parentElement.className){
            var id = parseInt(ev.target.parentElement.parentElement.children[0].id)
            this.do_action({
            name: _t("Employee"),
            type: 'ir.actions.act_window',
            res_model: 'hr.employee',
            res_id: id,
            view_mode: 'form',
            views: [[false, 'form']],
            })
        }
    },
});
    core.action_registry.add('organization_dashboard', EmployeeOrganizationalChart);

});