-
Notifications
You must be signed in to change notification settings - Fork 24.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IMP] mail: closed chat window using keyboard ESC key #16138
[IMP] mail: closed chat window using keyboard ESC key #16138
Conversation
a16f35c
to
808b176
Compare
808b176
to
78ac1c4
Compare
237d852
to
e8094d5
Compare
c68a1a2
to
394728e
Compare
394728e
to
c68a1a2
Compare
1429258
to
c8640c3
Compare
c8640c3
to
003e298
Compare
set_focus:function() { | ||
var self = this; | ||
// Need Timeout: Text selected and first click on chat window should set focus to composer again | ||
setTimeout(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why need setTimeout ?
a7bf407
to
f7afd8f
Compare
29c65ed
to
dd52db1
Compare
dd52db1
to
9421e15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is quite good, but I requested a few changes, to make it even better. Please ping me when you are done
event.stopPropagation(); | ||
this.mention_manager.reset_suggestions(); | ||
} else { | ||
this.trigger("keyup_escape"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should do a trigger_up, not a trigger (we want to catch the event somewhere up the component tree)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, the name of the event is not so good. rename keyup_escape into 'escape_pressed'
@@ -39,6 +39,11 @@ return ChatWindow.extend({ | |||
basic_composer.mention_set_enabled_commands(commands); | |||
basic_composer.mention_set_prefetched_partners(partners); | |||
}); | |||
basic_composer.on('keyup_escape', self, function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not bind an event handler on the basic composer. The event should come from a trigger_up, so, it should be bound in the custom_events key on top of this file.
|
||
var upKeyEvent = jQuery.Event( "keyup", {which: 27}); | ||
var close_chat = chat_window.$el.find('.o_composer_input').trigger(upKeyEvent); | ||
assert.equal(!chat_window.folded, true, "Closed chat Window"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that you should write assert.strictEqual(chat_window.folded, false, "chat window should be closed")
assert.equal(chat_window.$input.is(":focus"), true, "Focused"); | ||
|
||
var upKeyEvent = jQuery.Event( "keyup", {which: 27}); | ||
var close_chat = chat_window.$el.find('.o_composer_input').trigger(upKeyEvent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use chat_window.$(...) instead of chat_window.$el.find
@@ -819,5 +821,41 @@ QUnit.test('followers widget: do not display follower duplications', function (a | |||
form.destroy(); | |||
}); | |||
|
|||
QUnit.test('chatter: close chat window using ESCAPE key', function (assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test should not be named with 'chatter': it is a chat window test, so maybe, just "chatter: close chat window using ESCAPE key"
Also, this is not a chatter_test, so it should go into a new file, chat_window_test.js
93c4a35
to
4b5db84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I requested some other small changes. once it is done, it should be green
@@ -9,6 +9,9 @@ var composer = require('mail.composer'); | |||
|
|||
return ChatWindow.extend({ | |||
template: "mail.ExtendedChatWindow", | |||
custom_events: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be in chat_window.js instead.
@@ -43,6 +46,11 @@ return ChatWindow.extend({ | |||
} | |||
return $.when(this._super(), def); | |||
}, | |||
_onEscapePressed: function(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this should also be in chat_window.js
@@ -140,6 +141,12 @@ return Widget.extend({ | |||
this.trigger("fold_channel", this.channel_id, this.folded); | |||
} | |||
}, | |||
_onChatWindowClicked: function() { | |||
var selectObj = window.getSelection(); | |||
if (selectObj.toString().length === 0){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here, you should replace this line with:
if (selectObj.anchorOffset === selectObj.focusOffset){
|
||
QUnit.module('mail', {}, function () { | ||
|
||
QUnit.test('chat_window: close using ESCAPE key', function (assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a line QUnit.module('chat_window'); above this line. This is useful to separate properly the tests when looking at them in the logs
data: {}, | ||
}); | ||
|
||
var chat_window = new ChatWindow(parent, 1, "user", false, messages, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename chat_window into chatWindow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, we cannot test that the window is closed at the end, but we can test that the close_chat_session event has been triggered. You can add these lines:
chatWindow.on('close_chat_session', null, function () {
assert.ok(true, "chat window should trigger a close event");
});
(and you will need to change the assert.expect accordingly)
chat_window.appendTo($('#qunit-fixture')); | ||
|
||
chat_window.thread.$el.trigger("click"); | ||
assert.equal(chat_window.$input.is(":focus"), true, "Focused"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use assert.strictEqual
var upKeyEvent = jQuery.Event( "keyup", {which: 27}); | ||
chat_window.$('.o_composer_input').trigger(upKeyEvent); | ||
assert.strictEqual(chat_window.folded, false, "Closed chat Window"); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you forgot to destroy the chatwindow at the end of the test. This is a memory leak, but is easily fixed: add chatWindow.destroy(); just before the end of the test
4b5db84
to
00cb949
Compare
00cb949
to
6221a63
Compare
merged in master (commits are squashed: 6ea3b8d) |
Description of the issue/feature this PR addresses:
Task: https://www.odoo.com/web#id=32316&view_type=form&model=project.task&action=333&active_id=131&menu_id=4720
Pad: https://pad.odoo.com/p/r.65cde9c930c29052ed5b151ba0b419c0
Current behavior before PR:
Desired behavior after PR is merged:
--
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr