[1.1.1] BorderLayout/LayoutManager - broken inline listeners + fix
January 7th, 2009 by cfz
inline listeners don't work in BorderLayout / LayoutManager because
inline listeners in config are not copied to these classes
the addEvents method is called after the superclass's constructor is called
// broken Ext.LayoutManager
Ext.LayoutManager = function(container, config) {
// inline listeners not copied from config
Ext.LayoutManager.superclass.constructor.call(this );
this.el = Ext.get(container);
if (this.el.dom == document.body && Ext.isIE && !config.allowScroll) {
document.body.scroll = "no";
} else if(this.el.dom != document.body && this.el.getStyle('position') == 'static') {
this.el.position('relative');
}
this.id = this.el.id;
this.el.addClass("x-layout-container");
this.monitorWindowResize = true;
this.regions = {};
this.addEvents({ // should be called before superclass constructor
"layout" : true,
"regionresized" : true,
"regioncollapsed" : true,
"regionexpanded" : true
});
this.updating = false;
Ext.EventManager.onWindowResize(this.onWindowResiz e, this, true);
};
a working patch follows
(place this in your custom overrides file)
(function() { // fixes 1.1.1's broken BorderLayout inline listeners
var oldLM = Ext.LayoutManager; // keep reference to original Ext.LayoutManager
Ext.LayoutManager = function(container, config) {
this.listeners = config.listeners; // copy listeners from config
this.addEvents({ // add events before superclass constructor
"layout" : true,
"regionresized" : true,
"regioncollapsed" : true,
"regionexpanded" : true
});
Ext.LayoutManager.superclass.constructor.call(this );
this.el = Ext.get(container);
// ie scrollbar fix
if (this.el.dom == document.body && Ext.isIE && !config.allowScroll) {
document.body.scroll = "no";
} else if (this.el.dom != document.body && this.el.getStyle('position') == 'static') {
this.el.position('relative');
}
this.id = this.el.id;
this.el.addClass("x-layout-container");
this.monitorWindowResize = true;
this.regions = {};
this.updating = false;
Ext.EventManager.onWindowResize(this.onWindowResiz e, this, true);
};
Ext.extend(Ext.LayoutManager, Ext.util.Observable); // corrected LayoutManager should also extend Ext.util.Observable
Ext.applyIf(Ext.LayoutManager.prototype, oldLM.prototype); // copy original LayoutManager methods
Ext.BorderLayout.superclass = Ext.LayoutManager.prototype; // rewire BorderLayout's superclass
oldLM = null; // remove original LayoutManager
})();
[edit]
@jack/brian/saki: coincidentally, while researching this bug, i discovered that the addEvents method must be called before the superclass's constructor.
(something similar was also mentioned in this thread)
p.s. if it's important to call addEvents before the call to the superclass's constructor, i've compiled a list of classes where this isn't the case. i can PM the list over if need be. just let me know.
Thanks.
it's already in the 1.x SVN. ;)
Just cleaning up the overrides file. Also I've got this ones hanging there for a long while now. Probably they've been already commited/improved. If you can, please take a look.
/** Destroys this form, and all its Fields. */
Ext.override(Ext.form.BasicForm, {
destroy: function() {
this.destroyed = true;
if (this.txId) {
Ext.Ajax.abort(this.txId);
delete this.txId;
}
this.items.each(function(f){
f.destroy();
});
this.purgeListeners();
this.el.removeAllListeners();
this.el.remove();
Ext.ComponentMgr.unregister(this);
}
});
/** Уничтожение Layout`a */
Ext.override(Ext.LayoutManager, {
destroy: function()
{
for (var region in this.regions) {
var r = this.regions[region];
for (var i=0, len=r.panels.length; i
r.panels.remove();
}
}
this.purgeListeners()
}
});
/** Уничтожение Layout`a */
Ext.override(Ext.GridPanel, {
destroy: function()
{
for (var region in this.regions) {
var r = this.regions[region];
for (var i=0, len=r.panels.length; i
r.panels.itemAt(i).destroy();
r.panels.remove();
}
}
this.purgeListeners()
}
});
Thanks
in the LayoutManager, if only
this.listeners = config.listeners
is added (just before the call to the superclass's constructor) without moving the addEvents block too, then the following error is thrown if inline listeners are placed in the BorderLayout config.
http://img72.imageshack.us/img72/3461/layoutmanagererrorss2.png
Thanks.
thanks for the fix :D
Neverless, I did change it. ;)
#If you have any other info about this subject , Please add it free.# |
Posted in ncgloryholes.com | edit