summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/js/composers/basic_composer.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/mail/static/src/js/composers/basic_composer.js')
-rw-r--r--addons/mail/static/src/js/composers/basic_composer.js55
1 files changed, 28 insertions, 27 deletions
diff --git a/addons/mail/static/src/js/composers/basic_composer.js b/addons/mail/static/src/js/composers/basic_composer.js
index 9def912612c..72936152ae5 100644
--- a/addons/mail/static/src/js/composers/basic_composer.js
+++ b/addons/mail/static/src/js/composers/basic_composer.js
@@ -128,7 +128,7 @@ var BasicComposer = Widget.extend({
.on('update_typing_partners', this, this._onUpdateTypingPartners);
// Mention
- this._mentionManager.prependTo(this.$('.o_composer'));
+ var prependPromise = this._mentionManager.prependTo(this.$('.o_composer'));
// Drag-Drop files
// Allowing body to detect dragenter and dragleave for display
@@ -137,7 +137,7 @@ var BasicComposer = Widget.extend({
$body.on('dragleave.' + this._dropZoneNS, this._onBodyFileDragLeave.bind(this));
$body.on("dragover." + this._dropZoneNS, this._onBodyFileDragover.bind(this));
$body.on("drop." + this._dropZoneNS, this._onBodyFileDrop.bind(this));
- return this._super();
+ return Promise.all([this._super(), prependPromise]);
},
destroy: function () {
$("body").off('dragleave.' + this._dropZoneNS);
@@ -236,7 +236,7 @@ var BasicComposer = Widget.extend({
* displayed to the user. If none of them match, then it will fetch for more
* partner suggestions (@see _mentionFetchPartners).
*
- * @param {$.Deferred<Object[]>} prefetchedPartners list of list of
+ * @param {Promise<Object[]>} prefetchedPartners list of list of
* prefetched partners.
*/
mentionSetPrefetchedPartners: function (prefetchedPartners) {
@@ -299,20 +299,21 @@ var BasicComposer = Widget.extend({
/**
* @private
* @param {string} search
- * @returns {$.Deferred<Object[]>}
+ * @returns {Promise<Object[]>}
*/
_mentionGetCannedResponses: function (search) {
var self = this;
- var def = $.Deferred();
- clearTimeout(this._cannedTimeout);
- this._cannedTimeout = setTimeout(function () {
- var cannedResponses = self.call('mail_service', 'getCannedResponses');
- var matches = fuzzy.filter(utils.unaccent(search), _.pluck(cannedResponses, 'source'));
- var indexes = _.pluck(matches.slice(0, self.options.mentionFetchLimit), 'index');
- def.resolve(_.map(indexes, function (index) {
- return cannedResponses[index];
- }));
- }, 500);
+ var def = new Promise(function (resolve, reject) {
+ clearTimeout(self._cannedTimeout);
+ self._cannedTimeout = setTimeout(function () {
+ var cannedResponses = self.call('mail_service', 'getCannedResponses');
+ var matches = fuzzy.filter(utils.unaccent(search), _.pluck(cannedResponses, 'source'));
+ var indexes = _.pluck(matches.slice(0, self.options.mentionFetchLimit), 'index');
+ resolve(_.map(indexes, function (index) {
+ return cannedResponses[index];
+ }));
+ }, 500);
+ });
return def;
},
/**
@@ -346,7 +347,7 @@ var BasicComposer = Widget.extend({
*/
_mentionFetchPartners: function (search) {
var self = this;
- return $.when(this._mentionPrefetchedPartners).then(function (prefetchedPartners) {
+ return Promise.resolve(this._mentionPrefetchedPartners).then(function (prefetchedPartners) {
// filter prefetched partners with the given search string
var suggestions = [];
var limit = self.options.mentionFetchLimit;
@@ -371,7 +372,7 @@ var BasicComposer = Widget.extend({
{ limit: limit, search: search }
);
}
- return $.when(suggestions).then(function (suggestions) {
+ return Promise.resolve(suggestions).then(function (suggestions) {
//add im_status on suggestions
_.each(suggestions, function (suggestionsSet) {
_.each(suggestionsSet, function (suggestion) {
@@ -387,27 +388,27 @@ var BasicComposer = Widget.extend({
* @param {string} model
* @param {string} method
* @param {Object} kwargs
- * @return {$.Deferred}
+ * @return {Promise}
*/
_mentionFetchThrottled: function (model, method, kwargs) {
var self = this;
// Delays the execution of the RPC to prevent unnecessary RPCs when the user is still typing
- var def = $.Deferred();
- clearTimeout(this.mentionFetchTimer);
- this.mentionFetchTimer = setTimeout(function () {
- return self._rpc({model: model, method: method, kwargs: kwargs})
+ return new Promise(function (resolve, reject) {
+ clearTimeout(self.mentionFetchTimer);
+ self.mentionFetchTimer = setTimeout(function () {
+ return self._rpc({model: model, method: method, kwargs: kwargs})
.then(function (results) {
- def.resolve(results);
+ resolve(results);
});
- }, this.MENTION_THROTTLE);
- return def;
+ }, self.MENTION_THROTTLE);
+ });
},
/**
* @private
- * @returns {$.Deferred}
+ * @returns {Promise}
*/
_preprocessMessage: function () {
- // Return a deferred as this function is extended with asynchronous
+ // Return a promise as this function is extended with asynchronous
// behavior for the chatter composer
//Removing unwanted extra spaces from message
@@ -420,7 +421,7 @@ var BasicComposer = Widget.extend({
var commands = this.options.commandsEnabled ?
this._mentionManager.getListenerSelection('/') :
[];
- return $.when({
+ return Promise.resolve({
content: this._mentionManager.generateLinks(value),
attachment_ids: _.pluck(this.get('attachment_ids'), 'id'),
partner_ids: _.uniq(_.pluck(this._mentionManager.getListenerSelection('@'), 'id')),