PDA

View Full Version : Anyway to create singleton window?



yAdEs
9 May 2013, 8:23 AM
Is there anyway to create singleton window?

As I know, the singleton property is used by Ext.Base, and will lead bug to window.

It's really boring to check componet when we create a window. Basicly, I need to do such thing for every singleton window.

var comp = Ext.ComponentQuery.query("Test.view.Mywindow")[0];
if(comp){
Ext.applyIf(comp,config);
}else{
comp = Ext.create("Test.view.Mywindow",config);
}
comp.show();

It will be much more convience if add a "single" config for window.

evant
9 May 2013, 4:52 PM
Ext.require('Ext.window.Window', function(){
MyApp = {
win: new Ext.window.Window({
title: 'Foo',
width: 200,
height: 200
})
}
})

Ext.onReady(function() {

MyApp.win.show();

});

yAdEs
9 May 2013, 5:22 PM
How can I do it when to create them without launch them onReady?

yAdEs
10 May 2013, 8:21 AM
I add a new constructor method for Ext.window.Window, and when you add a "single" property to window or config, set it to true, the window will be create singleton.

constructor : function(config) {
var me = this;
config = config || {};
if(config.single || me.single){
var comp = Ext.ComponentQuery.query('window[$className=' + me.$className + ']')[0];
if(comp){
return comp;
}else{
me.callParent([config]);
}
}else{
me.callParent([config]);
}
},