Permalink
Browse files

[FIX] mail: enable composer after message sent

c5dc0b2 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
  • Loading branch information...
nle-odoo committed Nov 7, 2018
1 parent 7aa2136 commit 0ab187c1ea751c1fa097b1563b064f8d4eefdf79
@@ -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,13 +280,16 @@ 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)) {
self.trigger_up('reload');
} else if (messageData.attachment_ids.length) {
self.trigger_up('reload', {fieldNames: ['message_attachment_count']});
}
}).fail(function () {
self._enableComposer();
});
});
});
@@ -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) {
@@ -45,7 +45,7 @@ var ChatterComposer = BasicComposer.extend({
*
* @override
*/
clearComposerOnSend: function () {},
_clearComposerOnSend: function () {},
//--------------------------------------------------------------------------
// Private
@@ -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,55 @@ 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: '<form string="Partners">' +
'<sheet>' +
'<field name="foo"/>' +
'</sheet>' +
'<div class="oe_chatter">' +
'<field name="message_ids" widget="mail_thread"/>' +
'</div>' +
'</form>',
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([{
author_id: ["42", "Me"],
model: 'partner',
}]);
}
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);

0 comments on commit 0ab187c

Please sign in to comment.