[MOV] hr: separate chat_mixin and employee code

In preparation of the next commit, separate the chat mixin from the
employee js code into appropriate files

Task ID: 2575379
This commit is contained in:
William Braeckman
2021-08-03 07:17:30 +00:00
parent 47269e8203
commit 27aacca0db
3 changed files with 39 additions and 31 deletions
+2 -1
View File
@@ -50,7 +50,8 @@
'assets': {
'web.assets_backend': [
'hr/static/src/scss/hr.scss',
'hr/static/src/js/chat.js',
'hr/static/src/js/chat_mixin.js',
'hr/static/src/js/hr_employee.js',
'hr/static/src/js/language.js',
'hr/static/src/js/m2x_avatar_employee.js',
'hr/static/src/js/standalone_m2o_avatar_employee.js',
+36
View File
@@ -0,0 +1,36 @@
odoo.define('hr.chat_mixin', function (require) {
"use strict";
const { Component } = owl;
// CHAT MIXIN
const ChatMixin = {
/**
* @override
*/
_render: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
var $chat_button = self.$el.find('.o_employee_chat_btn');
$chat_button.off('click').on('click', self._onOpenChat.bind(self));
});
},
destroy: function () {
if (this.$el) {
this.$el.find('.o_employee_chat_btn').off('click');
}
return this._super();
},
_onOpenChat: function (ev) {
ev.preventDefault();
ev.stopImmediatePropagation();
const env = Component.env;
env.messaging.openChat({ employeeId: this.state.data.id });
return true;
},
};
return ChatMixin;
});
@@ -11,36 +11,7 @@ odoo.define('hr.employee_chat', function (require) {
var KanbanRenderer = require('web.KanbanRenderer');
var KanbanRecord = require('web.KanbanRecord');
const { Component } = owl;
// CHAT MIXIN
var ChatMixin = {
/**
* @override
*/
_render: function () {
var self = this;
return this._super.apply(this, arguments).then(function () {
var $chat_button = self.$el.find('.o_employee_chat_btn');
$chat_button.off('click').on('click', self._onOpenChat.bind(self));
});
},
destroy: function () {
if (this.$el) {
this.$el.find('.o_employee_chat_btn').off('click');
}
return this._super();
},
_onOpenChat: function (ev) {
ev.preventDefault();
ev.stopImmediatePropagation();
const env = Component.env;
env.messaging.openChat({ employeeId: this.state.data.id });
return true;
},
};
const ChatMixin = require('hr.chat_mixin');
// USAGE OF CHAT MIXIN IN FORM VIEWS
var EmployeeFormRenderer = FormRenderer.extend(ChatMixin);