summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2018-11-07 13:26:56 +0000
committerNicolas Lempereur <nle@odoo.com>2018-11-09 08:10:24 +0000
commit9799dd294dfb201f2f256151120d38580e34e0ec (patch)
treee394d6199643db69147a16551b7c1589da6f7455
parent7754416cd8a6484dd7d449f302909d7ef70ffe0f (diff)
[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
-rw-r--r--addons/mail/static/src/js/chatter.js15
-rw-r--r--addons/mail/static/src/js/composers/basic_composer.js1
-rw-r--r--addons/mail/static/src/js/composers/chatter_composer.js2
-rw-r--r--addons/mail/static/tests/chatter_tests.js52
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
@@ -183,6 +183,12 @@ var Chatter = Widget.extend({
this.$('.btn').prop('disabled', true); // disable buttons
},
/**
+ * @private
+ */
+ _disableComposer: function () {
+ this.$(".o_composer_button_send").prop('disabled', true);
+ },
+ /**
* Discard changes on the record.
*
* @private
@@ -222,6 +228,12 @@ var Chatter = Widget.extend({
/**
* @private
*/
+ _enableComposer: function () {
+ this.$(".o_composer_button_send").prop('disabled', false);
+ },
+ /**
+ * @private
+ */
_openAttachments: function () {
var self = this;
this.fields.attachments = new AttachmentBox(this, this.record);
@@ -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: '<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([]);
+ }
+ 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);