summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/extended_chat_window.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-12-21 12:29:50 +0100
committerAlexandre Kühn <alex.e.kuhn@gmail.com>2018-02-01 14:51:58 +0100
commit02ec09cb1c3e2d7bc7968f40c18f2208d7f3f498 (patch)
tree10d91136786b13666e78cfb94b12f1609d6f883d /addons/mail/static/src/js/extended_chat_window.js
parent0cd656b5af38051df3f7d6319e99705150bb1cd8 (diff)
[REF][IMP] *: mail js refactoring
This commit improves the JS code of the mail module, which comes maily from the new coding guidelines and the addition of "JS services". JS services are important objects that do not fit well in the component tree, such as chat_manager or ajax. The benefits of JS services are improved readability of the code, reduced coupling, and more testable modules. In particular, discuss was hard to Summary of the changes: - ClientAction has been renamed into Discuss - Clear instantiation of chatManager - New coding guidelines in most mail modules - JS Services can interact with each other - Chat Manager and Window Manager are services - Window Manager renamed to Chat Window Manager - bus.bus is now encapsulated in Bus Service (a service) - The test infrastructure has been tweaked with JS Services - Chat Mixin has been removed A future improvement would be to translate some 'trigger' into 'trigger_up'.
Diffstat (limited to 'addons/mail/static/src/js/extended_chat_window.js')
-rw-r--r--addons/mail/static/src/js/extended_chat_window.js34
1 files changed, 17 insertions, 17 deletions
diff --git a/addons/mail/static/src/js/extended_chat_window.js b/addons/mail/static/src/js/extended_chat_window.js
index 2163c28dd92..a8aa5673b81 100644
--- a/addons/mail/static/src/js/extended_chat_window.js
+++ b/addons/mail/static/src/js/extended_chat_window.js
@@ -1,9 +1,6 @@
odoo.define('mail.ExtendedChatWindow', function (require) {
"use strict";
-var core = require('web.core');
-
-var chat_manager = require('mail.chat_manager');
var ChatWindow = require('mail.ChatWindow');
var composer = require('mail.composer');
@@ -19,27 +16,29 @@ return ChatWindow.extend({
this.$el.addClass('o_thread_less');
this.$('.o_chat_search_input input')
.autocomplete({
- source: function(request, response) {
- chat_manager.search_partner(request.term, 10).done(response);
+ source: function (request, response) {
+ self.call('chat_manager', 'searchPartner', request.term, 10).done(response);
},
- select: function(event, ui) {
+ select: function (event, ui) {
self.trigger('open_dm_session', ui.item.id);
},
})
.focus();
} else if (!self.options.input_less) {
- var basic_composer = new composer.BasicComposer(self, {mention_partners_restricted: true, isMini: true});
- basic_composer.on('post_message', self, function (message) {
- this.trigger('post_message', message, this.channel_id);
+ var basicComposer = new composer.BasicComposer(self, {mention_partners_restricted: true, isMini: true});
+ basicComposer.on('post_message', self, function (message) {
+ self.call('chat_manager', 'postMessage', message, {
+ channelID: self.channel_id,
+ });
});
- basic_composer.once('input_focused', self, function () {
- var channel = chat_manager.get_channel(this.channel_id);
- var commands = chat_manager.get_commands(channel);
- var partners = chat_manager.get_mention_partner_suggestions(channel);
- basic_composer.mention_set_enabled_commands(commands);
- basic_composer.mention_set_prefetched_partners(partners);
+ basicComposer.once('input_focused', self, function () {
+ var channel = self.call('chat_manager', 'getChannel', self.channel_id);
+ var commands = self.call('chat_manager', 'getCommands', channel);
+ var partners = self.call('chat_manager', 'getMentionPartnerSuggestions', channel);
+ basicComposer.mention_set_enabled_commands(commands);
+ basicComposer.mention_set_prefetched_partners(partners);
});
- def = basic_composer.replace(self.$('.o_chat_composer'));
+ def = basicComposer.replace(self.$('.o_chat_composer'));
}
return $.when(this._super(), def);
},
@@ -49,7 +48,8 @@ return ChatWindow.extend({
event.stopPropagation();
},
on_reverse_breadcrumb: function () {
- chat_manager.bus.trigger('client_action_open', false);
+ var chatBus = this.call('chat_manager', 'getChatBus');
+ chatBus.trigger('discuss_open', false);
},
on_click_expand: _.debounce(function (event) {
event.preventDefault();