beavx420
23 May 2011, 5:20 AM
We used a modified version of a similar extension for ExtJS v3 (that never quite worked right)... took a few minutes to upgrade and figured it would be nice to share!
Basically it will create a toolbar inline with the tabs of a tab panel. Right now it only docks the toolbar to the right-side of the tabbar and you must define the width of the toolbar otherwise it won't work properly (couldn't figure out how to get the size of the toolbar)
26212
Sample:
Ext.define('TestTabs', {
extend: 'Ext.tab.Panel',
requires: [
'Ext.ux.tab.Toolbar'
],
initComponent: function() {
Ext.apply(this, {
activeTab: 0,
plugins: [
Ext.create('Ext.ux.tab.Toolbar', {
width: 180,
items: [{
text: 'New Page',
tooltip: 'Add a new page to hold widgets'
}, {
text: 'Reset Layout',
tooltip: 'Restores the default layout'
}]
})
],
items: [{
title: 'Test Tab'
}]
});
this.callParent();
}
});
Plugin Code:
/**
* @class Ext.ux.tab.Toolbar
* @extends Object
* Plugin (ptype = 'tabtoolbar') for adding a toolbar to a TabBar.
* @constructor
* @param {Object} config Configuration options
* @ptype tabtoolbar
*/
Ext.define('Ext.ux.tab.Toolbar', {
alias: 'plugin.tabtoolbar',
constructor: function(config) {
config = config || {};
Ext.apply(this, config);
},
/**
* @cfg {String} position The position where the toolbar will appear inside the tabbar. Supported values are
* 'left' and 'right' (defaults to right).
*/
position: 'right',
//private
init: function(tabPanel) {
var me = this;
Ext.apply(tabPanel, me.parentOverrides);
me.tabPanel = tabPanel;
me.tabBar = tabPanel.tabBar;
// ensure we have a valid position
if (this.position !== 'left') {
this.position = 'right';
}
me.tabBar.on({
afterlayout: function() {
me.layout = me.tabBar.layout;
// we need to subtract the toolbar width from this function result
me.layout.getLayoutTargetSize = Ext.Function.bind(me.getLayoutTargetSize, me);
var scrollerEl = me.tabBar.body.child('.' + Ext.baseCSSPrefix + 'box-scroller-' + this.position),
contentEl = me.tabBar.body.createChild({
style: 'width:' + this.width + 'px;',
cls: Ext.baseCSSPrefix + 'tab-toolbar-' + this.position
}, scrollerEl);
// if scroller is not created (only one tab)
// we need to add the floating style to the tab bar
if (scrollerEl == undefined) {
me.tabBar.body.child('.' + Ext.baseCSSPrefix + 'box-inner').setStyle({
float: this.position == 'left' ? 'right' : 'left'
})
}
me.toolbar = new Ext.toolbar.Toolbar({
cls: 'x-tab-toolbar',
renderTo: contentEl,
items: this.items || []
});
},
scope: this,
single: true
});
},
/**
* Override the default getLayoutTargetSize of the tabbar layout so we
* can subtract the width of the toolbar
*/
getLayoutTargetSize: function() {
var me = this,
result = Ext.getClass(me.layout).prototype.getLayoutTargetSize.apply(me.layout, arguments);
result.width -= this.width;
return result;
}
});
Plugin CSS:
/**
* Ext.ux.tab.Toolbar styles
*/
.x-tab-toolbar-right { z-index: 6; float: right; }
.x-tab-toolbar-right .x-tab-toolbar { padding: 0 2px; border-width: 0 0 0 1px; }
.x-tab-toolbar-left { z-index: 6; float: left; }
.x-tab-toolbar-left .x-tab-toolbar { padding: 0 2px; border-width: 0 1px 0 0; }
I included a screenshot that shows off the plugin in action. Any improvements are welcomed...
Thanks!
Basically it will create a toolbar inline with the tabs of a tab panel. Right now it only docks the toolbar to the right-side of the tabbar and you must define the width of the toolbar otherwise it won't work properly (couldn't figure out how to get the size of the toolbar)
26212
Sample:
Ext.define('TestTabs', {
extend: 'Ext.tab.Panel',
requires: [
'Ext.ux.tab.Toolbar'
],
initComponent: function() {
Ext.apply(this, {
activeTab: 0,
plugins: [
Ext.create('Ext.ux.tab.Toolbar', {
width: 180,
items: [{
text: 'New Page',
tooltip: 'Add a new page to hold widgets'
}, {
text: 'Reset Layout',
tooltip: 'Restores the default layout'
}]
})
],
items: [{
title: 'Test Tab'
}]
});
this.callParent();
}
});
Plugin Code:
/**
* @class Ext.ux.tab.Toolbar
* @extends Object
* Plugin (ptype = 'tabtoolbar') for adding a toolbar to a TabBar.
* @constructor
* @param {Object} config Configuration options
* @ptype tabtoolbar
*/
Ext.define('Ext.ux.tab.Toolbar', {
alias: 'plugin.tabtoolbar',
constructor: function(config) {
config = config || {};
Ext.apply(this, config);
},
/**
* @cfg {String} position The position where the toolbar will appear inside the tabbar. Supported values are
* 'left' and 'right' (defaults to right).
*/
position: 'right',
//private
init: function(tabPanel) {
var me = this;
Ext.apply(tabPanel, me.parentOverrides);
me.tabPanel = tabPanel;
me.tabBar = tabPanel.tabBar;
// ensure we have a valid position
if (this.position !== 'left') {
this.position = 'right';
}
me.tabBar.on({
afterlayout: function() {
me.layout = me.tabBar.layout;
// we need to subtract the toolbar width from this function result
me.layout.getLayoutTargetSize = Ext.Function.bind(me.getLayoutTargetSize, me);
var scrollerEl = me.tabBar.body.child('.' + Ext.baseCSSPrefix + 'box-scroller-' + this.position),
contentEl = me.tabBar.body.createChild({
style: 'width:' + this.width + 'px;',
cls: Ext.baseCSSPrefix + 'tab-toolbar-' + this.position
}, scrollerEl);
// if scroller is not created (only one tab)
// we need to add the floating style to the tab bar
if (scrollerEl == undefined) {
me.tabBar.body.child('.' + Ext.baseCSSPrefix + 'box-inner').setStyle({
float: this.position == 'left' ? 'right' : 'left'
})
}
me.toolbar = new Ext.toolbar.Toolbar({
cls: 'x-tab-toolbar',
renderTo: contentEl,
items: this.items || []
});
},
scope: this,
single: true
});
},
/**
* Override the default getLayoutTargetSize of the tabbar layout so we
* can subtract the width of the toolbar
*/
getLayoutTargetSize: function() {
var me = this,
result = Ext.getClass(me.layout).prototype.getLayoutTargetSize.apply(me.layout, arguments);
result.width -= this.width;
return result;
}
});
Plugin CSS:
/**
* Ext.ux.tab.Toolbar styles
*/
.x-tab-toolbar-right { z-index: 6; float: right; }
.x-tab-toolbar-right .x-tab-toolbar { padding: 0 2px; border-width: 0 0 0 1px; }
.x-tab-toolbar-left { z-index: 6; float: left; }
.x-tab-toolbar-left .x-tab-toolbar { padding: 0 2px; border-width: 0 1px 0 0; }
I included a screenshot that shows off the plugin in action. Any improvements are welcomed...
Thanks!