Roo.bootstrap.NavGroup = function(config){
Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
this.navItems = [];
Roo.bootstrap.NavGroup.register(this);
this.addEvents({
'changed': true
});
};
Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
align: '',
inverse: false,
form: false,
type: 'nav',
navId : '',
navItems : false,
getAutoCreate : function()
{
var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
cfg = {
tag : 'ul',
cls: 'nav'
};
if (Roo.bootstrap.version == 4) {
if (['tabs','pills'].indexOf(this.type) != -1) {
cfg.cls += ' nav-' + this.type;
} else {
if (this.parent() && this.parent().xtype != 'NavHeaderbar') {
cfg.cls += ' navbar-nav';
}
}
} else {
if (['tabs','pills'].indexOf(this.type) != -1) {
cfg.cls += ' nav-' + this.type
} else {
if (this.type !== 'nav') {
Roo.log('nav type must be nav/tabs/pills')
}
cfg.cls += ' navbar-nav'
}
}
if (this.parent() && this.parent().sidebar) {
cfg = {
tag: 'ul',
cls: 'dashboard-menu sidebar-menu'
};
return cfg;
}
if (this.form === true) {
cfg = {
tag: 'form',
cls: 'navbar-form form-inline'
};
if (this.align === 'right') {
cfg.cls += ' navbar-right ml-md-auto';
} else {
cfg.cls += ' navbar-left';
}
}
if (this.align === 'right') {
cfg.cls += ' navbar-right ml-md-auto';
} else {
cfg.cls += ' mr-auto';
}
if (this.inverse) {
cfg.cls += ' navbar-inverse';
}
return cfg;
},
setActiveItem : function(item)
{
var prev = false;
Roo.each(this.navItems, function(v){
if (v == item) {
return ;
}
if (v.isActive()) {
v.setActive(false, true);
prev = v;
}
});
item.setActive(true, true);
this.fireEvent('changed', this, item, prev);
},
getActive : function()
{
var prev = false;
Roo.each(this.navItems, function(v){
if (v.isActive()) {
prev = v;
}
});
return prev;
},
indexOfNav : function()
{
var prev = false;
Roo.each(this.navItems, function(v,i){
if (v.isActive()) {
prev = i;
}
});
return prev;
},
addItem : function(cfg)
{
if (this.form && Roo.bootstrap.version == 4) {
cfg.tag = 'div';
}
var cn = new Roo.bootstrap.NavItem(cfg);
this.register(cn);
cn.parentId = this.id;
cn.onRender(this.el, null);
return cn;
},
register : function(item)
{
this.navItems.push( item);
item.navId = this.navId;
},
clearAll : function()
{
this.navItems = [];
this.el.dom.innerHTML = '';
},
getNavItem: function(tabId)
{
var ret = false;
Roo.each(this.navItems, function(e) {
if (e.tabId == tabId) {
ret = e;
return false;
}
return true;
});
return ret;
},
setActiveNext : function()
{
var i = this.indexOfNav(this.getActive());
if (i > this.navItems.length) {
return;
}
this.setActiveItem(this.navItems[i+1]);
},
setActivePrev : function()
{
var i = this.indexOfNav(this.getActive());
if (i < 1) {
return;
}
this.setActiveItem(this.navItems[i-1]);
},
clearWasActive : function(except) {
Roo.each(this.navItems, function(e) {
if (e.tabId != except.tabId && e.was_active) {
e.was_active = false;
return false;
}
return true;
});
},
getWasActive : function ()
{
var r = false;
Roo.each(this.navItems, function(e) {
if (e.was_active) {
r = e;
return false;
}
return true;
});
return r;
}
});
Roo.apply(Roo.bootstrap.NavGroup, {
groups: {},
register : function(navgrp)
{
this.groups[navgrp.navId] = navgrp;
},
get: function(navId) {
if (typeof(this.groups[navId]) == 'undefined') {
return false;
}
return this.groups[navId] ;
}
});