summaryrefslogtreecommitdiff
path: root/addons/mail/static/src
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2016-01-26 12:18:35 +0100
committerAaron Bohy <aab@odoo.com>2016-02-01 11:31:09 +0100
commitef77e6821a00b5646e68aee00fa2c3e26704f21e (patch)
treea46c1acfef89235b4ee8ae2c9177924f9fbe7921 /addons/mail/static/src
parent68c928aca73104fe29d0dd3e48aa1055d2780aae (diff)
[FIX] mail: systray: move Inbox counter to its own item
Clicking on that item redirects to the Inbox in Discuss. The messaging menu's counter is now the number of conversations (public or private channels, dm and livechat) in which there is at least one unread message. Moreover, it is emphasized when one of those conversations is a chat. Also make mass-mailing channels available through the messaging menu (for consistency as its counter takes those channels into account) and allow to open them in chat windows without input.
Diffstat (limited to 'addons/mail/static/src')
-rw-r--r--addons/mail/static/src/js/chat_manager.js22
-rw-r--r--addons/mail/static/src/js/chat_window.js1
-rw-r--r--addons/mail/static/src/js/client_action.js2
-rw-r--r--addons/mail/static/src/js/systray.js61
-rw-r--r--addons/mail/static/src/js/window_manager.js3
-rw-r--r--addons/mail/static/src/less/client_action.less23
-rw-r--r--addons/mail/static/src/xml/chat_window.xml2
-rw-r--r--addons/mail/static/src/xml/systray.xml15
8 files changed, 76 insertions, 53 deletions
diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js
index 75b1819ddd2..74db804b7fc 100644
--- a/addons/mail/static/src/js/chat_manager.js
+++ b/addons/mail/static/src/js/chat_manager.js
@@ -25,6 +25,7 @@ var channels = [];
var channels_preview_def;
var channel_defs = {};
var chat_unread_counter = 0;
+var unread_conversation_counter = 0;
var emojis = [];
var emoji_substitutions = {};
var needaction_counter = 0;
@@ -146,7 +147,7 @@ function add_message (data, options) {
channel.hidden = false;
chat_manager.bus.trigger('new_channel', channel);
}
- if (!msg.author_id || msg.author_id[0] !== session.partner_id) {
+ if (channel.type !== 'static' && !msg.is_author) {
if (options.increment_unread) {
update_channel_unread_counter(channel, channel.unread_counter+1);
}
@@ -176,6 +177,7 @@ function make_message (data) {
date: moment(time.str_to_datetime(data.date)),
message_type: data.message_type,
subtype_description: data.subtype_description,
+ is_author: data.author_id && data.author_id[0] === session.partner_id,
is_note: data.is_note,
attachment_ids: data.attachment_ids,
subject: data.subject,
@@ -240,11 +242,7 @@ function make_message (data) {
}
// Don't redirect on author clicked of self-posted messages
- if (msg.author_id && msg.author_id[0] === session.partner_id) {
- msg.author_redirect = false;
- } else {
- msg.author_redirect = true;
- }
+ msg.author_redirect = !msg.is_author;
// Compute the avatar_url
if (msg.author_id && msg.author_id[0]) {
@@ -449,8 +447,13 @@ function fetch_document_messages (ids, options) {
}
function update_channel_unread_counter (channel, counter) {
+ if (channel.unread_counter > 0 && counter === 0) {
+ unread_conversation_counter = Math.max(0, unread_conversation_counter-1);
+ } else if (channel.unread_counter === 0 && counter > 0) {
+ unread_conversation_counter++;
+ }
if (channel.is_chat) {
- chat_unread_counter = chat_unread_counter - channel.unread_counter + counter;
+ chat_unread_counter = Math.max(0, chat_unread_counter - channel.unread_counter + counter);
}
channel.unread_counter = counter;
chat_manager.bus.trigger("update_channel_unread_counter", channel);
@@ -807,6 +810,9 @@ var chat_manager = {
get_chat_unread_counter: function () {
return chat_unread_counter;
},
+ get_unread_conversation_counter: function () {
+ return unread_conversation_counter;
+ },
get_last_seen_message: function (channel) {
if (channel.last_seen_message_id) {
@@ -814,7 +820,7 @@ var chat_manager = {
var msg = _.findWhere(messages, {id: channel.last_seen_message_id});
if (msg) {
var i = _.sortedIndex(messages, msg, 'id') + 1;
- while (i < messages.length && messages[i].author_id && messages[i].author_id[0] === session.partner_id) {
+ while (i < messages.length && messages[i].is_author) {
msg = messages[i];
i++;
}
diff --git a/addons/mail/static/src/js/chat_window.js b/addons/mail/static/src/js/chat_window.js
index 95ac9dd8897..3568dd697cb 100644
--- a/addons/mail/static/src/js/chat_window.js
+++ b/addons/mail/static/src/js/chat_window.js
@@ -28,6 +28,7 @@ return Widget.extend({
this.options = _.defaults(options || {}, {
display_stars: true,
placeholder: _t("Say something"),
+ input_less: false,
});
this.unread_msgs = unread_msgs || 0;
this.is_hidden = false;
diff --git a/addons/mail/static/src/js/client_action.js b/addons/mail/static/src/js/client_action.js
index e0acd48236b..a2b4a400a1b 100644
--- a/addons/mail/static/src/js/client_action.js
+++ b/addons/mail/static/src/js/client_action.js
@@ -360,7 +360,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
// Hide 'detach' button in static channels
self.$buttons
.find('.o_mail_chat_button_detach')
- .toggle(channel.type !== "static" && !channel.mass_mailing);
+ .toggle(channel.type !== "static");
// Hide 'invite', 'unsubscribe' and 'settings' buttons in static channels and DM
self.$buttons
.find('.o_mail_chat_button_invite, .o_mail_chat_button_unsubscribe, .o_mail_chat_button_settings')
diff --git a/addons/mail/static/src/js/systray.js b/addons/mail/static/src/js/systray.js
index 21d22a12eac..3929947acbb 100644
--- a/addons/mail/static/src/js/systray.js
+++ b/addons/mail/static/src/js/systray.js
@@ -10,6 +10,42 @@ var chat_manager = require('mail.chat_manager');
var QWeb = core.qweb;
/**
+ * Menu item appended in the systray part of the navbar, redirects to the Inbox in Discuss
+ * Also displays the needaction counter (= Inbox counter)
+ */
+var InboxItem = Widget.extend({
+ template:'mail.chat.InboxItem',
+ events: {
+ "click": "on_click",
+ },
+ start: function () {
+ this.$needaction_counter = this.$('.o_notification_counter');
+ chat_manager.bus.on("update_needaction", this, this.update_counter);
+ this.update_counter();
+ return this._super();
+ },
+ update_counter: function () {
+ var counter = chat_manager.get_needaction_counter();
+ this.$needaction_counter.text(counter);
+ this.$el.toggleClass('o_no_notification', !counter);
+ },
+ on_click: function (event) {
+ event.preventDefault();
+ this.discuss_redirect();
+ },
+ discuss_redirect: _.debounce(function () {
+ var self = this;
+ var discuss_ids = chat_manager.get_discuss_ids();
+ this.do_action(discuss_ids.action_id, {clear_breadcrumbs: true}).then(function () {
+ self.trigger_up('hide_app_switcher');
+ core.bus.trigger('change_menu_section', discuss_ids.menu_id);
+ });
+ }, 1000, true),
+});
+
+SystrayMenu.Items.push(InboxItem);
+
+/**
* Menu item appended in the systray part of the navbar
*
* The menu item indicates the counter of needactions + unread messages in chat channels. When
@@ -24,13 +60,11 @@ var MessagingMenu = Widget.extend({
"click .o_filter_button": "on_click_filter_button",
"click .o_new_message": "on_click_new_message",
"click .o_mail_channel_preview": "on_click_channel",
- "click .o_redirect_to_discuss": "on_click_redirect_to_discuss",
},
start: function () {
this.$filter_buttons = this.$('.o_filter_button');
this.$channels_preview = this.$('.o_mail_navbar_dropdown_channels');
this.filter = false;
- chat_manager.bus.on("update_needaction", this, this.update_counter);
chat_manager.bus.on("update_channel_unread_counter", this, this.update_counter);
this.update_counter();
return this._super();
@@ -39,9 +73,10 @@ var MessagingMenu = Widget.extend({
return this.$el.hasClass('open');
},
update_counter: function () {
- var counter = chat_manager.get_needaction_counter() + chat_manager.get_chat_unread_counter();
+ var counter = chat_manager.get_unread_conversation_counter();
this.$('.o_notification_counter').text(counter);
this.$el.toggleClass('o_no_notification', !counter);
+ this.$el.toggleClass('o_unread_chat', !!chat_manager.get_chat_unread_counter());
if (this.is_open()) {
this.render_channels_preview();
}
@@ -52,15 +87,13 @@ var MessagingMenu = Widget.extend({
if (self.filter === 'chat') {
return channel.is_chat;
} else if (self.filter === 'channels') {
- return !channel.is_chat && channel.type !== 'static' && !channel.mass_mailing;
+ return !channel.is_chat && channel.type !== 'static';
} else {
- return channel.type !== 'static' && !channel.mass_mailing;
+ return channel.type !== 'static';
}
});
- // Update inbox counter and display spinner while waiting for channels preview
- var inbox_counter = chat_manager.get_needaction_counter();
- this.$('.o_inbox_counter').html(inbox_counter ? '(' + inbox_counter + ')' : '');
+ // Display spinner while waiting for channels preview
this.$channels_preview.html(QWeb.render('mail.chat.Spinner'));
chat_manager.get_channels_preview(channels).then(function (channels_preview) {
@@ -111,18 +144,6 @@ var MessagingMenu = Widget.extend({
chat_manager.bus.trigger('detach_channel', channel);
}
},
- on_click_redirect_to_discuss: function (event) {
- event.preventDefault();
- this.discuss_redirect();
- },
- discuss_redirect: _.debounce(function () {
- var self = this;
- var discuss_ids = chat_manager.get_discuss_ids();
- this.do_action(discuss_ids.action_id, {clear_breadcrumbs: true}).then(function () {
- self.trigger_up('hide_app_switcher');
- core.bus.trigger('change_menu_section', discuss_ids.menu_id);
- });
- }, 1000, true),
});
SystrayMenu.Items.push(MessagingMenu);
diff --git a/addons/mail/static/src/js/window_manager.js b/addons/mail/static/src/js/window_manager.js
index 65488129884..3ee3007a7ea 100644
--- a/addons/mail/static/src/js/window_manager.js
+++ b/addons/mail/static/src/js/window_manager.js
@@ -39,11 +39,12 @@ function open_chat (session) {
var chat_session = _.findWhere(chat_sessions, {id: session.id});
if (!chat_session) {
var prefix = !session.is_chat ? "#" : "";
+ var options = { input_less: session.mass_mailing };
chat_session = {
id: session.id,
uuid: session.uuid,
name: session.name,
- window: new ExtendedChatWindow(web_client, session.id, prefix + session.name, session.is_folded, session.unread_counter),
+ window: new ExtendedChatWindow(web_client, session.id, prefix + session.name, session.is_folded, session.unread_counter, options),
};
chat_session.window.on("close_chat_session", null, function () {
close_chat(chat_session);
diff --git a/addons/mail/static/src/less/client_action.less b/addons/mail/static/src/less/client_action.less
index d7b72cb7453..c4b28874358 100644
--- a/addons/mail/static/src/less/client_action.less
+++ b/addons/mail/static/src/less/client_action.less
@@ -283,6 +283,9 @@
display: none;
}
}
+ &.o_unread_chat > a > i {
+ color: @odoo-brand-optional;
+ }
&.open .o_mail_navbar_dropdown {
.o-flex-display();
@@ -308,19 +311,16 @@
height: 50px;
}
- .o_filter_button,
- .o_new_message,
- .o_redirect_to_discuss {
- .btn-link;
- padding: 5px;
- }
-
.o_mail_navbar_dropdown_top {
.o-flex-display();
.o-flex(0, 0, auto);
justify-content: space-between;
border-bottom: 1px solid lightgray;
+ .o_filter_button, .o_new_message {
+ .btn-link;
+ padding: 5px;
+ }
.o_filter_button {
color: @odoo-main-color-muted;
&:hover, &.o_selected {
@@ -332,15 +332,6 @@
}
}
}
- .o_mail_navbar_dropdown_bottom {
- .o-flex(0, 0, auto);
- border-top: 1px solid lightgray;
- height: 35px;
- .o_redirect_to_discuss {
- height: 100%;
- width: 100%;
- }
- }
.o_mail_navbar_dropdown_channels {
.o-flex(0, 1, auto);
diff --git a/addons/mail/static/src/xml/chat_window.xml b/addons/mail/static/src/xml/chat_window.xml
index eb003cd59cd..7bb854a274c 100644
--- a/addons/mail/static/src/xml/chat_window.xml
+++ b/addons/mail/static/src/xml/chat_window.xml
@@ -11,7 +11,7 @@
</div>
<div class="o_chat_content">
</div>
- <div class="o_chat_input">
+ <div t-if='!widget.options.input_less' class="o_chat_input">
<input t-att-placeholder="widget.options.placeholder"/>
</div>
</div>
diff --git a/addons/mail/static/src/xml/systray.xml b/addons/mail/static/src/xml/systray.xml
index 247096b3b6e..4a987fdf992 100644
--- a/addons/mail/static/src/xml/systray.xml
+++ b/addons/mail/static/src/xml/systray.xml
@@ -1,9 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
+ <t t-name="mail.chat.InboxItem">
+ <li class="o_mail_navbar_item">
+ <a href="#" title="Inbox">
+ <i class="fa fa-at"/> <span class="o_notification_counter"/>
+ </a>
+ </li>
+ </t>
+
<t t-name="mail.chat.MessagingMenu">
<li class="o_mail_navbar_item">
- <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="Messages" href="#">
+ <a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="Conversations" href="#">
<i class="fa fa-comments"/> <span class="o_notification_counter"/>
</a>
<ul class="o_mail_navbar_dropdown dropdown-menu" role="menu">
@@ -16,11 +24,6 @@
<button type="button" class="btn btn-sm o_new_message"> New message </button>
</li>
<li class="o_mail_navbar_dropdown_channels"/>
- <li class="o_mail_navbar_dropdown_bottom">
- <button type="button" class="btn o_redirect_to_discuss">
- @Inbox <span class="o_inbox_counter"/>
- </button>
- </li>
</ul>
</li>
</t>