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:
 "Message with failed delivery is not removed" (result: "")
 "Send button should be enabled after failure" (result: true)

issue found when checking opw-1904029
closes #28475
  • Loading branch information...
nle-odoo committed Nov 7, 2018
1 parent 4795943 commit 42bc55b5094e560266c84b63e025399b4aef5e87
@@ -182,6 +182,14 @@ var Chatter = Widget.extend({
_disableChatter: function () {
this.$('.btn').prop('disabled', true); // disable buttons
},
/**
* @private
*/
_disableComposer: function () {
if (this._composer) {
this._composer.$(".o_composer_button_send").prop('disabled', true);
}
},
/**
* Discard changes on the record.
*
@@ -219,6 +227,14 @@ var Chatter = Widget.extend({
_enableChatter: function () {
this.$('.btn').prop('disabled', false); // enable buttons
},
/**
* @private
*/
_enableComposer: function () {
if (this._composer) {
this._composer.$(".o_composer_button_send").prop('disabled', false);
}
},
/**
* @private
*/
@@ -268,7 +284,10 @@ var Chatter = Widget.extend({
}
self._composer.on('post_message', self, function (messageData) {
self._discardOnReload(messageData).then(function () {
self.fields.thread.postMessage(messageData).then(function () {
self._disableComposer();
self.fields.thread.postMessage(messageData).fail(function () {
self._enableComposer();
}).then(function () {
self._closeComposer(true);
if (self._reloadAfterPost(messageData)) {
self.trigger_up('reload');
@@ -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
@@ -839,6 +839,61 @@ 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");
return $.Deferred().reject();
}
if (args.method === 'message_format') {
return $.when([{
author_id: ["42", "Me"],
model: 'partner',
}]);
}
return this._super(route, args);
},
intercepts: {
get_messages: function (ev) {
ev.stopPropagation();
ev.data.callback($.when([]));
},
},
});
form.$('.o_chatter_button_new_message').click();
assert.notOk(form.$('.o_composer_button_send').prop('disabled'),
"Send button should be enabled when posting a message");
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",
"Message with failed delivery is not removed");
assert.notOk(form.$('.o_composer_button_send').prop('disabled'),
"Send button should be enabled after failure");
form.$('.oe_chatter .o_composer_text_field:first()').val("My first message");
form.destroy();
});
QUnit.test('chatter: receive notif when document is open', function (assert) {
assert.expect(2);

0 comments on commit 42bc55b

Please sign in to comment.