summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/composer.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/composer.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/composer.js')
-rw-r--r--addons/mail/static/src/js/composer.js15
1 files changed, 7 insertions, 8 deletions
diff --git a/addons/mail/static/src/js/composer.js b/addons/mail/static/src/js/composer.js
index 2e2aaa66f74..06675ec3902 100644
--- a/addons/mail/static/src/js/composer.js
+++ b/addons/mail/static/src/js/composer.js
@@ -1,7 +1,6 @@
odoo.define('mail.composer', function (require) {
"use strict";
-var chat_mixin = require('mail.chat_mixin');
var DocumentViewer = require('mail.DocumentViewer');
var utils = require('mail.utils');
@@ -385,7 +384,7 @@ var MentionManager = Widget.extend({
});
-var BasicComposer = Widget.extend(chat_mixin, {
+var BasicComposer = Widget.extend({
template: "mail.ChatComposer",
events: {
"keydown .o_composer_input": "_onKeydown",
@@ -482,7 +481,7 @@ var BasicComposer = Widget.extend(chat_mixin, {
self.trigger('input_focused');
});
this.$input.html(this.options.default_body);
- this.$input.css('min-height', this.options.input_min_height)
+ this.$input.css('min-height', this.options.input_min_height);
// Attachments
$(window).on(this.fileupload_id, this.on_attachment_loaded);
@@ -728,7 +727,7 @@ var BasicComposer = Widget.extend(chat_mixin, {
},
// remove mention when user try to edit or remove it.
_removeMention: function (event) {
- if (window.getSelection().anchorNode.parentNode.tagName == 'A') {
+ if (window.getSelection().anchorNode.parentNode.tagName === 'A') {
document.getElementById(window.getSelection().anchorNode.parentNode.id).remove();
}
},
@@ -790,8 +789,8 @@ var BasicComposer = Widget.extend(chat_mixin, {
var self = this;
var def = $.Deferred();
clearTimeout(this.canned_timeout);
- this.canned_timeout = setTimeout(function() {
- var canned_responses = self._getCannedResponses();
+ this.canned_timeout = setTimeout(function () {
+ var canned_responses = self.call('chat_manager', 'getCannedResponses');
var matches = fuzzy.filter(utils.unaccent(search), _.pluck(canned_responses, 'source'));
var indexes = _.pluck(matches.slice(0, self.options.mention_fetch_limit), 'index');
def.resolve(_.map(indexes, function (i) {
@@ -876,7 +875,7 @@ var BasicComposer = Widget.extend(chat_mixin, {
_onEmojiButtonClick: function () {
if (!this.$emojisContainer) { // lazy rendering
this.$emojisContainer = $(QWeb.render('mail.ChatComposer.emojis', {
- emojis: this._getEmojis(),
+ emojis: this.call('chat_manager', 'getEmojis'),
}));
}
if (this.$emojisContainer.parent().length) {
@@ -938,7 +937,7 @@ var BasicComposer = Widget.extend(chat_mixin, {
*/
_onEmojiImageClick: function (ev) {
this.$input.html(this.$input.html() + " " + $(ev.currentTarget).data('emoji') + " ");
- this._placeCaretAtEnd(this.$input[0])
+ this._placeCaretAtEnd(this.$input[0]);
this._hideEmojis();
},
});