From 29d8576b0a9e41b922489e193ae4bb32e0b30fad Mon Sep 17 00:00:00 2001 From: Damien Bouvy <dbo@odoo.com> Date: Mon, 5 Sep 2016 14:48:37 +0200 Subject: [PATCH] [FIX] mail: remove duplicate code There already is a redirect implementation in the chat_manager which closely matches the on_redirect implementation in chatter.js, however the former has the advantage of calling get_formview_id to ensure that the view is correct. This fixes a faulty behaviour when some models are referenced from chatter message using data attribute data-oe-model and data-oe-id. For example, linking invoices in the chatter would always open them with the 'vendor invoice' view; from this revision on the correct view will be used (assuming get_formview_id is implemented on the model). The default behaviour of the chat_manager when a user clicks on a partner record is to open a channel if the partner has a user then return a callback passed as a parameter (usually to open the channel as a popup or in the discuss app). To keep the old behaviour of the chatter followers list widget (i.e. open the partner form when clicking on a follower), a small change has to be made on the redirect implementation: when no callback is provided, do not create the channel (instead a returning an empty callback). --- addons/mail/static/src/js/chat_manager.js | 6 +++--- addons/mail/static/src/js/chatter.js | 15 ++------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 2cf6090871f1..dbadbb47bb9f 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -936,9 +936,9 @@ var chat_manager = { if (res_model === "res.partner") { var domain = [["partner_id", "=", res_id]]; UserModel.call("search", [domain]).then(function (user_ids) { - if (user_ids.length && user_ids[0] !== session.uid) { - self.create_channel(res_id, 'dm').then(dm_redirection_callback || function () {}); - } else if (!user_ids.length) { + if (user_ids.length && user_ids[0] !== session.uid && dm_redirection_callback) { + self.create_channel(res_id, 'dm').then(dm_redirection_callback); + } else { redirect_to_document(res_model, res_id); } }); diff --git a/addons/mail/static/src/js/chatter.js b/addons/mail/static/src/js/chatter.js index 646951df1639..0b06d300679a 100644 --- a/addons/mail/static/src/js/chatter.js +++ b/addons/mail/static/src/js/chatter.js @@ -310,7 +310,7 @@ var Chatter = form_common.AbstractField.extend({ this.followers = this.field_manager.fields.message_follower_ids; if (this.followers) { this.$('.o_chatter_topbar').append(this.followers.$el); - this.followers.on('redirect', this, this.on_redirect); + this.followers.on('redirect', chat_manager, chat_manager.redirect); this.followers.on('followers_update', this, this.on_followers_update); } @@ -324,7 +324,7 @@ var Chatter = form_common.AbstractField.extend({ this.thread.on('toggle_star_status', this, function (message_id) { chat_manager.toggle_star_status(message_id); }); - this.thread.on('redirect', this, this.on_redirect); + this.thread.on('redirect', chat_manager, chat_manager.redirect); this.thread.on('redirect_to_channel', this, this.on_channel_redirect); this.ready = $.Deferred(); @@ -405,17 +405,6 @@ var Chatter = form_common.AbstractField.extend({ }); }, - on_redirect: function (res_model, res_id) { - this.do_action({ - type:'ir.actions.act_window', - view_type: 'form', - view_mode: 'form', - res_model: res_model, - views: [[false, 'form']], - res_id: res_id, - }); - }, - on_followers_update: function (followers) { this.mention_suggestions = []; var self = this; -- GitLab