PDA

View Full Version : Destroy all components at once



checks
30 Aug 2012, 2:03 PM
Hello,

I want to destroy all components. I have an application that uses Log in and Log out, so when the user Logs out I need to destroy all windows that the user leaved active. The problem is that the application has a lot of windows son I don't want to do this...

window1.destroy();
window2.destroy();
etc . . .

Does sencha have a method to destroy all components at once???

Thanks!!!!

scottmartin
30 Aug 2012, 6:35 PM
If you destroy the viewport, all items are destroyed as well. Containers automatically destroy all child items.

Scott.

jemptymethod
4 Sep 2012, 9:54 AM
I question whether Scott's approach is what the OP wants, destroying the entire viewport -- that seems a bit drastic.

Instead it appears that when a user logs out, they just want to destroy a number of windows the user may have open. My suggestion then is to store references to the open windows in a MixedCollection, or better yet a plain old Javascript object or array. Presuming that an array is used and it is named openWindows, then it would be a matter of something such as:



for (var i=0, n=openWindows.length; i<n; i++) {
var openWindow = openWindows[i];
if (openWindow) {
openWindow.destroy();
}
}

4 Sep 2012, 10:12 AM
If you destroy the viewport, all items are destroyed as well. Containers automatically destroy all child items.

Scott.

Window instances are generally not children of containers.

droessner
4 Sep 2012, 11:17 AM
How about this?



Ext.WindowManager.each(function(component) {
if (component.getXType() === 'window') {
component.destroy();
}
});

jemptymethod
4 Sep 2012, 11:55 AM
How about this?



Ext.WindowManager.each(function(component) {
if (component.getXType() === 'window') {
component.destroy();
}
});


I like this better than mine.

checks
11 Sep 2012, 1:59 PM
Excelent, I tried destroying viewport and it didn't work.
now I'll try with the code below.

Thanks to all of u..

checks
11 Sep 2012, 2:09 PM
Ok, I tried with your code, and I get the error... Ext.WindowManager is undefined.

So I have the next question:

how should I use this code?
Is 'component' a var????

I use Extjs 3.1

jemptymethod
14 Sep 2012, 12:41 PM
In Ext 3 it would be Ext.WindowMgr (yet another change from 3 to 4 for no good reason: at least provide an alias for a while and mark WindowMgr as deprecated)

droessner
14 Sep 2012, 1:02 PM
In Ext 3 it would be Ext.WindowMgr (yet another change from 3 to 4 for no good reason: at least provide an alias for a while and mark WindowMgr as deprecated)

Ext.WindowMgr is still a valid alias in 4.x.

checks
18 Sep 2012, 7:18 AM
Thank you so much for helping me... my problem is solved... with the next code

Ext.WindowMgr.each(function(w) {
w.destroy();
});

dawesi
19 Sep 2012, 5:10 AM
I would have thought


window.location.reload()


would also do the job

;)

checks
20 Sep 2012, 9:27 AM
I tested it and you´re right, it also do the job...
tks!