From 1ca3b3df3421961caec3b747a364071c80f5c7da Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 17:14:58 +0700 Subject: initial commit --- .../static/src/js/organizational_view.js | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 hr_organizational_chart/static/src/js/organizational_view.js (limited to 'hr_organizational_chart/static/src/js') diff --git a/hr_organizational_chart/static/src/js/organizational_view.js b/hr_organizational_chart/static/src/js/organizational_view.js new file mode 100644 index 0000000..a0942a3 --- /dev/null +++ b/hr_organizational_chart/static/src/js/organizational_view.js @@ -0,0 +1,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); + +}); -- cgit v1.2.3