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.
16 * @cfg {Boolean} pilltype default true (turn to off to disable active toggle)
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, {
53 getAutoCreate : function()
55 var cfg = Roo.apply({}, Roo.bootstrap.NavGroup.superclass.getAutoCreate.call(this));
61 if (Roo.bootstrap.version == 4) {
62 if (['tabs','pills'].indexOf(this.type) != -1) {
63 cfg.cls += ' nav-' + this.type;
65 // trying to remove so header bar can right align top?
66 if (this.parent() && this.parent().xtype != 'NavHeaderbar') {
67 // do not use on header bar...
68 cfg.cls += ' navbar-nav';
73 if (['tabs','pills'].indexOf(this.type) != -1) {
74 cfg.cls += ' nav-' + this.type
76 if (this.type !== 'nav') {
77 Roo.log('nav type must be nav/tabs/pills')
79 cfg.cls += ' navbar-nav'
83 if (this.parent() && this.parent().sidebar) {
86 cls: 'dashboard-menu sidebar-menu'
92 if (this.form === true) {
95 cls: 'navbar-form form-inline'
97 //nav navbar-right ml-md-auto
98 if (this.align === 'right') {
99 cfg.cls += ' navbar-right ml-md-auto';
101 cfg.cls += ' navbar-left';
105 if (this.align === 'right') {
106 cfg.cls += ' navbar-right ml-md-auto';
108 cfg.cls += ' mr-auto';
112 cfg.cls += ' navbar-inverse';
120 * sets the active Navigation item
121 * @param {Roo.bootstrap.NavItem} the new current navitem
123 setActiveItem : function(item)
126 Roo.each(this.navItems, function(v){
131 v.setActive(false, true);
138 item.setActive(true, true);
139 this.fireEvent('changed', this, item, prev);
144 * gets the active Navigation item
145 * @return {Roo.bootstrap.NavItem} the current navitem
147 getActive : function()
151 Roo.each(this.navItems, function(v){
162 indexOfNav : function()
166 Roo.each(this.navItems, function(v,i){
177 * adds a Navigation item
178 * @param {Roo.bootstrap.NavItem} the navitem to add
180 addItem : function(cfg)
182 if (this.form && Roo.bootstrap.version == 4) {
185 var cn = new Roo.bootstrap.NavItem(cfg);
187 cn.parentId = this.id;
188 cn.onRender(this.el, null);
192 * register a Navigation item
193 * @param {Roo.bootstrap.NavItem} the navitem to add
195 register : function(item)
197 this.navItems.push( item);
198 item.navId = this.navId;
203 * clear all the Navigation item
206 clearAll : function()
209 this.el.dom.innerHTML = '';
212 getNavItem: function(tabId)
215 Roo.each(this.navItems, function(e) {
216 if (e.tabId == tabId) {
226 setActiveNext : function()
228 var i = this.indexOfNav(this.getActive());
229 if (i > this.navItems.length) {
232 this.setActiveItem(this.navItems[i+1]);
234 setActivePrev : function()
236 var i = this.indexOfNav(this.getActive());
240 this.setActiveItem(this.navItems[i-1]);
242 clearWasActive : function(except) {
243 Roo.each(this.navItems, function(e) {
244 if (e.tabId != except.tabId && e.was_active) {
245 e.was_active = false;
252 getWasActive : function ()
255 Roo.each(this.navItems, function(e) {
270 Roo.apply(Roo.bootstrap.NavGroup, {
274 * register a Navigation Group
275 * @param {Roo.bootstrap.NavGroup} the navgroup to add
277 register : function(navgrp)
279 this.groups[navgrp.navId] = navgrp;
283 * fetch a Navigation Group based on the navigation ID
284 * @param {string} the navgroup to add
285 * @returns {Roo.bootstrap.NavGroup} the navgroup
287 get: function(navId) {
288 if (typeof(this.groups[navId]) == 'undefined') {
290 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
292 return this.groups[navId] ;