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 (['nav','pills'].indexOf(this.type) != -1) {
62 cfg.cls = ' navbar-' + this.type;
65 if (['tabs','pills'].indexOf(this.type) != -1) {
66 cfg.cls += ' nav-' + this.type
68 if (this.type !== 'nav') {
69 Roo.log('nav type must be nav/tabs/pills')
71 cfg.cls += ' navbar-nav'
75 if (this.parent() && this.parent().sidebar) {
78 cls: 'dashboard-menu sidebar-menu'
84 if (this.form === true) {
87 cls: 'navbar-form form-inline'
90 if (this.align === 'right') {
91 cfg.cls += ' navbar-right ml-md-auto';
93 cfg.cls += ' navbar-left';
97 if (this.align === 'right') {
98 cfg.cls += ' navbar-right ml-md-auto';
100 cfg.cls += ' mr-auto';
104 cfg.cls += ' navbar-inverse';
112 * sets the active Navigation item
113 * @param {Roo.bootstrap.NavItem} the new current navitem
115 setActiveItem : function(item)
118 Roo.each(this.navItems, function(v){
123 v.setActive(false, true);
130 item.setActive(true, true);
131 this.fireEvent('changed', this, item, prev);
136 * gets the active Navigation item
137 * @return {Roo.bootstrap.NavItem} the current navitem
139 getActive : function()
143 Roo.each(this.navItems, function(v){
154 indexOfNav : function()
158 Roo.each(this.navItems, function(v,i){
169 * adds a Navigation item
170 * @param {Roo.bootstrap.NavItem} the navitem to add
172 addItem : function(cfg)
174 if (this.form && Roo.bootstrap.version == 4) {
177 var cn = new Roo.bootstrap.NavItem(cfg);
179 cn.parentId = this.id;
180 cn.onRender(this.el, null);
184 * register a Navigation item
185 * @param {Roo.bootstrap.NavItem} the navitem to add
187 register : function(item)
189 this.navItems.push( item);
190 item.navId = this.navId;
195 * clear all the Navigation item
198 clearAll : function()
201 this.el.dom.innerHTML = '';
204 getNavItem: function(tabId)
207 Roo.each(this.navItems, function(e) {
208 if (e.tabId == tabId) {
218 setActiveNext : function()
220 var i = this.indexOfNav(this.getActive());
221 if (i > this.navItems.length) {
224 this.setActiveItem(this.navItems[i+1]);
226 setActivePrev : function()
228 var i = this.indexOfNav(this.getActive());
232 this.setActiveItem(this.navItems[i-1]);
234 clearWasActive : function(except) {
235 Roo.each(this.navItems, function(e) {
236 if (e.tabId != except.tabId && e.was_active) {
237 e.was_active = false;
244 getWasActive : function ()
247 Roo.each(this.navItems, function(e) {
262 Roo.apply(Roo.bootstrap.NavGroup, {
266 * register a Navigation Group
267 * @param {Roo.bootstrap.NavGroup} the navgroup to add
269 register : function(navgrp)
271 this.groups[navgrp.navId] = navgrp;
275 * fetch a Navigation Group based on the navigation ID
276 * @param {string} the navgroup to add
277 * @returns {Roo.bootstrap.NavGroup} the navgroup
279 get: function(navId) {
280 if (typeof(this.groups[navId]) == 'undefined') {
282 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
284 return this.groups[navId] ;