/*
* Ext JS Library 2.3.0
* Copyright(c) 2006-2009, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.grid.GroupingView=Ext.extend(Ext.grid.GridView,{hideGroupedColumn:false,showGroupName:true,startCollapsed:false,enableGrouping:true,enableGroupingMenu:true,enableNoGroups:true,emptyGroupText:'(None)',ignoreAdd:false,groupTextTpl:'{text}',gidSeed:1000,initTemplates:function(){Ext.grid.GroupingView.superclass.initTemplates.call(this);this.state={};var sm=this.grid.getSelectionModel();sm.on(sm.selectRow?'beforerowselect':'beforecellselect',this.onBeforeRowSelect,this);if(!this.startGroup){this.startGroup=new Ext.XTemplate('
','
','
');}
this.startGroup.compile();this.endGroup='
';},findGroup:function(el){return Ext.fly(el).up('.x-grid-group',this.mainBody.dom);},getGroups:function(){return this.hasRows()?this.mainBody.dom.childNodes:[];},onAdd:function(){if(this.enableGrouping&&!this.ignoreAdd){var ss=this.getScrollState();this.refresh();this.restoreScroll(ss);}else if(!this.enableGrouping){Ext.grid.GroupingView.superclass.onAdd.apply(this,arguments);}},onRemove:function(ds,record,index,isUpdate){Ext.grid.GroupingView.superclass.onRemove.apply(this,arguments);var g=document.getElementById(record._groupId);if(g&&g.childNodes[1].childNodes.length<1){Ext.removeNode(g);}
this.applyEmptyText();},refreshRow:function(record){if(this.ds.getCount()==1){this.refresh();}else{this.isUpdating=true;Ext.grid.GroupingView.superclass.refreshRow.apply(this,arguments);this.isUpdating=false;}},beforeMenuShow:function(){var field=this.getGroupField();var g=this.hmenu.items.get('groupBy');if(g){g.setDisabled(this.cm.config[this.hdCtxIndex].groupable===false);}
var s=this.hmenu.items.get('showGroups');if(s){s.setDisabled(!field&&this.cm.config[this.hdCtxIndex].groupable===false);s.setChecked(!!field,true);}},renderUI:function(){Ext.grid.GroupingView.superclass.renderUI.call(this);this.mainBody.on('mousedown',this.interceptMouse,this);if(this.enableGroupingMenu&&this.hmenu){this.hmenu.add('-',{id:'groupBy',text:this.groupByText,handler:this.onGroupByClick,scope:this,iconCls:'x-group-by-icon'});if(this.enableNoGroups){this.hmenu.add({id:'showGroups',text:this.showGroupsText,checked:true,checkHandler:this.onShowGroupsClick,scope:this});}
this.hmenu.on('beforeshow',this.beforeMenuShow,this);}},onGroupByClick:function(){this.grid.store.groupBy(this.cm.getDataIndex(this.hdCtxIndex));this.beforeMenuShow();},onShowGroupsClick:function(mi,checked){if(checked){this.onGroupByClick();}else{this.grid.store.clearGrouping();}},toggleGroup:function(group,expanded){this.grid.stopEditing(true);group=Ext.getDom(group);var gel=Ext.fly(group);expanded=expanded!==undefined?expanded:gel.hasClass('x-grid-group-collapsed');this.state[gel.dom.id]=expanded;gel[expanded?'removeClass':'addClass']('x-grid-group-collapsed');},toggleAllGroups:function(expanded){var groups=this.getGroups();for(var i=0,len=groups.length;i