PDA

View Full Version : [CLOSED]Strange behaviour: Window, closeAction and ComponentQuery



htammen
26 Feb 2011, 6:24 AM
I´m using a Window as modal dialog:


Ext.define('SO.ux.client.UserAddUi', {
extend: 'Ext.Window',
title: 'Benutzer hinzufügen',
width: 600,
height: 300,
minHeight: 300,
layout: 'border',
modal: true,
id: 'userAddWindow',
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
xtype: 'button',
text: 'Hinzufügen',
icon: '../images/icons/user--plus.png',
id: 'btnAddUsers'
}]
}],
items: [
{
...
}
]
}

In initComponent I set a click handler for the toolbar button btnAddUsers

,initComponent: function() {
SO.ux.client.UserAdd.superclass.initComponent.call(this);
this.down('#btnAddUsers').on('click', this.addUsersHandler, this);
}


This works the first time the user opens the window. From the second time on this.down returns null and thus the window is not opened.

tobiu
26 Feb 2011, 7:26 AM
this is not directly related to your problem, but you should really use itemId instead of id (and then parent.getComponent(itemId)). Otherwise you indirectly create a singleton, since each further instance would get the same dom-id.

also prefer iconCls over icon.


best regards
tobiu

Animal
26 Feb 2011, 8:04 AM
It is to do with duplicate ids if the closeAction of that Window is not 'hide'.

That Window should be closeAction: 'hide', and only created once.

htammen
26 Feb 2011, 8:23 AM
O.k. I´ve refactored from id to itemId. Thank you for the hint I wasn´t aware of that.

But I don´t really understand that I have to use closeAction = 'hide'. The dialog is used very seldom and so I would like to destroy the window to save resources after it has been closed by the user. If I do this with all my widgets the user will run out of memory at some point.

evant
26 Feb 2011, 5:20 PM
Don't put non primitives in the object prototype (arrays, objects). This means they get shared across all instances.

Put them inside initComponent.

htammen
27 Feb 2011, 1:08 AM
??? don´t understand your last reply evant.
This may be caused in my bad javascript know how. Can you explain in some words what I´m doing wrong and what I should do instead?
Sorry for those basic question.

tobiu
27 Feb 2011, 3:26 AM
maybe saki's example helps in this case:
http://blog.extjs.eu/patterns/file-patters/ext-extension-with-factory-functions-file-pattern/
look how he uses the initComponent-method.

or get jay's book -> ext js in action.

since there are no real classes in javascript, we are dealing with prototypes all the time. if you define a prototype, you can only add primitive datatypes (numbers, strings, booleans), but no arrays / objects as evan told you already. if you do so, every time you create a new instance with the new operator, it will get the identical array / object and this can get really bad if you are not dealing with singletons.


best regards
tobiu