PDA

View Full Version : Limitting tab



irfan
20 Sep 2007, 12:08 AM
Helo, I'd like to know how to limitting tabs that can be added to a contentPanel?

For example: I have a contentPanel that only allowed 10 tabs. If more tab is added then it shows a warning message that the number of allowed tabs are reached and the user have to close some tabs.

code example of tab addition:


function OpenNewTab(tabTitle, link) {
Ext.onReady(function() {
var center = parent.kampiunApp.ui.layout.getRegion('center');
var iframe = Ext.DomHelper.append(parent.document.body, {tag: 'iframe', frameBorder: 0, src: link});
if (parent.tabCounter && parent.tabCounter <parent.tabLimit) //the code to limit tab.
parent.tabCounter++;
//alert(parent.tabCounter);
//if (!center.autoScroll)
// center.autoScroll = true;
//alert (center.);
panel= new Ext.ContentPanel(iframe, {title: Ext.util.Format.ellipsis(tabTitle,20), fitToFrame: true, autoScroll: true, closable: true});
panel.addEvents(
);

parent.kampiunApp.ui.layout.add('center', panel);
center.showPanel(panel)
});
}


Thanks.

evant
20 Sep 2007, 12:11 AM
var num = myLayout.myRegion.getTabs().getCount();

irfan
20 Sep 2007, 1:12 AM
var num = myLayout.myRegion.getTabs().getCount();


Thanks. It worked. But can I set the region or the Tabs behavior to set a certain amount of tab? Or maybe could I limit the tab using on listener method? What listener should I use?:-?

Animal
20 Sep 2007, 1:36 AM
This will fire a "beforeadd" event passing the TabPanel, the new item, and the current existing number of items to the handler.

If you return false from the handler, the item will not be added.



Ext.override(Ext.TabPanel, {
addTabItem : function(item){
if (!this.events.beforeadd) {
this.addEvents({beforeadd: true});
}
if (this.fireEvent("beforeadd", this, item, this.getCount()) !== false) {
this.items[item.id] = item;
this.items.push(item);
if(this.resizeTabs){
item.setWidth(this.currentTabWidth || this.preferredTabWidth);
this.autoSizeTabs();
}else{
item.autoSize();
}
}
}
});