PDA

View Full Version : Close (not hide) window and reopen



varunach
28 Apr 2011, 2:13 AM
Hi,

I want to close a window ( not hide) and then reopen the window. I want this functionality cause the formpanel contained inside the window changes dynamically ( child components are created dynamically based on user interaction) . I want the original formpanel to show up whenever the window is closed and reopened. Directly calling window.show() after it has already been closed throws an error (as expected).

How do i go about doing this?

Check out the desktop example on the Sencha site to see what i mean.

http://dev.sencha.com/deploy/ext-4.0.0/examples/desktop/desktop.html

Thanks

fay
28 Apr 2011, 4:11 AM
It would help if you specified what error you're receiving... Have you looked at the closeAction (http://dev.sencha.com/deploy/ext-3.3.1/docs/?class=Ext.Window&member=closeAction) config param?

friend
28 Apr 2011, 4:16 AM
Also, from the API docs, Window.close() does the following:



Closes the Window, removes it from the DOM, destroys the Window object and all its descendant Components. The beforeclose event is fired before the close happens and will cancel the close action if it returns false.



Also look at autoDestroy: false on the Window.

varunach
28 Apr 2011, 4:34 AM
fix this piece of code so that i can show and close (not hide) the window at will..


Ext.onReady(function(){
var button = new Ext.Button({
text : 'open',
renderTo : 'signUpDiv',
handler : function(){
if(win)
win.show();
else{
createWindow();
}
}
});
createWindow = function(){
var win = new Ext.Window({
title : 'Example',
autoDestroy : false,
closeAction : 'close',
items : [{title : 'panel'}],
buttons : [{text : 'close', handler : function(){
win.close();
}}]
});
win.show();
}
createWindow();
});

friend
28 Apr 2011, 4:46 AM
I think you're confused/hung-up on the idea of close vs. hiding of a Window. If you want to reuse a Window at a later time (including its child content), the end result is that the Window gets hidden. A 'close' operation typically denotes a destroy of the Window and its contents.

Even in the example below, trapping the 'beforeclose' event requires that you 'hide' the Window if you no longer want it to appear on the screen, yet maintain its child content.





var win = new Ext.Window({
title : 'Example',
listeners: {
beforeclose: function(panel) {
panel.hide();
return false;
}
},
items : [{title : 'panel'}],
buttons : [{text : 'close', handler : function(){
win.close();
}}]
});

win.show();
I'm still not certain why you can't just do a win.hide() when you're through with the window. You can swap out the child content of the Window at will if it exists but is hidden. If it's closed/destroyed, you always have to start from scratch.

varunach
28 Apr 2011, 5:00 AM
the thing is that the child components of the window are generated dynamically.. so i don't have control over their id's so can't hide/destroy them. I'll have to work out a way to do that if win.close() is not possible.. It'll be dead easy if the damn window can just die.. :D

mitchellsimoens
28 Apr 2011, 5:36 AM
var items = [
{ xtype : 'panel', title : 'One', html : 'One' },
{ xtype : 'panel', title : 'Two', html : 'Two' }
];

var win = new Ext.Window({
width : 400,
height : 400,
title : 'Test',
closeAction : 'hide',
listeners : {
hide: function() {
win.removeAll();
},
show: function() {
win.add(items);
win.doLayout();
}
}
});

var btn = new Ext.Button({
renderTo : Ext.getBody(),
text : 'Show Window',
handler : function() {
win.show();
}
});

This test case removes items on hide and adds items on show. If you have closeAction as the default, you will not be able to show the Window without recreating or unnecessary overhead.

varunach
28 Apr 2011, 5:48 AM
I DO want to recreate the window and ALL of it's child components. From my first post


I want the original formpanel to show up whenever the window is closed and reopened.

mitchellsimoens
28 Apr 2011, 6:12 AM
so recreate the window, what's the problem then?