Ext.namespace("Ext.ux.grid.livegrid");
Ext.ux.grid.livegrid.GridPanel=Ext.extend(Ext.grid.GridPanel,{initComponent:function(){this.cls=this.cls?this.cls+" ext-ux-livegrid":"ext-ux-livegrid";Ext.ux.grid.livegrid.GridPanel.superclass.initComponent.call(this)},onRender:function(a,b){Ext.ux.grid.livegrid.GridPanel.superclass.onRender.call(this,a,b);var c=this.getStore();!0===c._autoLoad&&(delete c._autoLoad,c.load())},walkCells:function(a,b,c,d,e){var f=this.store,g=f.getCount;f.getCount=f.getTotalCount;a=Ext.ux.grid.livegrid.GridPanel.superclass.walkCells.call(this,
a,b,c,d,e);f.getCount=g;return a}});Ext.namespace("Ext.ux.grid.livegrid");
Ext.ux.grid.livegrid.GridView=function(a){this.addEvents({reset:!0,beforebuffer:!0,buffer:!0,bufferfailure:!0,cursormove:!0,abortrequest:!0});this.horizontalScrollOffset=17;this._checkEmptyBody=!0;Ext.apply(this,a);this.templates={};this.templates.master=new Ext.Template('<div class="x-grid3" hidefocus="true"><div class="liveScroller"><div></div><div></div><div></div></div>','<div class="x-grid3-viewport"">','<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset" style="{ostyle}">{header}</div></div><div class="x-clear"></div></div>','<div class="x-grid3-scroller" style="overflow-y:hidden !important;"><div class="x-grid3-body" style="{bstyle}">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
"</div>",'<div class="x-grid3-resize-marker">&#160;</div>','<div class="x-grid3-resize-proxy">&#160;</div>',"</div>");this._gridViewSuperclass=Ext.ux.grid.livegrid.GridView.superclass;this._gridViewSuperclass.constructor.call(this)};
Ext.extend(Ext.ux.grid.livegrid.GridView,Ext.grid.GridView,{hdHeight:0,rowClipped:0,liveScroller:null,liveScrollerInsets:null,rowHeight:-1,visibleRows:1,lastIndex:-1,lastRowIndex:0,lastScrollPos:0,rowIndex:0,isBuffering:!1,requestQueue:-1,loadMask:!1,loadMaskDisplayed:!1,isPrebuffering:!1,_loadMaskAnchor:null,headerStyle:"",reset:function(a){if(!1===a){this.ds.modified=[];this.lastIndex=this.lastRowIndex=this.lastScrollPos=this.rowIndex=0;this.adjustVisibleRows();this.adjustScrollerPos(-this.liveScroller.dom.scrollTop,
!0);this.showLoadMask(!1);var b=this.processRows;this.processRows=Ext.emptyFn;this.suspendEvents();this.refresh(!0);this.resumeEvents();this.processRows=b;this.processRows(0);this.fireEvent("cursormove",this,0,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength);this.fireEvent("reset",this,a);return!1}var b={},c=this.ds.sortInfo;c&&(b={dir:c.direction,sort:c.field});this.fireEvent("reset",this,a);return this.ds.load({params:b})},renderUI:function(){var a=this.grid,b=
a.enableDragDrop||a.enableDrag;a.enableDragDrop=!1;a.enableDrag=!1;var c=this._gridViewSuperclass.renderUI.call(this),a=this.grid;a.enableDragDrop=b;if(a.enableDrag=b)this.dragZone=new Ext.ux.grid.livegrid.DragZone(a,{ddGroup:a.ddGroup||"GridDD"});return c},afterRenderUI:function(){this._gridViewSuperclass.afterRenderUI.call(this);if(this.loadMask){this._loadMaskAnchor=Ext.get(this.mainBody.dom.parentNode.parentNode);Ext.apply(this.loadMask,{msgCls:"x-mask-loading"});this._loadMaskAnchor.mask(this.loadMask.msg,
this.loadMask.msgCls);var a=this._loadMaskAnchor.dom,b=Ext.Element.data;b(a,"mask").addClass("ext-ux-livegrid");b(a,"mask").setDisplayed(!1);b(a,"maskMsg").setDisplayed(!1)}},init:function(a){this._gridViewSuperclass.init.call(this,a);a.on("expand",this._onExpand,this)},initData:function(a,b){this.ds&&(this.ds.un("bulkremove",this.onBulkRemove,this),this.ds.un("beforeload",this.onBeforeLoad,this));a&&(a.on("bulkremove",this.onBulkRemove,this),a.on("beforeload",this.onBeforeLoad,this));this._gridViewSuperclass.initData.call(this,
a,b)},renderBody:function(){var a=this.renderRows(0,this.visibleRows-1);return this.templates.body.apply({rows:a})},doRender:function(a,b,c,d,e,f){return this._gridViewSuperclass.doRender.call(this,a,b,c,d+this.ds.bufferRange[0],e,f)},initElements:function(){var a=Ext.Element,b=this.grid.getGridEl().dom.firstChild,c=b.childNodes;this.el=new a(b);this.mainWrap=new a(c[1]);this.liveScroller=new a(c[0]);b=this.liveScroller.dom.firstChild;this.liveScrollerInsets=[b,b.nextSibling,b.nextSibling.nextSibling];
this.liveScroller.on("scroll",this.onLiveScroll,this,{buffer:this.scrollDelay});this.mainHd=new a(this.mainWrap.dom.firstChild);this.innerHd=this.mainHd.dom.firstChild;this.scroller=new a(this.mainWrap.dom.childNodes[1]);this.forceFit&&this.scroller.setStyle("overflow-x","hidden");this.mainBody=new a(this.scroller.dom.firstChild);this.mainBody.on("mousewheel",this.handleWheel,this);this.focusEl=new a(this.scroller.dom.childNodes[1]);this.focusEl.swallowEvent("click",!0);this.resizeMarker=new a(c[2]);
this.resizeProxy=new a(c[3])},layout:function(){if(this.mainBody){var a=this.grid,b=a.getGridEl(),c=this.cm,b=b.getSize(!0),d=b.width;if(!(!a.hideHeaders&&20>d||20>b.height)){if(a.autoHeight)this.scroller.dom.style.overflow="visible",Ext.isWebKit&&(this.scroller.dom.style.position="static");else{b.height=void 0!=this.grid.groupingToolBar?b.height-this.grid.groupingToolBar.getHeight():b.height;this.el.setSize(b.width,b.height);var e=this.mainHd.getHeight(),e=b.height-e;this.scroller.setSize(d,e);this.innerHd&&
(this.innerHd.style.width=d+"px")}this.liveScroller.dom.style.top=this.mainHd.getHeight()+"px";this.forceFit?this.lastViewWidth!=d&&(this.fitColumns(!1,!1),this.lastViewWidth=d):this.autoExpand();this.onLayout(d,e);this.adjustVisibleRows();this.adjustBufferInset();(c=c.getColumnAt(1))&&a.fireEvent("columnresize",1,c.width)}}},removeRow:function(a){Ext.removeNode(this.getRow(a))},removeRows:function(a,b){for(var c=this.mainBody.dom,d=a;d<=b;d++)Ext.removeNode(c.childNodes[a])},getColumnStyle:function(a,
b){var c=Ext.ux.grid.livegrid.GridView.superclass.getColumnStyle.call(this,a,b);b&&(c+=this.headerStyle);return c},_onExpand:function(a){this.adjustVisibleRows();this.adjustBufferInset();this.adjustScrollerPos(this.rowHeight*this.rowIndex,!0)},onColumnMove:function(a,b,c){this.indexMap=null;this.replaceLiveRows(this.rowIndex,!0);this.updateHeaders();this.updateHeaderSortState();this.afterMove(c);this.grid.fireEvent("columnmove",b,c)},onColumnWidthUpdated:function(a,b,c){this.adjustVisibleRows();this.adjustBufferInset()},
onAllColumnWidthsUpdated:function(a,b){this.adjustVisibleRows();this.adjustBufferInset()},onRowSelect:function(a){a<this.rowIndex||a>this.rowIndex+this.visibleRows||this.addRowClass(a,this.selectedRowClass)},onRowDeselect:function(a){a<this.rowIndex||a>this.rowIndex+this.visibleRows||this.removeRowClass(a,this.selectedRowClass)},onClear:function(){this.reset(!1)},onBulkRemove:function(a,b){var c=null,d=0,d=0,e=b.length;if(0!=e){for(var f=0,g=0,k=0,h=0;h<e;h++)c=b[h][0],d=b[h][1],d=d!=Number.MIN_VALUE&&
d!=Number.MAX_VALUE?d+this.ds.bufferRange[0]:d,d<this.rowIndex?f++:d>=this.rowIndex&&d<=this.rowIndex+(this.visibleRows-1)?k++:d>=this.rowIndex+this.visibleRows&&g++,this.fireEvent("beforerowremoved",this,d,c),this.fireEvent("rowremoved",this,d,c);this.lastRowIndex=this.rowIndex=Math.max(0,Math.min(this.rowIndex-f,this.ds.totalLength-(this.visibleRows-1)));this.adjustScrollerPos(-(f*this.rowHeight),!0);this.updateLiveRows(this.rowIndex,!0);this.adjustBufferInset();this.processRows(0,void 0,!1)}},
onRemove:function(a,b,c){this.onBulkRemove(a,[[b,c]])},onAdd:function(a,b,c){this._checkEmptyBody&&("&nbsp;"==this.mainBody.dom.innerHTML&&(this.mainBody.dom.innerHTML=""),this._checkEmptyBody=!1);b=b.length;if(c==Number.MAX_VALUE||c==Number.MIN_VALUE)this.fireEvent("beforerowsinserted",this,c,c),c==Number.MIN_VALUE?(this.lastRowIndex=this.rowIndex+=b,this.adjustBufferInset(),this.adjustScrollerPos(this.rowHeight*b,!0),this.fireEvent("rowsinserted",this,c,c,b),this.processRows(0,void 0,!1),this.fireEvent("cursormove",
this,this.rowIndex,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength)):(this.adjustBufferInset(),this.fireEvent("rowsinserted",this,c,c,b));else{var d=c+this.ds.bufferRange[0],e=d+(b-1);this.getRows();d>this.rowIndex+(this.visibleRows-1)?(this.fireEvent("beforerowsinserted",this,d,e),this.fireEvent("rowsinserted",this,d,e,b),this.adjustVisibleRows(),this.adjustBufferInset()):d>=this.rowIndex&&d<=this.rowIndex+(this.visibleRows-1)?(this.lastRowIndex=this.rowIndex,this.rowIndex=
d>this.rowIndex?this.rowIndex:d,this.insertRows(a,c,c+(b-1)),this.lastRowIndex!=this.rowIndex&&this.fireEvent("cursormove",this,this.rowIndex,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength),this.adjustVisibleRows(),this.adjustBufferInset()):d<this.rowIndex&&(this.fireEvent("beforerowsinserted",this,d,e),this.lastRowIndex=this.rowIndex+=b,this.adjustVisibleRows(),this.adjustBufferInset(),this.adjustScrollerPos(this.rowHeight*b,!0),this.fireEvent("rowsinserted",this,
d,e,b),this.processRows(0,void 0,!0),this.fireEvent("cursormove",this,this.rowIndex,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength))}},onBeforeLoad:function(a,b){var c=a.proxy;c.activeRequest&&c.activeRequest[Ext.data.Api.actions.read]&&c.getConnection().abort(c.activeRequest[Ext.data.Api.actions.read]);this.fireEvent("abortrequest",a,b);this.isPreBuffering=this.isBuffering=!1;b.params=b.params||{};c=Ext.apply;c(b,{scope:this,callback:function(){this.reset(!1)},
suspendLoadEvent:!1});c(b.params,{start:0,limit:this.ds.bufferSize});return!0},onLoad:function(a,b,c){this.adjustBufferInset()},onDataChange:function(a){this.updateHeaderSortState()},liveBufferUpdate:function(a,b,c){!0===c?(this.adjustBufferInset(),this.fireEvent("buffer",this,this.ds,this.rowIndex,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength,b),this.grid.selModel.replaceSelections(a),this.isPrebuffering=this.isBuffering=!1,this.showLoadMask(!1),0<=this.requestQueue?
(a=this.requestQueue,this.requestQueue=-1,this.updateLiveRows(a)):this.isInRange(this.rowIndex)?this.replaceLiveRows(this.rowIndex,b.forceRepaint):this.updateLiveRows(this.rowIndex)):(this.fireEvent("bufferfailure",this,this.ds,b),this.requestQueue=-1,this.isPrebuffering=this.isBuffering=!1,this.showLoadMask(!1))},handleWheel:function(a){if(-1!=this.rowHeight){var b=a.getWheelDelta();this.adjustScrollerPos(-(b*this.rowHeight))}a.stopEvent()},onLiveScroll:function(){var a=Math.floor(this.liveScroller.dom.scrollTop/
this.rowHeight);this.rowIndex=a;a!=this.lastRowIndex&&(this.updateLiveRows(a),this.lastScrollPos=this.liveScroller.dom.scrollTop)},refreshRow:function(a){var b=this.ds,c;"number"==typeof a?(c=a,a=b.getAt(c)):c=b.indexOf(a);var d=c+this.ds.bufferRange[0];d<this.rowIndex||d>=this.rowIndex+this.visibleRows||this.insertRows(b,c,c,!0);this.fireEvent("rowupdated",this,d,a)},processRows:function(a,b,c){if(this.ds&&!(1>this.ds.getCount())){b=b||!this.grid.stripeRows;a=this.rowIndex;var d=this.getRows(),e=
0,f=this.grid.selModel;f.isAllSelected();for(var g=null,k=0,h=d.length;k<h;k++)g=d[k],g.rowIndex=e=a+k,g.className=g.className.replace(this.rowClsRe," "),b||0!==(e+1)%2||(g.className+=" x-grid3-row-alt"),!1!==c&&(!0===f.isSelected(this.ds.getAt(e))?this.addRowClass(e,this.selectedRowClass):this.removeRowClass(e,this.selectedRowClass),this.fly(g).removeClass("x-grid3-row-over"));0===a?Ext.fly(d[0]).addClass(this.firstRowCls):a+d.length==this.ds.totalLength&&Ext.fly(d[d.length-1]).addClass(this.lastRowCls)}},
insertRows:function(a,b,c,d){a=b+this.ds.bufferRange[0];var e=c+this.ds.bufferRange[0];d||this.fireEvent("beforerowsinserted",this,a,e);!0!==d&&this.getRows().length+(c-b)>=this.visibleRows?this.removeRows(this.visibleRows-1-(c-b),this.visibleRows-1):d&&this.removeRows(a-this.rowIndex,e-this.rowIndex);c=b==c?c:Math.min(c,this.rowIndex-this.ds.bufferRange[0]+(this.visibleRows-1));b=this.renderRows(b,c);(c=this.getRow(a))?Ext.DomHelper.insertHtml("beforeBegin",c,b):Ext.DomHelper.insertHtml("beforeEnd",
this.mainBody.dom,b);if(!0===d){b=this.getRows();c=this.rowIndex;for(var f=0,g=b.length;f<g;f++)b[f].rowIndex=c+f}d||(this.fireEvent("rowsinserted",this,a,e,e-a+1),this.processRows(0,void 0,!0))},getRow:function(a){return 0>a-this.rowIndex?null:this.getRows()[a-this.rowIndex]},getCell:function(a,b){return(a=this.getRow(a))?a.getElementsByTagName("td")[b]:null},focusCell:function(a,b,c){if(a=this.ensureVisible(a,b,c))this.focusEl.setXY(a),Ext.isGecko?this.focusEl.focus():this.focusEl.focus.defer(1,
this.focusEl)},ensureVisible:function(a,b,c){"number"!=typeof a&&(a=a.rowIndex);if(!(0>a||a>=this.ds.totalLength)){b=void 0!==b?b:0;var d=a-this.rowIndex;this.rowClipped&&a==this.rowIndex+this.visibleRows-1?this.adjustScrollerPos(this.rowHeight):a>=this.rowIndex+this.visibleRows?this.adjustScrollerPos((a-(this.rowIndex+this.visibleRows)+1)*this.rowHeight):a<=this.rowIndex&&this.adjustScrollerPos(d*this.rowHeight);var d=this.getRow(a),e;if(d){if(!1!==c||0!==b){for(;this.cm.isHidden(b);)b++;e=this.getCell(a,
b)}a=this.scroller.dom;if(!1!==c){c=parseInt(e.offsetLeft,10);b=c+e.offsetWidth;var f=parseInt(a.scrollLeft,10),g=f+a.clientWidth;c<f?a.scrollLeft=c:b>g&&(a.scrollLeft=b-a.clientWidth)}return e?Ext.fly(e).getXY():[a.scrollLeft+this.el.getX(),Ext.fly(d).getY()]}}},isRecordRendered:function(a){a=this.ds.indexOf(a);return a>=this.rowIndex&&a<this.rowIndex+this.visibleRows?!0:!1},isInRange:function(a){var b=Math.min(this.ds.totalLength-1,a+(this.visibleRows-1));return a>=this.ds.bufferRange[0]&&b<=this.ds.bufferRange[1]},
getPredictedBufferIndex:function(a,b,c){if(!b){if(a+this.ds.bufferSize>=this.ds.totalLength)return this.ds.totalLength-this.ds.bufferSize;if(Math.round(this.ds.bufferSize/2)<this.visibleRows)throw Ext.Msg.show({title:"\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435",msg:"\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043d\u0435\u043f\u0440\u0435\u0434\u0432\u0438\u0434\u0435\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.",
buttons:Ext.Msg.OK}),Error("\u0423\u0432\u0435\u043b\u0438\u0447\u044c\u0442\u0435 \u0440\u0430\u0437\u043c\u0435\u0440 \u0431\u0443\u0444\u0435\u0440\u0430");return Math.max(0,a+this.visibleRows-Math.round(this.ds.bufferSize/2))}if(!c)return Math.max(0,a-this.ds.bufferSize+this.visibleRows);if(c)return Math.max(0,Math.min(a,this.ds.totalLength-this.ds.bufferSize))},updateLiveRows:function(a,b,c){var d=this.isInRange(a);if(this.isBuffering)this.isPrebuffering&&(d?this.replaceLiveRows(a,b):this.showLoadMask(!0)),
this.fireEvent("cursormove",this,a,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength),this.requestQueue=a;else{var e=this.lastIndex;this.lastIndex=a;var d=this.isInRange(a),f=!1;if(d&&!0!==c){this.replaceLiveRows(a,b);this.fireEvent("cursormove",this,a,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength);if(a>e){if(f=!0,a+this.visibleRows+this.nearLimit<=this.ds.bufferRange[1]||this.ds.bufferRange[1]+1>=this.ds.totalLength)return}else if(a<
e){if(f=!1,0>=this.ds.bufferRange[0]||a-this.nearLimit>this.ds.bufferRange[0])return}else return;this.isPrebuffering=!0}this.isBuffering=!0;c=this.getPredictedBufferIndex(a,d,f);d||this.showLoadMask(!0);this.ds.suspendEvents();d=this.ds.sortInfo;e={};this.ds.lastOptions&&Ext.apply(e,this.ds.lastOptions.params);e.start=c;e.limit=this.ds.bufferSize;d&&(e.dir=d.direction,e.sort=d.field);b={forceRepaint:b,callback:this.liveBufferUpdate,scope:this,params:e,suspendLoadEvent:!0};this.fireEvent("beforebuffer",
this,this.ds,a,Math.min(this.ds.totalLength,this.visibleRows-this.rowClipped),this.ds.totalLength,b);this.ds.load(b);this.ds.resumeEvents()}},showLoadMask:function(a){if(this.loadMask&&a!=this.loadMaskDisplayed){var b=this._loadMaskAnchor.dom,c=Ext.Element.data,d=c(b,"mask"),b=c(b,"maskMsg");a?(d.setDisplayed(!0),b.setDisplayed(!0),b.center(this._loadMaskAnchor),!Ext.isIE||Ext.isIE7&&Ext.isStrict||"auto"!=this._loadMaskAnchor.getStyle("height")||d.setSize(void 0,this._loadMaskAnchor.getHeight())):
(d.setDisplayed(!1),b.setDisplayed(!1));this.loadMaskDisplayed=a}},replaceLiveRows:function(a,b,c){var d=a-this.lastRowIndex;if(0!=d||!0===b){b=0<d;var d=Math.abs(d),e=this.ds.bufferRange,f=a-e[0],g=Math.min(f+this.visibleRows-1,e[1]-e[0]);d>=this.visibleRows||0==d?this.mainBody.update(this.renderRows(f,g)):b?(this.removeRows(0,d-1),f+this.visibleRows-d<=e[1]-e[0]&&(d=this.renderRows(f+this.visibleRows-d,g),Ext.DomHelper.insertHtml("beforeEnd",this.mainBody.dom,d))):(this.removeRows(this.visibleRows-
d,this.visibleRows-1),d=this.renderRows(f,f+d-1),Ext.DomHelper.insertHtml("beforeBegin",this.mainBody.dom.firstChild,d));!1!==c&&this.processRows(0,void 0,!0);this.lastRowIndex=a}},adjustBufferInset:function(){var a=this.liveScroller.dom,b=this.grid,c=b.store,b=b.getGridEl().getSize().width,c=c.totalLength==this.visibleRows-this.rowClipped?0:Math.max(0,c.totalLength-(this.visibleRows-this.rowClipped));if(0==c)this.scroller.setWidth(b),a.style.display="none";else if(this.scroller.setWidth(b-this.getScrollOffset()),
a.style.display="",this.cm.getTotalWidth(),this.getScrollOffset(),contHeight=this.scroller.getHeight(),a.style.height=Math.max(contHeight,2*this.horizontalScrollOffset)+"px",-1!=this.rowHeight)for(var c=a=0==c?0:contHeight+c*this.rowHeight,b=this.liveScrollerInsets.length,a=0==a?0:Math.round(a/b),d=0;d<b;d++)d==b-1&&0!=a&&(a-=3*a-c),this.liveScrollerInsets[d].style.height=a+"px"},adjustVisibleRows:function(){if(-1==this.rowHeight)if(this.getRows()[0]){if(this.rowHeight=this.getRows()[0].offsetHeight,
0>=this.rowHeight){this.rowHeight=-1;return}}else return;var a=this.grid,b=a.store;a.getGridEl().getSize();vh=this.scroller.getHeight();a=b.totalLength||0;b=Math.max(1,Math.floor(vh/this.rowHeight));this.rowClipped=0;a>b&&this.rowHeight/3<vh-b*this.rowHeight&&(b=Math.min(b+1,a),this.rowClipped=1);this.visibleRows!=b&&(this.visibleRows=b,!this.isBuffering||this.isPrebuffering)&&(this.rowIndex+(b-this.rowClipped)>a&&(this.lastRowIndex=this.rowIndex=Math.max(0,a-(b-this.rowClipped))),this.updateLiveRows(this.rowIndex,
!0))},adjustScrollerPos:function(a,b){if(0!=a){var c=this.liveScroller,d=c.dom;!0===b&&c.un("scroll",this.onLiveScroll,this);this.lastScrollPos=d.scrollTop;d.scrollTop+=a;!0===b&&(d.scrollTop=d.scrollTop,c.on("scroll",this.onLiveScroll,this,{buffer:this.scrollDelay}))}}});Ext.namespace("Ext.ux.grid.livegrid");Ext.ux.grid.livegrid.JsonReader=function(a,b){Ext.ux.grid.livegrid.JsonReader.superclass.constructor.call(this,a,b)};
Ext.extend(Ext.ux.grid.livegrid.JsonReader,Ext.data.JsonReader,{buildExtractors:function(){if(!this.ef){var a=this.meta;a.versionProperty&&(this.getVersion=this.createAccessor(a.versionProperty));Ext.ux.grid.livegrid.JsonReader.superclass.buildExtractors.call(this)}},readRecords:function(a){this.__readRecords||(this.__readRecords=Ext.ux.grid.livegrid.JsonReader.superclass.readRecords);var b=this.__readRecords.call(this,a);this.meta.versionProperty&&(a=this.getVersion(a),b.version=void 0===a||""===
a?null:a);return b}});Ext.namespace("Ext.ux.grid.livegrid");Ext.ux.grid.livegrid.RowSelectionModel=function(a){this.addEvents({selectiondirty:!0});Ext.apply(this,a);this.allSelected=!1;this.excludes=[];this.pendingSelections={};Ext.ux.grid.livegrid.RowSelectionModel.superclass.constructor.call(this)};
Ext.extend(Ext.ux.grid.livegrid.RowSelectionModel,Ext.grid.RowSelectionModel,{initEvents:function(){Ext.ux.grid.livegrid.RowSelectionModel.superclass.initEvents.call(this);this.grid.view.on("rowsinserted",this.onAdd,this);this.grid.store.on("selectionsload",this.onSelectionsLoad,this)},onRemove:function(a,b,c){a=this.getPendingSelections();var d=a.length,e=!1;if(b==Number.MIN_VALUE||b==Number.MAX_VALUE)c&&(this.isIdSelected(c.id)&&b==Number.MIN_VALUE&&this.shiftSelections(this.grid.store.bufferRange[1],
-1),this.selections.remove(c),e=!0),b==Number.MIN_VALUE?this.clearPendingSelections(0,this.grid.store.bufferRange[0]):this.clearPendingSelections(this.grid.store.bufferRange[1]),0!=d&&this.fireEvent("selectiondirty",this,b,1);else{e=this.isIdSelected(c.id);if(!e)return;this.selections.remove(c);0!=d&&(c=a[0],b<=a[d-1]||b<=c)&&(this.shiftSelections(b,-1),this.fireEvent("selectiondirty",this,b,1))}e&&this.fireEvent("selectionchange",this)},onAdd:function(a,b,c,d){a=this.getPendingSelections();c=a.length;
if(b==Number.MIN_VALUE||b==Number.MAX_VALUE)b==Number.MIN_VALUE?(this.clearPendingSelections(0,this.grid.store.bufferRange[0]),this.shiftSelections(this.grid.store.bufferRange[1],d)):this.clearPendingSelections(this.grid.store.bufferRange[1]),0!=c&&this.fireEvent("selectiondirty",this,b,r);else{var e=a[0];if(b<=a[c-1]||b<=e)this.fireEvent("selectiondirty",this,b,d),this.shiftSelections(b,d)}},shiftSelections:function(a,b){var c=0,c=0,d={},e=this.grid.store,f=a-e.bufferRange[0],g=0,k=this.grid.store.totalLength,
g=null,h=this.getPendingSelections(),m=h.length;if(0!=m){for(var l=0;l<m;l++)if(c=h[l],!(c<a)){c+=b;g=f+b;if(c>=k)break;(g=e.getAt(g))?this.selections.add(g):d[c]=!0}this.pendingSelections=d}},onSelectionsLoad:function(a,b,c){this.replaceSelections(b)},hasNext:function(){return!1!==this.last&&this.last+1<this.grid.store.getTotalCount()},getCount:function(){return this.selections.length+this.getPendingSelections().length},isSelected:function(a){if("number"==typeof a){var b=a;a=this.grid.store.getAt(b);
if(!a)return-1!=this.getPendingSelections().indexOf(b)?!0:!1}return this.allSelected&&!this.excludes[a.id]?!0:a&&this.selections.key(a.id)?!0:!1},deselectRecord:function(a,b){if(!this.locked&&this.selections.key(a.id)){this.allSelected&&(this.excludes[a.id]=!0);var c=this.grid.store,d=c.indexOfId(a.id);-1==d?(d=c.findInsertIndex(a),d!=Number.MIN_VALUE&&d!=Number.MAX_VALUE&&(d+=c.bufferRange[0])):delete this.pendingSelections[d];this.last==d&&(this.last=!1);this.lastActive==d&&(this.lastActive=!1);
this.selections.remove(a);if(!b)this.grid.getView().onRowDeselect(d);this.fireEvent("rowdeselect",this,d,a);this.fireEvent("selectionchange",this)}},deselectRow:function(a,b){if(!this.locked){this.last==a&&(this.last=!1);this.lastActive==a&&(this.lastActive=!1);var c=this.grid.store.getAt(a);delete this.pendingSelections[a];c&&(this.allSelected&&(this.excludes[c.id]=!0),this.selections.remove(c));if(!b)this.grid.getView().onRowDeselect(a);this.fireEvent("rowdeselect",this,a,c);this.fireEvent("selectionchange",
this)}},selectRow:function(a,b,c){if(!(this.locked||0>a||a>=this.grid.store.getTotalCount())){var d=this.grid.store.getAt(a);if(!1!==this.fireEvent("beforerowselect",this,a,b,d)){b&&!this.singleSelect||this.clearSelections();d?(this.selections.add(d),delete this.pendingSelections[a],delete this.excludes[d.id]):this.pendingSelections[a]=!0;this.last=this.lastActive=a;if(!c)this.grid.getView().onRowSelect(a);this.fireEvent("rowselect",this,a,d);this.fireEvent("selectionchange",this)}}},clearPendingSelections:function(a,
b){void 0==b&&(b=Number.MAX_VALUE);for(var c={},d=this.getPendingSelections(),e=d.length,f=0,g=0;g<e;g++)f=d[g],f<=b&&f>=a||(c[f]=!0);this.pendingSelections=c},replaceSelections:function(a){if(a&&0!=a.length){for(var b=this.grid.store,c=null,d=[],e=this.getPendingSelections(),f=e.length,g=this.selections,k=0,h=0;h<f;h++)if(k=e[h],c=b.getAt(k))g.add(c),d.push(c.id),delete this.pendingSelections[k];b=null;h=0;for(len=a.length;h<len;h++)c=a[h],b=c.id,-1==d.indexOf(b)&&g.containsKey(b)&&g.add(c)}},getPendingSelections:function(a){var b=
[],c=0,d=[],e;for(e in this.pendingSelections)d.push(parseInt(e));d.sort(function(a,b){return a>b?1:a<b?-1:0});if(!a)return d;a=d.length;if(0==a)return[];b[c]=[d[0],d[0]];e=0;for(a-=1;e<a;e++)1==d[e+1]-d[e]?b[c][1]=d[e+1]:(c++,b[c]=[d[e+1],d[e+1]]);return b},clearSelections:function(a){if(!this.locked){if(!0!==a){var b=this.grid.store;a=this.selections;var c=-1;a.each(function(a){c=b.indexOfId(a.id);-1!=c&&this.deselectRow(c+b.bufferRange[0])},this);a.clear()}else this.selections.clear();this.pendingSelections=
{};this.allSelected=this.last=!1;this.excludes=[]}},selectRange:function(a,b,c){if(!this.locked)if(c||this.clearSelections(),a<=b)for(;a<=b;a++)this.selectRow(a,!0);else for(;a>=b;a--)this.selectRow(a,!0)},isAllSelected:function(){return this.allSelected},selectAll:function(){this.isLocked()||(this.excludes=[],this.selectRange(0,this.grid.store.getTotalCount(),!1),this.allSelected=!0)},getExcludes:function(){return this.excludes}});Ext.namespace("Ext.ux.grid.livegrid");
Ext.ux.grid.livegrid.Store=function(a){a=a||{};a.remoteSort=!0;this._autoLoad=a.autoLoad?!0:!1;a.autoLoad=!1;this.addEvents("bulkremove","versionchange","beforeselectionsload","selectionsload");Ext.ux.grid.livegrid.Store.superclass.constructor.call(this,a);this.totalLength=0;this.bufferRange=[-1,-1];this.on("clear",function(){this.bufferRange=[-1,-1]},this);this.url&&!this.selectionsProxy&&(this.selectionsProxy=new Ext.data.HttpProxy({url:this.url}))};
Ext.extend(Ext.ux.grid.livegrid.Store,Ext.data.Store,{version:null,insert:function(a,b){b=[].concat(b);a=a>=this.bufferSize?Number.MAX_VALUE:a;if(a==Number.MIN_VALUE||a==Number.MAX_VALUE){var c=b.length;a==Number.MIN_VALUE&&(this.bufferRange[0]+=c,this.bufferRange[1]+=c);this.totalLength+=c;this.fireEvent("add",this,b,a)}else{var c=!1,d=b;b.length+a>=this.bufferSize&&(c=!0,d=b.splice(0,this.bufferSize-a));this.totalLength+=d.length;-1>=this.bufferRange[0]&&(this.bufferRange[0]=0);this.bufferRange[1]<
this.bufferSize-1&&(this.bufferRange[1]=Math.min(this.bufferRange[1]+d.length,this.bufferSize-1));for(var e=0,f=d.length;e<f;e++)this.data.insert(a,d[e]),d[e].join(this);for(;this.getCount()>this.bufferSize;)this.data.remove(this.data.last());this.fireEvent("add",this,d,a);!0==c&&this.fireEvent("add",this,b,Number.MAX_VALUE)}},remove:function(a,b){var c=this._getIndex(a);if(0>c)return this.totalLength-=1,this.pruneModifiedRecords&&this.modified.remove(a),this.bufferRange[0]=Math.max(-1,this.bufferRange[0]-
1),this.bufferRange[1]=Math.max(-1,this.bufferRange[1]-1),!0!==b&&this.fireEvent("remove",this,a,c),c;this.bufferRange[1]=Math.max(-1,this.bufferRange[1]-1);this.data.removeAt(c);this.pruneModifiedRecords&&this.modified.remove(a);this.totalLength-=1;!0!==b&&this.fireEvent("remove",this,a,c);return c},_getIndex:function(a){var b=this.indexOfId(a.id);0>b&&(b=this.findInsertIndex(a));return b},bulkRemove:function(a){for(var b=null,c=[],d=a.length,e=[],f=0;f<d;f++)b=a[f],e[b.id]=this._getIndex(b);for(f=
0;f<d;f++)b=a[f],this.remove(b,!0),c.push([b,e[b.id]]);this.fireEvent("bulkremove",this,c)},removeAll:function(){this.totalLength=0;this.bufferRange=[-1,-1];this.data.clear();this.pruneModifiedRecords&&(this.modified=[]);this.fireEvent("clear",this)},loadRanges:function(a){if(0<a.length&&!this.selectionsProxy.activeRequest[Ext.data.Api.actions.read]&&!1!==this.fireEvent("beforeselectionsload",this,a)){a=Ext.encode(a);var b={},c;for(c in this.lastOptions)b.i=this.lastOptions.i;b.ranges=a;this.selectionsProxy.doRequest(Ext.data.Api.actions.read,
null,b,this.reader,this.selectionsLoaded,this,b)}},loadSelections:function(a){0!=a.length&&this.loadRanges(a)},selectionsLoaded:function(a,b,c){if(!1!==this.checkVersionChange(a,b,c)){c=a.records;for(var d=0,e=c.length;d<e;d++)c[d].join(this);this.fireEvent("selectionsload",this,a.records,Ext.decode(b.ranges))}else this.fireEvent("selectionsload",this,[],Ext.decode(b.ranges))},checkVersionChange:function(a,b,c){if(a&&!1!==c&&void 0!==a.version&&(b=this.version,this.version=a.version,this.version!==
b))return this.fireEvent("versionchange",this,b,this.version)},findInsertIndex:function(a){this.remoteSort=!1;a=Ext.ux.grid.livegrid.Store.superclass.findInsertIndex.call(this,a);this.remoteSort=!0;if(!(0>=this.bufferRange[0]&&0==a)){if(0<this.bufferRange[0]&&0==a)return Number.MIN_VALUE;if(a>=this.bufferSize)return Number.MAX_VALUE}return a},sortData:function(a,b){b=b||"ASC";var c=this.fields.get(a).sortType;this.data.sort(b,function(b,e){var f=c(b.data[a]),g=c(e.data[a]);return f>g?1:f<g?-1:0})},
onMetaChange:function(a,b,c){this.version=null;Ext.ux.grid.livegrid.Store.superclass.onMetaChange.call(this,a,b,c)},loadRecords:function(a,b,c){this.checkVersionChange(a,b,c);this.bufferRange=a?[b.params.start,Math.max(0,Math.min(b.params.start+b.params.limit-1,a.totalRecords-1))]:[-1,-1];!0===b.suspendLoadEvent&&this.suspendEvents();Ext.ux.grid.livegrid.Store.superclass.loadRecords.call(this,a,b,c);!0===b.suspendLoadEvent&&this.resumeEvents()},getAt:function(a){return-1==this.bufferRange[0]?void 0:
this.data.itemAt(a-this.bufferRange[0])},clearFilter:function(){},isFiltered:function(){},collect:function(){},createFilterFn:function(){},sum:function(){},filter:function(){},filterBy:function(){},query:function(){},queryBy:function(){},find:function(){},findBy:function(){}});Ext.namespace("Ext.ux.grid.livegrid");
Ext.ux.grid.livegrid.Toolbar=Ext.extend(Ext.Toolbar,{displayMsg:"Displaying {0} - {1} of {2}",emptyMsg:"No data to display",refreshText:"Refresh",initComponent:function(){Ext.ux.grid.livegrid.Toolbar.superclass.initComponent.call(this);this.grid&&(this.view=this.grid.getView());var a=this;this.view.init=this.view.init.createSequence(function(){a.bind(this)},this.view)},updateInfo:function(a,b,c){this.displayEl&&(a=0==c?this.emptyMsg:String.format(this.displayMsg,a+1,a+b,c),this.displayEl.update(a))},
unbind:function(a){var b;b=a instanceof Ext.grid.GridView?a:a.getView();a=a.ds;a.un("loadexception",this.enableLoading,this);a.un("beforeload",this.disableLoading,this);a.un("load",this.enableLoading,this);b.un("rowremoved",this.onRowRemoved,this);b.un("rowsinserted",this.onRowsInserted,this);b.un("beforebuffer",this.beforeBuffer,this);b.un("cursormove",this.onCursorMove,this);b.un("buffer",this.onBuffer,this);b.un("bufferfailure",this.enableLoading,this);this.view=void 0},bind:function(a){this.view=
a;var b=a.ds;b.on("loadexception",this.enableLoading,this);b.on("beforeload",this.disableLoading,this);b.on("load",this.enableLoading,this);a.on("rowremoved",this.onRowRemoved,this);a.on("rowsinserted",this.onRowsInserted,this);a.on("beforebuffer",this.beforeBuffer,this);a.on("cursormove",this.onCursorMove,this);a.on("buffer",this.onBuffer,this);a.on("bufferfailure",this.enableLoading,this)},enableLoading:function(){this.loading.setDisabled(!1)},disableLoading:function(){this.loading.setDisabled(!0)},
onCursorMove:function(a,b,c,d){this.updateInfo(b,c,d)},onRowsInserted:function(a,b,c){this.updateInfo(a.rowIndex,Math.min(a.ds.totalLength,a.visibleRows-a.rowClipped),a.ds.totalLength)},onRowRemoved:function(a,b,c){this.updateInfo(a.rowIndex,Math.min(a.ds.totalLength,a.visibleRows-a.rowClipped),a.ds.totalLength)},beforeBuffer:function(a,b,c,d,e,f){this.loading.disable();this.updateInfo(c,d,e)},onBuffer:function(a,b,c,d,e){this.loading.enable();this.updateInfo(c,d,e)},onClick:function(a){switch(a){case "refresh":this.view.reset(!0)?
this.loading.disable():this.loading.enable()}},onRender:function(a,b){Ext.PagingToolbar.superclass.onRender.call(this,a,b);this.loading=new Ext.Toolbar.Button({tooltip:this.refreshText,iconCls:"x-tbar-loading",handler:this.onClick.createDelegate(this,["refresh"])});this.addButton(this.loading);this.addSeparator();this.displayInfo&&(this.displayEl=Ext.fly(this.el.dom).createChild({cls:"x-paging-info"}))}});Ext.namespace("Ext.ux.grid.livegrid");
Ext.ux.grid.livegrid.DragZone=function(a,b){Ext.ux.grid.livegrid.DragZone.superclass.constructor.call(this,a,b);this.view.ds.on("beforeselectionsload",this._onBeforeSelectionsLoad,this);this.view.ds.on("selectionsload",this._onSelectionsLoad,this)};
Ext.extend(Ext.ux.grid.livegrid.DragZone,Ext.grid.GridDragZone,{isDropValid:!0,onInitDrag:function(a){this.view.ds.loadSelections(this.grid.selModel.getPendingSelections(!0));Ext.ux.grid.livegrid.DragZone.superclass.onInitDrag.call(this,a)},_onBeforeSelectionsLoad:function(){this.isDropValid=!1;Ext.fly(this.proxy.el.dom.firstChild).addClass("ext-ux-livegrid-drop-waiting")},_onSelectionsLoad:function(){this.isDropValid=!0;this.ddel.innerHTML=this.grid.getDragDropText();Ext.fly(this.proxy.el.dom.firstChild).removeClass("ext-ux-livegrid-drop-waiting")}});
Ext.namespace("Ext.ux.grid.livegrid");
Ext.ux.grid.livegrid.EditorGridPanel=Ext.extend(Ext.grid.EditorGridPanel,{initEvents:function(){Ext.ux.grid.livegrid.EditorGridPanel.superclass.initEvents.call(this);this.view.on("cursormove",this.stopEditing,this,[!0])},startEditing:function(a,b){this.stopEditing();return this.colModel.isCellEditable(b,a)&&(this.view.ensureVisible(a,b,!0),!this.store.getAt(a))?void 0:Ext.ux.grid.livegrid.EditorGridPanel.superclass.startEditing.call(this,a,b)},walkCells:function(a,b,c,d,e){return Ext.ux.grid.livegrid.GridPanel.prototype.walkCells.call(this,
a,b,c,d,e)},onRender:function(a,b){return Ext.ux.grid.livegrid.GridPanel.prototype.onRender.call(this,a,b)},initComponent:function(){this.cls=this.cls?this.cls+" ext-ux-livegrid":"ext-ux-livegrid";return Ext.ux.grid.livegrid.EditorGridPanel.superclass.initComponent.call(this)}});Ext.namespace("Ext.ux.grid.livegrid");
Ext.ux.grid.livegrid.CheckboxSelectionModel=Ext.extend(Ext.ux.grid.livegrid.RowSelectionModel,{width:20,menuDisabled:!0,sortable:!1,fixed:!0,hideable:!1,dataIndex:"",id:"checker",headerCheckbox:null,markAll:!1,isColumn:!0,constructor:function(a){this.header||(this.header=Ext.grid.CheckboxSelectionModel.prototype.header);a.checkOnly&&(this.handleMouseDown=Ext.emptyFn);a.singleSelect&&(this.singleSelect=!0);this.sortable=!1;Ext.ux.grid.livegrid.CheckboxSelectionModel.superclass.constructor.call(this)},
initEvents:function(){Ext.ux.grid.livegrid.CheckboxSelectionModel.superclass.initEvents.call(this);this.grid.view.on("reset",function(a,b){this.headerCheckbox=new Ext.Element(a.getHeaderCell(this.grid.getColumnModel().getIndexById(this.id)).firstChild);this.markAll&&!1===b&&this.headerCheckbox.addClass("x-grid3-hd-checker-on")},this);Ext.grid.CheckboxSelectionModel.prototype.initEvents.call(this)},processEvent:function(a,b,c,d,e){return"mousedown"==a?(this.onMouseDown(b,b.getTarget()),!1):Ext.grid.Column.prototype.processEvent.apply(this,
arguments)},onMouseDown:function(a,b){0===a.button&&"x-grid3-row-checker"==b.className&&(a.stopEvent(),a.getTarget(".x-grid3-row")&&this.headerCheckbox&&(this.markAll=!1,this.headerCheckbox.removeClass("x-grid3-hd-checker-on")));return Ext.grid.CheckboxSelectionModel.prototype.onMouseDown.call(this,a,b)},onHdMouseDown:function(a,b){"x-grid3-hd-checker"!=b.className||this.headerCheckbox||(this.headerCheckbox=new Ext.Element(b.parentNode));return Ext.grid.CheckboxSelectionModel.prototype.onHdMouseDown.call(this,
a,b)},renderer:function(a,b,c){return Ext.grid.CheckboxSelectionModel.prototype.renderer.call(this,a,b,c)},handleMouseDown:function(a,b,c){c.shiftKey||(this.markAll=!1,this.headerCheckbox&&this.headerCheckbox.removeClass("x-grid3-hd-checker-on"),Ext.ux.grid.livegrid.CheckboxSelectionModel.superclass.handleMouseDown.call(this,a,b,c))},clearSelections:function(a){this.isLocked()||(this.markAll=!1,this.headerCheckbox&&this.headerCheckbox.removeClass("x-grid3-hd-checker-on"),Ext.ux.grid.livegrid.CheckboxSelectionModel.superclass.clearSelections.call(this,
a))},selectAll:function(){Ext.ux.grid.livegrid.CheckboxSelectionModel.superclass.selectAll.call(this);this.markAll=!0;this.headerCheckbox&&this.headerCheckbox.addClass("x-grid3-hd-checker-on")}});
