[IMP] mail: store composer when switching channels

This commit is contained in:
Ravi Gadhia
2017-09-08 08:44:04 +02:00
committed by David Monjoie
parent 168ca86592
commit 44a3c72e0f
2 changed files with 42 additions and 1 deletions
@@ -173,6 +173,7 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
this.throttled_renderSidebar = _.throttle(this.renderSidebar.bind(this), 100, { leading: false });
this.notification_bar = (window.Notification && window.Notification.permission === "default");
this.selected_message = null;
this.composerStates = {};
},
willStart: function () {
@@ -409,15 +410,31 @@ var ChatAction = Widget.extend(ControlPanelMixin, {
});
},
storeComposerState: function (channel) {
var composer = channel.mass_mailing ? this.extended_composer : this.basic_composer;
this.composerStates[channel.uuid] = composer.getState();
composer.clear_composer();
},
restoreComposerState: function (channel) {
var composer = channel.mass_mailing ? this.extended_composer : this.basic_composer;
var composerState = this.composerStates[channel.uuid];
if (composerState) {
composer.setState(composerState);
}
},
set_channel: function (channel) {
var self = this;
// Store scroll position of previous channel
if (this.channel) {
this.channels_scrolltop[this.channel.id] = this.thread.get_scrolltop();
this.storeComposerState(this.channel);
}
var new_channel_scrolltop = this.channels_scrolltop[channel.id];
this.channel = channel;
this.restoreComposerState(this.channel);
this.messages_separator_position = undefined; // reset value on channel change
this.unread_counter = this.channel.unread_counter;
this.last_seen_message_id = this.channel.last_seen_message_id;
+25 -1
View File
@@ -514,6 +514,13 @@ var BasicComposer = Widget.extend(chat_mixin, {
this.clear_composer();
},
getState: function () {
return {
attachments: this.get('attachment_ids'),
text: this.$input.val(),
};
},
// Events
on_click_add_attachment: function () {
this.$('input.o_input_file').click();
@@ -525,6 +532,11 @@ var BasicComposer = Widget.extend(chat_mixin, {
this.$input.focus();
},
setState: function (state) {
this.set('attachment_ids', state.attachments);
this.$input.val(state.text);
},
/**
* Send the message on ENTER, but go to new line on SHIFT+ENTER
*/
@@ -810,7 +822,15 @@ var ExtendedComposer = BasicComposer.extend({
return message;
});
},
clear_composer: function () {
this._super.apply(this, arguments);
this.$subject_input.val('');
},
getState: function () {
var state = this._super.apply(this, arguments);
state.subject = this.$subject_input.val();
return state;
},
should_send: function () {
return false;
},
@@ -824,6 +844,10 @@ var ExtendedComposer = BasicComposer.extend({
set_subject: function(subject) {
this.$('.o_composer_subject input').val(subject);
},
setState: function (state) {
this._super.apply(this, arguments);
this.set_subject(state.subject);
},
});
return {