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)

11.0 backport of 12.0 #28474

issue found when checking opw-1904029
  • Loading branch information...
nle-odoo committed Nov 8, 2018
1 parent e5c8071 commit d617cea73e0b74e01acbb19cd827d04744cfc3a9
@@ -129,6 +129,22 @@ var Chatter = Widget.extend(chat_mixin, {
this.composer.clear_composer();
}
},
/**
* @private
*/
_disableComposer: function () {
if (this.composer) {
this.composer.$(".o_composer_button_send").prop('disabled', true);
}
},
/**
* @private
*/
_enableComposer: function () {
if (this.composer) {
this.composer.$(".o_composer_button_send").prop('disabled', false);
}
},
_openComposer: function (options) {
var self = this;
var old_composer = this.composer;
@@ -156,7 +172,10 @@ var Chatter = Widget.extend(chat_mixin, {
self.composer.focus();
}
self.composer.on('post_message', self, function (message) {
self.fields.thread.postMessage(message).then(function () {
self._disableComposer();
self.fields.thread.postMessage(message).fail(function () {
self._enableComposer();
}).then(function () {
self._closeComposer(true);
if (self.postRefresh === 'always' || (self.postRefresh === 'recipients' && message.partner_ids.length)) {
self.trigger_up('reload');
@@ -479,13 +479,10 @@ var BasicComposer = Widget.extend(chat_mixin, {
},
send_message: function () {
var $button = this.$('.o_composer_button_send');
if (this.is_empty() || !this.do_check_attachment_upload()) {
return;
}
$button.prop('disabled', true);
clearTimeout(this.canned_timeout);
var self = this;
this.preprocess_message().then(function (message) {
@@ -680,6 +680,60 @@ 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 bus = new Bus();
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
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) {
console.log([route, args]);
if (args.method === 'message_get_suggested_recipients') {
return $.when({2: []});
}
return this._super(route, args);
},
intercepts: {
get_messages: function (ev) {
ev.stopPropagation();
ev.data.callback($.when([]));
},
post_message: function (ev) {
ev.stopPropagation();
assert.ok(form.$('.o_composer_button_send').prop("disabled"),
"Send button should be disabled when a message is being sent");
ev.data.callback($.Deferred().reject());
},
get_bus: function (ev) {
ev.stopPropagation();
ev.data.callback(bus);
},
},
});
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.destroy();
});
QUnit.test('chatter: post a message and switch in edit mode', function (assert) {
assert.expect(5);

0 comments on commit d617cea

Please sign in to comment.