Wtf.grid.MultiSelectionModel=function(A){Wtf.apply(this,A);this.selections=new Wtf.util.MixedCollection(false,function(B){return B.id});this.last=false;this.lastActive=false;this.selection=null;this.addEvents({"beforecellselect":true,"cellselect":true,"selectionchange":true,"beforerowselect":true,"rowselect":true,"rowdeselect":true,"multiplerowSelect":true});Wtf.grid.MultiSelectionModel.superclass.constructor.call(this)};Wtf.extend(Wtf.grid.MultiSelectionModel,Wtf.grid.AbstractSelectionModel,{singleSelect:false,initEvents:function(){if(!this.grid.enableDragDrop&&!this.grid.enableDrag){}else{this.grid.on("rowclick",function(B,D,C){if(C.button===0&&!C.shiftKey&&!C.ctrlKey){this.selectRow(D,false);B.view.focusRow(D)}},this)}this.rowNav=new Wtf.KeyNav(this.grid.getGridEl(),{"up":function(C){if(!C.shiftKey){this.selectPrevious(C.shiftKey)}else{if(this.last!==false&&this.lastActive!==false){var B=this.last;this.selectRange(this.last,this.lastActive-1);this.grid.getView().focusRow(this.lastActive);if(B!==false){this.last=B}}else{this.selectFirstRow()}}},"down":function(C){if(!C.shiftKey){this.selectNext(C.shiftKey)}else{if(this.last!==false&&this.lastActive!==false){var B=this.last;this.selectRange(this.last,this.lastActive+1);this.grid.getView().focusRow(this.lastActive);if(B!==false){this.last=B}}else{this.selectFirstRow()}}},scope:this});this.grid.on("cellmousedown",this.handleMouseDown,this);this.grid.getGridEl().on(Wtf.isIE?"keydown":"keypress",this.handleKeyDown,this);var A=this.grid.view;A.on("refresh",this.onViewChange,this);A.on("rowupdated",this.onRowUpdated,this);A.on("beforerowremoved",this.clearSelections,this);A.on("beforerowsinserted",this.clearSelections,this);if(this.grid.isEditor){this.grid.on("beforeedit",this.beforeEdit,this)}},beforeEdit:function(A){this.select(A.row,A.column,false,true,A.record)},onRowUpdated:function(A,B,C){if(this.selection&&this.selection.record==C){A.onCellSelect(B,this.selection.cell[1])}},onViewChange:function(){this.clearSelections(true)},getCount:function(){return this.selections.length},selectFirstRow:function(){this.selectRow(0)},selectLastRow:function(A){this.selectRow(this.grid.store.getCount()-1,A)},selectNext:function(A){if(this.hasNext()){this.selectRow(this.last+1,A);this.grid.getView().focusRow(this.last)}},selectPrevious:function(A){if(this.hasPrevious()){this.selectRow(this.last-1,A);this.grid.getView().focusRow(this.last)}},hasNext:function(){return this.last!==false&&(this.last+1)<this.grid.store.getCount()},hasPrevious:function(){return !!this.last},getSelections:function(){return[].concat(this.selections.items)},getSelected:function(){return this.selections.itemAt(0)},each:function(E,D){var C=this.getSelections();for(var B=0,A=C.length;B<A;B++){if(E.call(D||this,C[B],B)===false){return false}}return true},getSelectedCell:function(){return this.selection?this.selection.cell:null},deselectRow:function(B,A){if(this.locked){return }if(this.last==B){this.last=false}if(this.lastActive==B){this.lastActive=false}var C=this.grid.store.getAt(B);this.selections.remove(C);if(!A){this.grid.getView().onRowDeselect(B)}this.fireEvent("rowdeselect",this,B,C);this.fireEvent("selectionchange",this)},clearSelections:function(A){fast=false;if(this.locked){return }if(fast!==true){var C=this.grid.store;var B=this.selections;B.each(function(D){this.deselectRow(C.indexOfId(D.id),A)},this);B.clear()}else{this.selections.clear()}this.last=false;var B=this.selection;if(B){if(A!==true){this.grid.view.onCellDeselect(B.cell[0],B.cell[1])}this.selection=null;this.fireEvent("selectionchange",this,null)}},hasSelection:function(){return this.selection?true:false},isSelected:function(A){var B=typeof A=="number"?this.grid.store.getAt(A):A;return(B&&this.selections.key(B.id)?true:false)},isIdSelected:function(A){return(this.selections.key(A)?true:false)},handleMouseDown:function(E,G,A,F){if(F.button!==0||this.isLocked()){return }if(A==0){var B=this.grid.getView();if(F.shiftKey&&this.last!==false){var D=this.last;this.selectRange(D,G,F.ctrlKey);this.fireEvent("multiplerowSelect",D,G);this.last=D;B.focusRow(G)}else{var C=this.isSelected(G);if(F.ctrlKey&&C){this.deselectRow(G)}else{if(!C||this.getCount()>1){this.selectRow(G,F.ctrlKey||F.shiftKey);this.fireEvent("multiplerowSelect",D,G);B.focusRow(G)}}}}else{this.select(G,A)}},selectRange:function(A,C,D){if(this.locked){return }if(!D){this.clearSelections()}if(A<=C){for(var B=A;B<=C;B++){this.selectRow(B,true)}}else{for(var B=A;B>=C;B--){this.selectRow(B,true)}}},select:function(F,D,C,A,E){if(this.fireEvent("beforecellselect",this,F,D)!==false){this.clearSelections();E=E||this.grid.store.getAt(F);this.selection={record:E,cell:[F,D]};if(!C){var B=this.grid.getView();B.onCellSelect(F,D);if(A!==true){B.focusCell(F,D)}}this.fireEvent("cellselect",this,F,D);this.fireEvent("selectionchange",this,this.selection)}},isSelectable:function(C,B,A){return !A.isHidden(B)},handleKeyDown:function(F){if(!F.isNavKeyPress()){return }var E=this.grid,J=this.selection;if(!J){F.stopEvent();var I=E.walkCells(0,0,1,this.isSelectable,this);if(I){this.select(I[0],I[1])}return }var B=this;var H=function(M,K,L){return E.walkCells(M,K,L,B.isSelectable,B)};var C=F.getKey(),A=J.cell[0],G=J.cell[1];var D;switch(C){case F.TAB:if(F.shiftKey){D=H(A,G-1,-1);E.startEditing(A,G-1)}else{D=H(A,G+1,1);E.startEditing(A,G+1)}break;case F.DOWN:D=H(A+1,G,1);if((A+1)!=this.grid.store.getCount()){E.startEditing(A+1,G)}else{F.stopEvent()}this.selectFirstRow();break;case F.UP:D=H(A-1,G,-1);if((A)==0){F.stopEvent()}else{E.startEditing(A-1,G)}break;case F.RIGHT:D=H(A,G+1,1);E.startEditing(A,G+1);break;case F.LEFT:D=H(A,G-1,-1);E.startEditing(A,G-1);break;case F.ENTER:D=H(A+1,G,1);E.startEditing(A+1,G);if(E.isEditor&&!E.editing){F.stopEvent();return }break;default:}if(D){this.select(D[0],D[1]);F.stopEvent()}},onRowDeselect:function(A){this.removeRowClass(A,"x-grid3-row-selected")},acceptsNav:function(C,B,A){return !A.isHidden(B)&&A.isCellEditable(B,C)},onEditorKey:function(I,G){var K=this.selection;var B=this;var C=G.getKey(),D,F=this.grid,E=F.activeEditor,A=K.cell[0],H=K.cell[1];var J=function(N,L,M){return F.walkCells(N,L,M,B.isSelectable,B)};switch(C){case G.TAB:if(G.shiftKey){D=J(A,H-1,-1);F.startEditing(A,H-1)}else{D=J(A,H+1,1);F.startEditing(A,H+1)}break;case G.DOWN:D=J(A+1,H,1);if((A+1)!=this.grid.store.getCount()){F.startEditing(A+1,H)}else{G.stopEvent()}break;case G.UP:D=J(A-1,H,-1);if((A)==0){G.stopEvent()}else{F.startEditing(A-1,H)}break;case G.RIGHT:D=J(A,H+1,1);F.startEditing(A,H+1);break;case G.LEFT:D=J(A,H-1,-1);F.startEditing(A,H-1);break;case G.ESC:E.cancelEdit();F.startEditing(A,H);break;case G.ENTER:D=J(A+1,H,1);F.startEditing(A+1,H);break}},selectRow:function(B,D,A){if(this.locked||(B<0||B>=this.grid.store.getCount())){return }var C=this.grid.store.getAt(B);if(this.fireEvent("beforerowselect",this,B,D,C)!==false){if(!D||this.singleSelect){this.clearSelections()}this.selections.add(C);this.last=this.lastActive=B;if(!A){this.grid.getView().onRowSelect(B)}this.fireEvent("rowselect",this,B,C);this.fireEvent("selectionchange",this)}}})