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 if (this.parent() && this.parent().xtype != 'NavHeaderbar') {
66 // do not use on header bar...
67 cfg.cls += ' navbar-nav';
72 if (['tabs','pills'].indexOf(this.type) != -1) {
73 cfg.cls += ' nav-' + this.type
75 if (this.type !== 'nav') {
76 Roo.log('nav type must be nav/tabs/pills')
78 cfg.cls += ' navbar-nav'
82 if (this.parent() && this.parent().sidebar) {
85 cls: 'dashboard-menu sidebar-menu'
91 if (this.form === true) {
94 cls: 'navbar-form form-inline'
96 //nav navbar-right ml-md-auto
97 if (this.align === 'right') {
98 cfg.cls += ' navbar-right ml-md-auto';
100 cfg.cls += ' navbar-left';
104 if (this.align === 'right') {
105 cfg.cls += ' navbar-right ml-md-auto';
107 cfg.cls += ' mr-auto';
111 cfg.cls += ' navbar-inverse';
119 * sets the active Navigation item
120 * @param {Roo.bootstrap.NavItem} the new current navitem
122 setActiveItem : function(item)
125 Roo.each(this.navItems, function(v){
130 v.setActive(false, true);
137 item.setActive(true, true);
138 this.fireEvent('changed', this, item, prev);
143 * gets the active Navigation item
144 * @return {Roo.bootstrap.NavItem} the current navitem
146 getActive : function()
150 Roo.each(this.navItems, function(v){
161 indexOfNav : function()
165 Roo.each(this.navItems, function(v,i){
176 * adds a Navigation item
177 * @param {Roo.bootstrap.NavItem} the navitem to add
179 addItem : function(cfg)
181 if (this.form && Roo.bootstrap.version == 4) {
184 var cn = new Roo.bootstrap.NavItem(cfg);
186 cn.parentId = this.id;
187 cn.onRender(this.el, null);
191 * register a Navigation item
192 * @param {Roo.bootstrap.NavItem} the navitem to add
194 register : function(item)
196 this.navItems.push( item);
197 item.navId = this.navId;
202 * clear all the Navigation item
205 clearAll : function()
208 this.el.dom.innerHTML = '';
211 getNavItem: function(tabId)
214 Roo.each(this.navItems, function(e) {
215 if (e.tabId == tabId) {
225 setActiveNext : function()
227 var i = this.indexOfNav(this.getActive());
228 if (i > this.navItems.length) {
231 this.setActiveItem(this.navItems[i+1]);
233 setActivePrev : function()
235 var i = this.indexOfNav(this.getActive());
239 this.setActiveItem(this.navItems[i-1]);
241 clearWasActive : function(except) {
242 Roo.each(this.navItems, function(e) {
243 if (e.tabId != except.tabId && e.was_active) {
244 e.was_active = false;
251 getWasActive : function ()
254 Roo.each(this.navItems, function(e) {
269 Roo.apply(Roo.bootstrap.NavGroup, {
273 * register a Navigation Group
274 * @param {Roo.bootstrap.NavGroup} the navgroup to add
276 register : function(navgrp)
278 this.groups[navgrp.navId] = navgrp;
282 * fetch a Navigation Group based on the navigation ID
283 * @param {string} the navgroup to add
284 * @returns {Roo.bootstrap.NavGroup} the navgroup
286 get: function(navId) {
287 if (typeof(this.groups[navId]) == 'undefined') {
289 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
291 return this.groups[navId] ;