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().sidebar) {
73 cls: 'dashboard-menu sidebar-menu'
79 if (this.form === true) {
85 if (this.align === 'right') {
86 cfg.cls += ' navbar-right';
88 cfg.cls += ' navbar-left';
92 if (this.align === 'right') {
93 cfg.cls += ' navbar-right';
97 cfg.cls += ' navbar-inverse';
105 * sets the active Navigation item
106 * @param {Roo.bootstrap.NavItem} the new current navitem
108 setActiveItem : function(item)
111 Roo.each(this.navItems, function(v){
116 v.setActive(false, true);
123 item.setActive(true, true);
124 this.fireEvent('changed', this, item, prev);
129 * gets the active Navigation item
130 * @return {Roo.bootstrap.NavItem} the current navitem
132 getActive : function()
136 Roo.each(this.navItems, function(v){
147 indexOfNav : function()
151 Roo.each(this.navItems, function(v,i){
162 * adds a Navigation item
163 * @param {Roo.bootstrap.NavItem} the navitem to add
165 addItem : function(cfg)
167 var cn = new Roo.bootstrap.NavItem(cfg);
169 cn.parentId = this.id;
170 cn.onRender(this.el, null);
174 * register a Navigation item
175 * @param {Roo.bootstrap.NavItem} the navitem to add
177 register : function(item)
179 this.navItems.push( item);
180 item.navId = this.navId;
185 * clear all the Navigation item
188 clearAll : function()
191 this.el.dom.innerHTML = '';
194 getNavItem: function(tabId)
197 Roo.each(this.navItems, function(e) {
198 if (e.tabId == tabId) {
208 setActiveNext : function()
210 var i = this.indexOfNav(this.getActive());
211 if (i > this.navItems.length) {
214 this.setActiveItem(this.navItems[i+1]);
216 setActivePrev : function()
218 var i = this.indexOfNav(this.getActive());
222 this.setActiveItem(this.navItems[i-1]);
224 clearWasActive : function(except) {
225 Roo.each(this.navItems, function(e) {
226 if (e.tabId != except.tabId && e.was_active) {
227 e.was_active = false;
234 getWasActive : function ()
237 Roo.each(this.navItems, function(e) {
252 Roo.apply(Roo.bootstrap.NavGroup, {
256 * register a Navigation Group
257 * @param {Roo.bootstrap.NavGroup} the navgroup to add
259 register : function(navgrp)
261 this.groups[navgrp.navId] = navgrp;
265 * fetch a Navigation Group based on the navigation ID
266 * @param {string} the navgroup to add
267 * @returns {Roo.bootstrap.NavGroup} the navgroup
269 get: function(navId) {
270 if (typeof(this.groups[navId]) == 'undefined') {
272 //this.register(new Roo.bootstrap.NavGroup({ navId : navId }));
274 return this.groups[navId] ;