summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/models/threads/dm_chat.js
diff options
context:
space:
mode:
authorXavierDo <xdo@odoo.com>2019-01-07 10:56:19 +0000
committerXavierDo <xdo@odoo.com>2019-02-07 12:53:03 +0000
commit086405344e7302d9f7b243ba0c30d55131aeb3fe (patch)
tree2d8390249e17d6aebbcc1e83f49ed03976cf52b9 /addons/mail/static/src/js/models/threads/dm_chat.js
parentc21d200285ebeb646b8e5be6ba233f96d9714c6f (diff)
[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
Diffstat (limited to 'addons/mail/static/src/js/models/threads/dm_chat.js')
-rw-r--r--addons/mail/static/src/js/models/threads/dm_chat.js30
1 files changed, 25 insertions, 5 deletions
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;
},
/**