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));
61 if (['tabs','pills'].indexOf(this.type)!==-1) {
62 cfg.cls += ' nav-' + this.type
64 if (this.type!=='nav') {
65 Roo.log('nav type must be nav/tabs/pills')
67 cfg.cls += ' navbar-nav'
70 if (this.parent() && this.parent().sidebar) {
73 cls: 'dashboard-menu sidebar-menu'
79 if (this.form === true) {
85 if (this.align === 'right') {
86 cfg.cls += ' navbar-right ml-md-auto';
88 cfg.cls += ' navbar-left';
92 if (this.align === 'right') {
93 cfg.cls += ' navbar-right ml-md-auto';
95 cfg.cls += ' mr-auto';
99 cfg.cls += ' navbar-inverse';
107 * sets the active Navigation item
108 * @param {Roo.bootstrap.NavItem} the new current navitem
110 setActiveItem : function(item)
113 Roo.each(this.navItems, function(v){
118 v.setActive(false, true);
125 item.setActive(true, true);
126 this.fireEvent('changed', this, item, prev);
131 * gets the active Navigation item
132 * @return {Roo.bootstrap.NavItem} the current navitem
134 getActive : function()
138 Roo.each(this.navItems, function(v){
149 indexOfNav : function()
153 Roo.each(this.navItems, function(v,i){
164 * adds a Navigation item
165 * @param {Roo.bootstrap.NavItem} the navitem to add
167 addItem : function(cfg)
169 var cn = new Roo.bootstrap.NavItem(cfg);
171 cn.parentId = this.id;
172 cn.onRender(this.el, null);
176 * register a Navigation item
177 * @param {Roo.bootstrap.NavItem} the navitem to add
179 register : function(item)
181 this.navItems.push( item);
182 item.navId = this.navId;
187 * clear all the Navigation item
190 clearAll : function()
193 this.el.dom.innerHTML = '';
196 getNavItem: function(tabId)
199 Roo.each(this.navItems, function(e) {
200 if (e.tabId == tabId) {
210 setActiveNext : function()
212 var i = this.indexOfNav(this.getActive());
213 if (i > this.navItems.length) {
216 this.setActiveItem(this.navItems[i+1]);
218 setActivePrev : function()
220 var i = this.indexOfNav(this.getActive());
224 this.setActiveItem(this.navItems[i-1]);
226 clearWasActive : function(except) {
227 Roo.each(this.navItems, function(e) {
228 if (e.tabId != except.tabId && e.was_active) {
229 e.was_active = false;
236 getWasActive : function ()
239 Roo.each(this.navItems, function(e) {
254 Roo.apply(Roo.bootstrap.NavGroup, {
258 * register a Navigation Group
259 * @param {Roo.bootstrap.NavGroup} the navgroup to add
261 register : function(navgrp)
263 this.groups[navgrp.navId] = navgrp;
267 * fetch a Navigation Group based on the navigation ID
268 * @param {string} the navgroup to add
269 * @returns {Roo.bootstrap.NavGroup} the navgroup
271 get: function(navId) {
272 if (typeof(this.groups[navId]) == 'undefined') {
274 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
276 return this.groups[navId] ;