From 44a3c72e0fbf1fbbe4a6cdbd4016466d5b9a1039 Mon Sep 17 00:00:00 2001 From: Ravi Gadhia Date: Wed, 30 Aug 2017 19:07:47 +0530 Subject: [PATCH] [IMP] mail: store composer when switching channels --- addons/mail/static/src/js/client_action.js | 17 ++++++++++++++ addons/mail/static/src/js/composer.js | 26 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/addons/mail/static/src/js/client_action.js b/addons/mail/static/src/js/client_action.js index 85acb3118f7..a27790f9629 100644 --- a/addons/mail/static/src/js/client_action.js +++ b/addons/mail/static/src/js/client_action.js @@ -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; diff --git a/addons/mail/static/src/js/composer.js b/addons/mail/static/src/js/composer.js index f4ba98696a5..2782ff11442 100644 --- a/addons/mail/static/src/js/composer.js +++ b/addons/mail/static/src/js/composer.js @@ -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 {