9 * @class Roo.bootstrap.NavGroup
10 * @extends Roo.bootstrap.Component
11 * Bootstrap NavGroup class
12 * @cfg {String} align (left|right)
13 * @cfg {Boolean} inverse
14 * @cfg {String} type (nav|pills|tab) default nav
15 * @cfg {String} navId - reference Id for navbar.
19 * Create a new nav group
20 * @param {Object} config The config object
23 Roo.bootstrap.NavGroup = function(config){
24 Roo.bootstrap.NavGroup.superclass.constructor.call(this, config);
27 Roo.bootstrap.NavGroup.register(this);
31 * Fires when the active item changes
32 * @param {Roo.bootstrap.NavGroup} this
33 * @param {Roo.bootstrap.Navbar.Item} selected The item selected
34 * @param {Roo.bootstrap.Navbar.Item} prev The previously selected item
41 Roo.extend(Roo.bootstrap.NavGroup, Roo.bootstrap.Component, {
52 getAutoCreate : function()
54 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
60 if (Roo.bootstrap.version == 4) {
61 if (['tabs','pills'].indexOf(this.type) != -1) {
62 cfg.cls += ' nav-' + this.type;
64 // trying to remove so header bar can right align top?
65 //cfg.cls += ' navbar-nav';
68 if (['tabs','pills'].indexOf(this.type) != -1) {
69 cfg.cls += ' nav-' + this.type
71 if (this.type !== 'nav') {
72 Roo.log('nav type must be nav/tabs/pills')
74 cfg.cls += ' navbar-nav'
78 if (this.parent() && this.parent().sidebar) {
81 cls: 'dashboard-menu sidebar-menu'
87 if (this.form === true) {
90 cls: 'navbar-form form-inline'
92 //nav navbar-right ml-md-auto
93 if (this.align === 'right') {
94 cfg.cls += ' navbar-right ml-md-auto';
96 cfg.cls += ' navbar-left';
100 if (this.align === 'right') {
101 cfg.cls += ' navbar-right ml-md-auto';
103 cfg.cls += ' mr-auto';
107 cfg.cls += ' navbar-inverse';
115 * sets the active Navigation item
116 * @param {Roo.bootstrap.NavItem} the new current navitem
118 setActiveItem : function(item)
121 Roo.each(this.navItems, function(v){
126 v.setActive(false, true);
133 item.setActive(true, true);
134 this.fireEvent('changed', this, item, prev);
139 * gets the active Navigation item
140 * @return {Roo.bootstrap.NavItem} the current navitem
142 getActive : function()
146 Roo.each(this.navItems, function(v){
157 indexOfNav : function()
161 Roo.each(this.navItems, function(v,i){
172 * adds a Navigation item
173 * @param {Roo.bootstrap.NavItem} the navitem to add
175 addItem : function(cfg)
177 if (this.form && Roo.bootstrap.version == 4) {
180 var cn = new Roo.bootstrap.NavItem(cfg);
182 cn.parentId = this.id;
183 cn.onRender(this.el, null);
187 * register a Navigation item
188 * @param {Roo.bootstrap.NavItem} the navitem to add
190 register : function(item)
192 this.navItems.push( item);
193 item.navId = this.navId;
198 * clear all the Navigation item
201 clearAll : function()
204 this.el.dom.innerHTML = '';
207 getNavItem: function(tabId)
210 Roo.each(this.navItems, function(e) {
211 if (e.tabId == tabId) {
221 setActiveNext : function()
223 var i = this.indexOfNav(this.getActive());
224 if (i > this.navItems.length) {
227 this.setActiveItem(this.navItems[i+1]);
229 setActivePrev : function()
231 var i = this.indexOfNav(this.getActive());
235 this.setActiveItem(this.navItems[i-1]);
237 clearWasActive : function(except) {
238 Roo.each(this.navItems, function(e) {
239 if (e.tabId != except.tabId && e.was_active) {
240 e.was_active = false;
247 getWasActive : function ()
250 Roo.each(this.navItems, function(e) {
265 Roo.apply(Roo.bootstrap.NavGroup, {
269 * register a Navigation Group
270 * @param {Roo.bootstrap.NavGroup} the navgroup to add
272 register : function(navgrp)
274 this.groups[navgrp.navId] = navgrp;
278 * fetch a Navigation Group based on the navigation ID
279 * @param {string} the navgroup to add
280 * @returns {Roo.bootstrap.NavGroup} the navgroup
282 get: function(navId) {
283 if (typeof(this.groups[navId]) == 'undefined') {
285 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
287 return this.groups[navId] ;