summaryrefslogtreecommitdiff
path: root/hr_organizational_chart/static/js/hr_org_chart.js
blob: 58bc15a6ea6f2852977a7614df21827934e2b33f (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
var employee_data = [];

var nodeTemplate = function(data) {
      return `
        <span class="office">${data.office}</span>
        <div class="title">${data.name}</div>
        <div class="content">${data.title}</div>
      `;
    };

odoo.define("hr_org_chart_employee.hr_org_chart", function (require) {
  "use strict";

  var core = require('web.core');
  var session = require('web.session');
  var ajax = require('web.ajax');
  var Widget = require('web.Widget');
  var QWeb = core.qweb;
  var _t = core._t;
  var AbstractAction = require('web.AbstractAction');
  var _lt = core._lt;

  var OrgChartDepartment = AbstractAction.extend({
    events: {
        'click .nodes,.node': 'view_employee',
        },
    init: function(parent, context){
      this._super(parent, context);
        var self = this;
        if (context.tag == 'employee_organization_chart') {
            this._rpc({
            route: '/get/employees',
        }).then(function (result) {
            self._rpc({
                model: 'hr.organizational.chart',
                method: 'get_employee_data',
                args: [result],
            }, []).then(function(values){
                employee_data = values;
                self.render();
                self.href = window.location.href;
            });
            });
        }
    },
    willStart: function() {
      return $.when(ajax.loadLibs(this), this._super());
    },
    start: function() {
      var self = this;
      return this._super();
    },
    render: function() {
        var super_render = this._super;
        var self = this;
        var org_chart = QWeb.render('hr_organizational_chart.org_chart_template', {
            widget: self,
        });
        $(".o_control_panel").addClass("o_hidden");
        $(org_chart).prependTo(self.$el);
        return org_chart;
    },
    reload: function () {
      window.location.href = this.href;
    },
    view_employee: function(ev){
        if (ev.target.attributes[1]){
            var id = parseInt(ev.target.attributes[1].nodeValue)
            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('employee_organization_chart', OrgChartDepartment);
  window.reload()

  return OrgChartDepartment;


});