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 cfg.cls += ' navbar-nav';
67 if (['tabs','pills'].indexOf(this.type) != -1) {
68 cfg.cls += ' nav-' + this.type
70 if (this.type !== 'nav') {
71 Roo.log('nav type must be nav/tabs/pills')
73 cfg.cls += ' navbar-nav'
77 if (this.parent() && this.parent().sidebar) {
80 cls: 'dashboard-menu sidebar-menu'
86 if (this.form === true) {
89 cls: 'navbar-form form-inline'
92 if (this.align === 'right') {
93 cfg.cls += ' navbar-right ml-md-auto';
95 cfg.cls += ' navbar-left';
99 if (this.align === 'right') {
100 cfg.cls += ' navbar-right ml-md-auto';
102 cfg.cls += ' mr-auto';
106 cfg.cls += ' navbar-inverse';
114 * sets the active Navigation item
115 * @param {Roo.bootstrap.NavItem} the new current navitem
117 setActiveItem : function(item)
120 Roo.each(this.navItems, function(v){
125 v.setActive(false, true);
132 item.setActive(true, true);
133 this.fireEvent('changed', this, item, prev);
138 * gets the active Navigation item
139 * @return {Roo.bootstrap.NavItem} the current navitem
141 getActive : function()
145 Roo.each(this.navItems, function(v){
156 indexOfNav : function()
160 Roo.each(this.navItems, function(v,i){
171 * adds a Navigation item
172 * @param {Roo.bootstrap.NavItem} the navitem to add
174 addItem : function(cfg)
176 if (this.form && Roo.bootstrap.version == 4) {
179 var cn = new Roo.bootstrap.NavItem(cfg);
181 cn.parentId = this.id;
182 cn.onRender(this.el, null);
186 * register a Navigation item
187 * @param {Roo.bootstrap.NavItem} the navitem to add
189 register : function(item)
191 this.navItems.push( item);
192 item.navId = this.navId;
197 * clear all the Navigation item
200 clearAll : function()
203 this.el.dom.innerHTML = '';
206 getNavItem: function(tabId)
209 Roo.each(this.navItems, function(e) {
210 if (e.tabId == tabId) {
220 setActiveNext : function()
222 var i = this.indexOfNav(this.getActive());
223 if (i > this.navItems.length) {
226 this.setActiveItem(this.navItems[i+1]);
228 setActivePrev : function()
230 var i = this.indexOfNav(this.getActive());
234 this.setActiveItem(this.navItems[i-1]);
236 clearWasActive : function(except) {
237 Roo.each(this.navItems, function(e) {
238 if (e.tabId != except.tabId && e.was_active) {
239 e.was_active = false;
246 getWasActive : function ()
249 Roo.each(this.navItems, function(e) {
264 Roo.apply(Roo.bootstrap.NavGroup, {
268 * register a Navigation Group
269 * @param {Roo.bootstrap.NavGroup} the navgroup to add
271 register : function(navgrp)
273 this.groups[navgrp.navId] = navgrp;
277 * fetch a Navigation Group based on the navigation ID
278 * @param {string} the navgroup to add
279 * @returns {Roo.bootstrap.NavGroup} the navgroup
281 get: function(navId) {
282 if (typeof(this.groups[navId]) == 'undefined') {
284 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
286 return this.groups[navId] ;