PDA

View Full Version : window header close/"X" button click event



29 Mar 2012, 5:46 AM
Is there a way to capture the click event of the "X" button on a window. I cant use the beforeClose event that are thrown because i only need to make the change when the user cancels their attempted change on a form.
what happens is a user clicks on a record in a grid and opens a modal window that allows them to edit the information. some of the data in that model of the record gets modified to work with what is needed on the server side, but if i do not return it to its original state when the user cancels and the user modifies or adds another record. The store thinks that the both records contain changes that need to be saved and this causes a server side error. Ive fixed it for if the user presses escape or the cancel button that i have on the form, but i cant find a way to get to the click event on the "X" button in the header of the window.

mitchellsimoens
29 Mar 2012, 8:05 AM
The close tool executes me.close so there really isn't a way to distinguish from if you executed me.close or if the close tool did. The only way to do this is to override initTools and change the handler of the close tool.

29 Mar 2012, 8:13 AM
thanks for the response. do you know if there is any plans to have it throw an event that can be handled in future releases?

mitchellsimoens
29 Mar 2012, 8:14 AM
thanks for the response. do you know if there is any plans to have it throw an event that can be handled in future releases?

There is no plan currently.

birru
11 Jul 2012, 4:37 AM
Hello,

I had this problem today, too.
My solution is:
configure the window with

closable: false

and then add an afterrender listener:


listeners: {
afterrender: function() {
var cmp = this;
var myCloseTool = Ext.create('Ext.panel.Tool', {
type: 'close',
handler: function() {
// do something for this case
cmp.close();
}
})
cmp.header.insert(2, myCloseTool); // number depends on other items in header
}
}


you can do your custom actions in the handler of the manually inserted close-tool.