[FIX] mail: chatter: keep mentions
Message's body is kept when switching from 'New message' to 'Log a note' since
rev. f35b48aa. However, mentionned partners or channels were lost. This rev.
makes sure to preserve both message's body and mentions when switching between
composers.
This commit is contained in:
@@ -451,7 +451,6 @@ var ChatterComposer = composer.BasicComposer.extend({
|
||||
record_name: false,
|
||||
is_log: false,
|
||||
internal_subtypes: [],
|
||||
default_body: '',
|
||||
});
|
||||
if (this.options.is_log) {
|
||||
this.options.send_text = _('Log');
|
||||
@@ -468,13 +467,6 @@ var ChatterComposer = composer.BasicComposer.extend({
|
||||
return $.when(this._super.apply(this, arguments), this.message_get_suggested_recipients());
|
||||
},
|
||||
|
||||
start: function () {
|
||||
var self = this;
|
||||
return this._super().then(function () {
|
||||
self.$input.val(self.options.default_body);
|
||||
});
|
||||
},
|
||||
|
||||
should_send: function () {
|
||||
return false;
|
||||
},
|
||||
@@ -920,6 +912,7 @@ var Chatter = form_common.AbstractField.extend({
|
||||
is_log: options && options.is_log,
|
||||
record_name: this.record_name,
|
||||
default_body: old_composer && old_composer.$input.val(),
|
||||
default_mention_selections: old_composer && old_composer.mention_get_listener_selections(),
|
||||
});
|
||||
this.composer.on('input_focused', this, function () {
|
||||
this.composer.mention_set_prefetched_partners(this.mention_suggestions || []);
|
||||
|
||||
@@ -27,6 +27,9 @@ var accented_letters_mapping = {
|
||||
' ': '[()\\[\\]]',
|
||||
};
|
||||
|
||||
var MENTION_PARTNER_DELIMITER = '@';
|
||||
var MENTION_CHANNEL_DELIMITER = '#';
|
||||
|
||||
// The MentionManager allows the Composer to register listeners. For each
|
||||
// listener, it detects if the user is currently typing a mention (starting by a
|
||||
// given delimiter). If so, if fetches mention suggestions and renders them. On
|
||||
@@ -106,7 +109,7 @@ var MentionManager = Widget.extend({
|
||||
* @param {string} [redirect_classname] the classname of the <a> wrapping the mention
|
||||
*/
|
||||
register: function (listener) {
|
||||
this.listeners.push(_.extend(listener, {
|
||||
this.listeners.push(_.defaults(listener, {
|
||||
selection: [],
|
||||
}));
|
||||
},
|
||||
@@ -123,6 +126,14 @@ var MentionManager = Widget.extend({
|
||||
return listener ? listener.selection : [];
|
||||
},
|
||||
|
||||
get_listener_selections: function () {
|
||||
var selections = {};
|
||||
_.each(this.listeners, function (listener) {
|
||||
selections[listener.delimiter] = listener.selection;
|
||||
});
|
||||
return selections;
|
||||
},
|
||||
|
||||
proposition_navigation: function (keycode) {
|
||||
var $active = this.$('.o_mention_proposition.active');
|
||||
if (keycode === $.ui.keyCode.ENTER) { // selecting proposition
|
||||
@@ -333,6 +344,8 @@ var BasicComposer = Widget.extend({
|
||||
mention_fetch_limit: 8,
|
||||
mention_partners_restricted: false, // set to true to only suggest prefetched partners
|
||||
send_text: _('Send'),
|
||||
default_body: '',
|
||||
default_mention_selections: {},
|
||||
});
|
||||
this.context = this.options.context;
|
||||
|
||||
@@ -344,16 +357,18 @@ var BasicComposer = Widget.extend({
|
||||
// Mention
|
||||
this.mention_manager = new MentionManager(this);
|
||||
this.mention_manager.register({
|
||||
delimiter: '@',
|
||||
delimiter: MENTION_PARTNER_DELIMITER,
|
||||
fetch_callback: this.mention_fetch_partners.bind(this),
|
||||
model: 'res.partner',
|
||||
redirect_classname: 'o_mail_redirect',
|
||||
selection: this.options.default_mention_selections[MENTION_PARTNER_DELIMITER],
|
||||
});
|
||||
this.mention_manager.register({
|
||||
delimiter: '#',
|
||||
delimiter: MENTION_CHANNEL_DELIMITER,
|
||||
fetch_callback: this.mention_fetch_channels.bind(this),
|
||||
model: 'mail.channel',
|
||||
redirect_classname: 'o_channel_redirect',
|
||||
selection: this.options.default_mention_selections[MENTION_CHANNEL_DELIMITER],
|
||||
});
|
||||
|
||||
// Emojis
|
||||
@@ -372,6 +387,7 @@ var BasicComposer = Widget.extend({
|
||||
this.$input.focus(function () {
|
||||
self.trigger('input_focused');
|
||||
});
|
||||
this.$input.val(this.options.default_body);
|
||||
dom_utils.autoresize(this.$input, {parent: this, min_height: this.options.input_min_height});
|
||||
|
||||
// Attachments
|
||||
@@ -635,6 +651,9 @@ var BasicComposer = Widget.extend({
|
||||
mention_set_prefetched_partners: function (prefetched_partners) {
|
||||
this.mention_prefetched_partners = prefetched_partners;
|
||||
},
|
||||
mention_get_listener_selections: function () {
|
||||
return this.mention_manager.get_listener_selections();
|
||||
},
|
||||
|
||||
// Others
|
||||
is_empty: function () {
|
||||
|
||||
Reference in New Issue
Block a user