From 9799dd294dfb201f2f256151120d38580e34e0ec Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 7 Nov 2018 13:26:56 +0000 Subject: [PATCH] [FIX] mail: enable composer after message sent c5dc0b2f39 disabled send button on composer sent. But this is only needed for chatter composer, other composers directly send the message and are not refreshed asynchronously. So for other composer, the send button worked one time but then was disabled and the only way to sent was ENTER (on basic composer) or CTRL+ENTER (on extended composer). With this fix, disabling the button is done only for chatter composer. Also the behavior of not clearing the message if there was an error is introduced back. Without change in code, added test fails with: "Should keep unsent message in the composer on failure" (result: "") "Send button should be re-enabled on message post failure" (result: true) issue found when checking opw-1904029 closes #28475 --- addons/mail/static/src/js/chatter.js | 15 ++++++ .../static/src/js/composers/basic_composer.js | 1 - .../src/js/composers/chatter_composer.js | 2 +- addons/mail/static/tests/chatter_tests.js | 52 ++++++++++++++++--- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/addons/mail/static/src/js/chatter.js b/addons/mail/static/src/js/chatter.js index 2f2e1a0e770..000353d1219 100644 --- a/addons/mail/static/src/js/chatter.js +++ b/addons/mail/static/src/js/chatter.js @@ -182,6 +182,12 @@ var Chatter = Widget.extend({ _disableChatter: function () { this.$('.btn').prop('disabled', true); // disable buttons }, + /** + * @private + */ + _disableComposer: function () { + this.$(".o_composer_button_send").prop('disabled', true); + }, /** * Discard changes on the record. * @@ -219,6 +225,12 @@ var Chatter = Widget.extend({ _enableChatter: function () { this.$('.btn').prop('disabled', false); // enable buttons }, + /** + * @private + */ + _enableComposer: function () { + this.$(".o_composer_button_send").prop('disabled', false); + }, /** * @private */ @@ -268,6 +280,7 @@ var Chatter = Widget.extend({ } self._composer.on('post_message', self, function (messageData) { self._discardOnReload(messageData).then(function () { + self._disableComposer(); self.fields.thread.postMessage(messageData).then(function () { self._closeComposer(true); if (self._reloadAfterPost(messageData)) { @@ -275,6 +288,8 @@ var Chatter = Widget.extend({ } else if (messageData.attachment_ids.length) { self.trigger_up('reload', {fieldNames: ['message_attachment_count']}); } + }).fail(function () { + self._enableComposer(); }); }); }); diff --git a/addons/mail/static/src/js/composers/basic_composer.js b/addons/mail/static/src/js/composers/basic_composer.js index 0e4d62232e2..a6cdb39e2de 100644 --- a/addons/mail/static/src/js/composers/basic_composer.js +++ b/addons/mail/static/src/js/composers/basic_composer.js @@ -390,7 +390,6 @@ var BasicComposer = Widget.extend({ return; } - this.$(".o_composer_button_send").prop("disabled", true); clearTimeout(this._cannedTimeout); var self = this; this._preprocessMessage().then(function (message) { diff --git a/addons/mail/static/src/js/composers/chatter_composer.js b/addons/mail/static/src/js/composers/chatter_composer.js index d1a990b31e4..cda91eab205 100644 --- a/addons/mail/static/src/js/composers/chatter_composer.js +++ b/addons/mail/static/src/js/composers/chatter_composer.js @@ -45,7 +45,7 @@ var ChatterComposer = BasicComposer.extend({ * * @override */ - clearComposerOnSend: function () {}, + _clearComposerOnSend: function () {}, //-------------------------------------------------------------------------- // Private diff --git a/addons/mail/static/tests/chatter_tests.js b/addons/mail/static/tests/chatter_tests.js index d4d10f71746..b379bc9050b 100644 --- a/addons/mail/static/tests/chatter_tests.js +++ b/addons/mail/static/tests/chatter_tests.js @@ -820,12 +820,6 @@ QUnit.test('chatter: post a message disable the send button', function(assert) { } return this._super(route, args); }, - intercepts: { - get_messages: function (ev) { - ev.stopPropagation(); - ev.data.callback($.when([])); - }, - }, }); form.$('.o_chatter_button_new_message').click(); @@ -839,6 +833,52 @@ QUnit.test('chatter: post a message disable the send button', function(assert) { form.destroy(); }); +QUnit.test('chatter: post message failure keep message', function(assert) { + assert.expect(4); + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + services: this.services, + arch: '
' + + '' + + '' + + '' + + '
' + + '' + + '
' + + '
', + res_id: 2, + session: {}, + mockRPC: function (route, args) { + if (args.method === 'message_get_suggested_recipients') { + return $.when({2: []}); + } + if (args.method === 'message_post') { + assert.ok(form.$('.o_composer_button_send').prop("disabled"), + "Send button should be disabled when a message is being sent"); + // simulate failure + return $.Deferred().reject(); + } + if (args.method === 'message_format') { + return $.when([]); + } + return this._super(route, args); + }, + }); + + form.$('.o_chatter_button_new_message').click(); + assert.notOk(form.$('.o_composer_button_send').prop('disabled'), + "Send button should be enabled initially"); + form.$('.oe_chatter .o_composer_text_field:first()').val("My first message"); + form.$('.oe_chatter .o_composer_button_send').click(); + assert.strictEqual(form.$('.o_composer_text_field').val(), "My first message", + "Should keep unsent message in the composer on failure"); + assert.notOk(form.$('.o_composer_button_send').prop('disabled'), + "Send button should be re-enabled on message post failure"); + form.destroy(); +}); + QUnit.test('chatter: receive notif when document is open', function (assert) { assert.expect(2);