PDA

View Full Version : How to create, destroy, then re-create a custom window?



abcdef
20 Nov 2011, 9:33 PM
My custom window:


Ext.define('MyApp.window.Window' ,{
extend: 'Ext.window.Window',
alias: 'widget.myappwindow',
componentCls: 'myapp-window',
modal: true,
width: 400,
height: 150,
layout: {
type: 'hbox',
align: 'top'
},
items: [
{
xtype: 'container',
cls: 'body-icon'
},
{
xtype: 'container',
itemId: 'message',
cls: 'body-message',
flex: 1
}
],
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
height: 35,
layout: {
pack: 'center'
},
defaults: {
minWidth: 60,
margin: '0 2 0 2'
}
}],
initComponent: function() {
var me = this;
me.initConfig();
me.callParent(arguments);
return me;
}
});


In one of my controller methods, I am doing this:



Ext.create('MyApp.window.Window').show();


Works fine the first time; every other time, I get the following error in console:



NOT_FOUND_ERR: DOM Exception 8: An attempt was made to reference a Node in a context where it does not exist.

What I'd like to do is to create a new window every single time the control flows into this method. close() destroys the window by default.

Please help!

flanders
20 Nov 2011, 11:20 PM
Within the Ext.define() method you are defining an class. In other words an blueprint for instantation. On this blueprint you can add properties that are copied onto the new instance when it is instantiated. However, javascript doesn't copy objects and passes them by reference. This will result in all your instances having references to the same items array, dockedItems array and layout object.

To avoid this, you should move these to initComponent:




Ext.define('MyApp.window.Window' ,{
extend: 'Ext.window.Window',
alias: 'widget.myappwindow',
/** 'primitive types' get copied so they can stay here, but personally i move them as well
componentCls: 'myapp-window',
modal: true,
width: 400,
height: 150,
initComponent: function() {
var me = this; // apply the shiit before you hit callParent

Ext.apply(me, {
items: [ .. ],
dockedItems: [ .. ],
...
});

me.initConfig();
me.callParent(arguments);
return me;
}});

abcdef
21 Nov 2011, 1:12 PM
Aah! Thanks and sorry for the noise!