View Full Version : Window.close() vs userInitiated close action?

11 Feb 2010, 6:28 AM

I have a dialog Ext.Window that has some buttons in the bbar and a [X] close tool button in the top right.

If the user clicks on any of the buttons in the bbar, I do some stuff and close the Ext.Window. If the user closes the Ext.Window by clicking the [X], I have to roll back some stuff and then close the window. If the window is closed by me calling close(), I do not want anything to roll back.

I can't find an event to listen for, that is solely triggered by the [X] close button (or pressing escape).

Do any of you know a neat way to distinguish the two close actions from one another (the ones invoked by the user closing the window, and the ones invoked by me calling this.close())?

The best thing I can come up with is to set some flag in the bbar button handlers and listen for window.close, and roll stuff back if the flag is not set. But surely there has to be a better way than this? Best practices anyone? I can't imagine that I am the only one with this need?

11 Feb 2010, 6:46 AM
You have to set a flag, like you described, and implement your logic around that.

In the window's close event handler, you can decide to disallow the window to close by returning false.

Or you can do your rollback actions, even Ext.Ajax.request(), and return true to allow the window to close. Meanwhile, you're doing your rollback actions.

12 Feb 2010, 1:10 AM
What about the close tool button? Can't I get a handle for that, and listen for an onclick event on that? :-/

12 Feb 2010, 1:23 AM
Not sure what you are asking. Do you need this?

var yourWindow = Ext.Window({
listeners: {
'close': function() {
if you don't need to catch the close event after calling close() try to use the suspendEvents (http://www.extjs.com/deploy/dev/docs/?class=Ext.Window) method

12 Feb 2010, 2:02 AM
Nah - I just thought that the close button itself (the [X] in the top right corner) ought to fire a click event when the user closes the dialog window, and that I maybe could dig out that dom element and listen for that click.

To suspend all events seems like a rather drastic measure. I think that I will just stick to the flag solution described above here instead. But thanks for the suggestions anyway! :-)

12 Feb 2010, 2:18 AM
To suspend all events seems like a rather drastic measure.
The suspendEvents method will disable events only for this window. The window will be closed after that by the close() method. It's ok.

12 Feb 2010, 7:20 AM
Yesterday I read a blog post (http://tdg-i.com/202/how-to-extend-and-override-without-creating-an-extension-or-override) by Jay Garcia (http://www.extjs.com/forum/member.php?u=172) that might give you an idea on how to handle your close.