PDA

View Full Version : [Ext2.0_rc1] Ext.Toolbar and missing 'ownerCt' property



pic_Nick
26 Nov 2007, 8:30 AM
There is 'ownerCt' property in Ext.Toolbar in the docs, but actualy there is not in the constructed object. I've checked it with FireBug and was unable to locate.
This is a simple example, just replace the contents of examples/panel/panel.js:

Ext.onReady(function(){
var p = new Ext.Panel({
title: 'My Panel',
collapsible:true,
renderTo: document.body,
width:400,
html: Ext.example.bogusMarkup,
tbar: [{
text: "Button",
handler: function(){
var o = p.getTopToolbar();
alert("o.ownerCt="+o.ownerCt);
}
}]
});
});
Can anybody explain, why it is not there?
Big thanks in advance!

efege
26 Nov 2007, 8:59 AM
The explanation comes in part from the docs, though the last word is as always in the source code. Docs say:



ownerCt
The component's owner Ext.Container (defaults to undefined, and is set automatically when the component is added to a container).


"when the component is added to a container"... ok, let's see what this means. The only place in the source where the ownerCt property is set, is in the methods add and insert, in Container.js. On the other hand, you can see that in Panel.js, when top/bottom toolbars are added to a panel, that is done by means of the toolbar's render method, which is inherited from Component. And this method does not involve neither of Container's add or insert methods.

So, rendering a Toolbar to a Panel has no relation to adding/inserting a Component into a Container. In other words, the Panel is not a Container for the Toolbar... not at least in the sense that those capitalized terms have in Ext.

pic_Nick
26 Nov 2007, 10:25 AM
Thank you Fernando for your explanation.
But then I have one more question: what ways do exist to add Toolbar as a Component to the Container, if any?

efege
26 Nov 2007, 10:43 AM
I did this test, which outputs true to the console:



tb1 = new Ext.Toolbar([{
text: 'Btn 1'
}, {
text: 'Btn 2'
}]);
tb2 = new Ext.Toolbar([{
text: 'Btn 1'
}, {
text: 'Btn 2'
}]);
p = new Ext.Panel({
width: 500,
height: 250,
renderTo: document.body,
items: tb1,
bbar: tb2
});
console.log((tb1.ownerCt == p) && (tb2.ownerCt === undefined));

pic_Nick
26 Nov 2007, 10:02 PM
Ok, thank you, I get your point.
But, futher more, the buttons on these toolbars still do not have ownerCt property. Right? And there is no way to make it available there, except overriding addButton method of the toolbar?

efege
27 Nov 2007, 3:09 AM
May I ask why do you need to access such property from the toolbar buttons, and what value do you expect it to have? As your own example demonstrates, the button's handler function can easily access the containing panel component (using the reference p)... What else are you trying to do?

pic_Nick
27 Nov 2007, 7:19 AM
Of course you may. I need this property, because I'm building UI dynamicaly from XML description by means of xtype mechanism and there is no explicit references such p there and can not be. This example was just for clearness of what I mean. And I'm expecting that ownerCt property of the toolbar button should contain a reference to this toolbar (and in the end the toolbar itself should contain reference to its container panel but it's just a dream :D).

heidtmare
27 Nov 2007, 7:34 AM
I do something similar and I've found that i have to assign ids to components as i go,
and use Ext.getCmp('componets-id') later on in the dynamic object.

Example:

{
xtype:'fieldset',
id: 'FIND_Search_form_fieldset_entry',
title: 'Entry',
collapsible: true,
titleCollapse: true,
autoHeight: true,
items :[{
xtype:'button',
icon: modulePath+'/FIND_Search/images/add.gif',
cls: 'x-btn-text-icon',
text: 'Add an Identifier',
handler: function(){
Ext.getCmp('FIND_Search_form_fieldset_entry').insert(2, {
xtype:'textfield',
fieldLabel:'Identifier',
name: 'entry_identifier[]',
listeners: {
render: function(ct){createRemoveButton(ct,FIND_Search_form);}
}
});
Ext.getCmp('FIND_Search_form_fieldset_entry').doLayout();
}
}

pic_Nick
27 Nov 2007, 9:55 PM
Yes, heidtmare, this is some sort of solution, but not very sutable for me. In this case I will have to manage the naming of this ID's, whatch for them not to have 2 components with identical ID. This brings some inconvenience.