From 086405344e7302d9f7b243ba0c30d55131aeb3fe Mon Sep 17 00:00:00 2001 From: XavierDo Date: Mon, 7 Jan 2019 10:56:19 +0000 Subject: [IMP] mail, hr_holidays: use leaves to compute im_status When on leave, the im_status can be either leave_online or leave_offline. This will allow to display a specific icon and a default message when the user is not at the office. The leave can have an out of office message. This message will be displayed in the chat window instead of the user ooo message, and the end date of the leave will be displayed too. Technical details. Right now the im_status access leaves directly to know if a user is on leave or not. An index has been added to optimise this request (thanks to rco). A solution to optimise this would be to compute part of the information in a cron. Task: 1856205 --- .../mail/static/src/js/models/threads/dm_chat.js | 30 ++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'addons/mail/static/src/js/models/threads/dm_chat.js') diff --git a/addons/mail/static/src/js/models/threads/dm_chat.js b/addons/mail/static/src/js/models/threads/dm_chat.js index 21fb72e91ae..fb524515193 100644 --- a/addons/mail/static/src/js/models/threads/dm_chat.js +++ b/addons/mail/static/src/js/models/threads/dm_chat.js @@ -1,8 +1,10 @@ odoo.define('mail.model.DMChat', function (require) { "use strict"; -var core = require('web.core'); var TwoUserChannel = require('mail.model.TwoUserChannel'); + +var core = require('web.core'); + var _t = core._t; /** @@ -20,7 +22,8 @@ var DMChat = TwoUserChannel.extend({ * @param {integer} params.data.direct_partner[0].id * @param {string} params.data.direct_partner[0].im_status * @param {string} params.data.direct_partner[0].name - * @param {string} [params.data.direct_partner[0].out_of_office_message=''] + * @param {string} [params.data.direct_partner[0].out_of_office_message] + * @param {string} [params.data.direct_partner[0].out_of_office_date_end] */ init: function (params) { this._super.apply(this, arguments); @@ -54,14 +57,31 @@ var DMChat = TwoUserChannel.extend({ return this._directPartnerID; }, /** + * Get the out of office info + * + * @override {mail.model.AbstractThread} + * @returns {string|undefined} + */ + getOutOfOfficeInfo: function () { + if (!this._outOfOfficeDateEnd) { + return undefined; + } + var currentDate = new Date(); + var date = new Date(this._outOfOfficeDateEnd); + var options = { day: 'numeric', month: 'short' }; + if (currentDate.getFullYear() !== date.getFullYear()) { + options.year = 'numeric'; + } + var formattedDate = date.toLocaleDateString(window.navigator.language, options); + return _.str.sprintf(_t("Out of office until %s"), formattedDate); + }, + /** * Get the out of office message of the thread * + * @override {mail.model.AbstractThread} * @returns {string} */ getOutOfOfficeMessage: function () { - if (this._outOfOfficeMessage === '') { - return undefined; - } return this._outOfOfficeMessage; }, /** -- cgit v1.2.3