PDA

View Full Version : Toolbar.insertButton to take Arrays and button configs



Animal
27 Feb 2007, 1:37 AM
The old version processed Arrays.

It also processed button config objects rather than assuming fully fledged Buttons.

Jack, could we have the following enhancement to insertButton Please?



insertButton : function(index, item){
if(item instanceof Array){
var buttons = [];
for(var i = 0, len = item.length; i < len; i++) {
buttons.push(this.insertButton(index + i, item[i]));
}
return buttons;
}
if (!(item instanceof Ext.Button))
item = new Ext.ToolbarButton(item);
var td = document.createElement("td");
this.tr.insertBefore(td, this.tr.childNodes[index]);
item.render(td);
this.items.insert(index, item);
return item;
}

jack.slocum
27 Feb 2007, 8:31 AM
There was an issue with it. I forget what it was... is that code well tested?

PS: You are missing some brackets ;)

Animal
27 Feb 2007, 8:52 AM
Works for me. This is what I have in my overrides file, and the screenshots that I posted today were created with this code:



Ext.override(Ext.Toolbar, {
/**
* Inserts any Toolbar.Item/Toolbar.Button at the specified index
* @param {Number} index The index where the item is to be inserted
* @param {Object/Toolbar.Item/Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
* @return {Ext.Toolbar.Button/Item}
*/
insertButton : function(index, item){
if(item instanceof Array){
var buttons = [];
for(var i = 0, len = item.length; i < len; i++) {
buttons.push(this.insertButton(index + i, item[i]));
}
return buttons;
}
if (!(item instanceof Ext.Button))
item = new Ext.ToolbarButton(item);
var td = document.createElement("td");
this.tr.insertBefore(td, this.tr.childNodes[index]);
item.render(td);
this.items.insert(index, item);
return item;
}
});

jack.slocum
27 Feb 2007, 9:22 AM
I dropped it in. Thanks. Ext.ToolbarButton doesn't exist, so I changed that and I changed it to test for Ext.Toolbar.Button.

For packer support and worry free new line stripping, I have to be strict with brackets and semi-colons. Obviously there was only 1 spot for it here so no biggie. :)