ug.DataStorage=function(A){ug.DataStorage.superclass.constructor.call(this);
Ext.apply(this,A||{});
this.addEvents("beforereset","reset","resize","change","beforeinsert","insert","beforeremove","remove","message");
this.reset()
};
Ext.extend(ug.DataStorage,Ext.util.Observable,{reset:function(){this.fireEvent("beforereset");
this.size=-1;
this.doReset();
this.fireEvent("reset")
},doReset:function(){},map:function(C,B,E,D,A){},mapIndices:function(C,B,A){},setMessage:function(A){if(this.message!=A){this.message=A;
this.fireEvent("message",A)
}},getMessage:function(){return this.message
},getSize:function(){return this.size
},setSize:function(A){if(A!=this.size){this.size=A;
this.fireEvent("resize",A)
}},contains:function(A){return(A>=0)&&(A<this.size)
},clamp:function(A){return Math.min(this.size-1,Math.max(0,A))
},getSelectCount:function(){},isSelected:function(A){},setSelected:function(A,B){},getSelection:function(){},clearSelection:function(){},getCell:function(A){},setCell:function(B,A){},fetchData:function(A,B){},filterData:function(A){},getDatum:function(A){},isDisabled:function(B){var A=this.getDatum(B);
return A&&A.disabled
},setDatum:function(B,A){this.setData(B,[A])
},setData:function(A,B){},insertDatum:function(B,A){this.insertData(B,[A])
},insertData:function(A,B){},hasData:function(B,A){},remove:function(A,B){},getSelectedData:function(A,B){},fireRegionEvent:function(B,A,C){this.fireEvent(B,A,C)
}});
ug.ArrayStorage=function(A){ug.ArrayStorage.superclass.constructor.call(this,A);
var B=(A&&A.data)||[];
this.setSize(B.length);
this.setData(0,B)
};
Ext.extend(ug.ArrayStorage,ug.DataStorage,{doReset:function(){this.data=[];
this.selected=[];
this.selectCount=0;
this.cells=[]
},map:function(D,B,F,E,A){if(typeof D=="function"){A=F;
E=B;
F=D;
B=this.size;
D=0
}for(var C=D;
C<B;
++C){A=F.call(E,this,C,A)
}return A
},mapIndices:function(E,D,C){for(var B=0,F=E.length;
B<F;
++B){var A=E[B];
D.call(C,this,A)
}},getSelectCount:function(){return this.selectCount
},isSelected:function(A){return this.contains(A)&&this.selected[A]
},setSelected:function(A,B){if(this.contains(A)&&(this.selected[A]?!B:B)){this.selectCount+=B?1:-1;
this.selected[A]=B;
return true
}return false
},getSelection:function(){var B=[];
for(var A=0;
A<this.size;
++A){if(this.selected[A]){B.push(A)
}}return B
},clearSelection:function(){var B=[];
for(var A=0;
A<this.size;
++A){if(this.selected[A]){B.push(A);
this.selected[A]=false
}}this.selectCount=0;
return B
},getCell:function(A){return this.contains(A)&&this.cells[A]
},setCell:function(B,A){if(this.contains(B)){this.cells[B]=A
}},getDatum:function(A){return this.contains(A)&&this.data[A]
},setData:function(A,C){var D=Math.min(this.size-A,C.length);
if(D>0){for(var B=0;
B<D;
++B){this.data[A+B]=C[B]
}this.fireRegionEvent("change",A,D)
}},insertData:function(A,B){var D=B.length;
if(D>0){this.fireRegionEvent("beforeinsert",A,D);
var C=new Array(D);
ug.insertArray(this.data,A,B);
ug.insertArray(this.selected,A,C);
ug.insertArray(this.cells,A,C);
this.size=Math.max(0,this.size)+D;
this.fireRegionEvent("insert",A,D)
}},hasData:function(D,A){var B=(D>=0)&&(A<=this.size);
for(var C=D;
B&&(C<A);
++C){B&=this.data[C]
}return B
},remove:function(A,E){if(typeof E=="undefined"){E=1
}E=Math.min(this.size-A,E);
if(E>0){this.fireRegionEvent("beforeremove",A,E);
this.data.splice(A,E);
var D=this.selected.splice(A,E);
this.cells.splice(A,E);
this.size=this.size-E;
var C=[];
for(var B=0;
B<E;
++B){if(D[B]){--this.selectCount
}}this.fireRegionEvent("remove",A,E)
}},getSelectedData:function(A,C){var D=[];
for(var B=0;
B<this.size;
++B){if(this.selected[B]){D.push(this.data[B])
}}A.call(C,D)
}});
ug.CellRenderer=function(A){Ext.apply(this,A||{})
};
ug.CellRenderer.prototype={height:16,cls:"",render:function(B,A){}};
ug.DataPanel=function(A){ug.DataPanel.superclass.constructor.call(this,A);
this.addEvents("focuschange","select","action")
};
Ext.extend(ug.DataPanel,Ext.BoxComponent,{hasFocus:false,focusIndex:-1,onRender:function(B,A){if(!this.el){this.el=document.createElement("div");
this.el.id=this.getId()
}ug.DataPanel.superclass.onRender.call(this,B,A);
this.el.dom.setAttribute("tabIndex",1);
this.inner=this.el.insertHtml("beforeEnd","<div class='inner'></div>",true);
if(this.storage.getSize()>0){this.onStorageResize(this.storage.getSize());
this.onStorageChange(0,this.storage.getSize())
}if(this.readOnly){this.setReadOnly(this.readOnly)
}},afterRender:function(){ug.DataPanel.superclass.afterRender.apply(this,arguments);
this.initEvents()
},initEvents:function(){this.el.on({focus:this.onFocus,blur:this.onBlur,scroll:this.onScroll,scope:this});
this.inner.on({mousedown:this.onMouseDown,dblclick:this.onDoubleClick,scope:this});
this.keyMap=new Ext.KeyMap(this.el,[{key:" ",fn:this.onSelectKey,scope:this,stopEvent:true},{key:Ext.EventObjectImpl.prototype.BACKSPACE,fn:this.onBackspaceKey,scope:this},{key:"\r\n",fn:this.onActionKey,scope:this}]);
this.storage.on({resize:this.onStorageResize,change:this.onStorageChange,beforeinsert:this.onBeforeStorageInsert,insert:this.onStorageInsert,beforeremove:this.onBeforeStorageRemove,remove:this.onStorageRemove,beforereset:this.onBeforeStorageReset,reset:this.onStorageReset,message:this.onMessage,scope:this});
this.sm.on({selectionchange:this.onSelectionChange,scope:this});
this.sm.init(this.storage,this);
this.onMessage(this.storage.getMessage())
},onMessage:function(A){if(this.message){Ext.removeNode(this.message);
delete this.message
}if(A){this.message=this.createCell(0,"message");
ug.flyChild(this.message,".inner").update(A)
}},setReadOnly:function(A){this.readOnly=A;
if(this.el){if(A){this.el.addClass("readOnly")
}else{this.el.removeClass("readOnly");
if(this.hasFocus){this.onFocus()
}}}},onDisable:function(){this.el.dom.setAttribute("tabIndex",-1)
},onEnable:function(){this.el.dom.setAttribute("tabIndex",1)
},onFocus:function(){this.hasFocus=true;
if((this.focusIndex>=0)&&!this.readOnly){var A=this.storage.getCell(this.focusIndex);
if(A){Ext.fly(A).addClass("focused")
}}},onBlur:function(){this.hasFocus=false;
if(this.focusIndex>=0){var A=this.storage.getCell(this.focusIndex);
if(A){Ext.fly(A).removeClass("focused")
}}},onScroll:Ext.emptyFn,onMouseDown:function(A){this.onMouseEvent(A,false)
},onDoubleClick:function(A){this.onMouseEvent(A,true)
},onMouseEvent:function(G,E){if(this.readOnly||(G.button!=0)){return 
}G.preventDefault();
var D=this.el.getBox(true);
var C=G.getPageY()-D.y;
var H=C+this.el.getScroll().top;
var A=this.findCell(G.getPageX()-D.x,H);
if(!this.storage.contains(A)||this.storage.isDisabled(A)){this.focus();
return 
}var B={type:"mouse",x:G.getPageX(),y:G.getPageY(),button:G.button,ctrlKey:G.ctrlKey,shiftKey:G.shiftKey};
this.fireEvent("select",A,B);
if(E){this.fireEvent("action",B)
}else{this.setFocusIndex(A,B);
this.focus();
this.dragIndex=A;
this.dragEv=Ext.applyIf({type:"drag"},B);
this.scrollTask={run:function(){this.el.scroll(this.scrollDir,this.scrollAmount,false);
var K=this.el.getBox(true);
var I=this.dragEv.x-K.x;
var L=this.dragEv.y-K.y+this.el.getScroll().top;
var J=this.findCell(I,L);
if(this.storage.contains(J)){this.dragTo(J)
}},interval:50,scope:this};
this.scrollDir=null;
var F=Ext.getDoc();
F.on("mouseup",this.onMouseUp,this);
F.on("mousemove",this.onMouseMove,this);
F.on("selectstart",this.stopSelect,this)
}},onMouseMove:function(D,E){D.preventDefault();
this.dragEv.x=D.getPageX();
this.dragEv.y=D.getPageY();
var B=this.el.getBox(true);
var H=D.getPageY()-B.y;
var G=H+this.el.getScroll().top;
var C=this.findCell(D.getPageX()-B.x,G);
if(this.storage.contains(C)&&!this.storage.isDisabled(C)){this.dragTo(C)
}var A=16-H,I=H-B.height+17,F=null;
if(A>=0){F="up";
this.scrollAmount=A
}else{if(I>=0){F="down";
this.scrollAmount=I
}}if(F!=this.scrollDir){if(this.scrollDir){Ext.TaskMgr.stop(this.scrollTask)
}this.scrollDir=F;
if(F){Ext.TaskMgr.start(this.scrollTask)
}}},findCell:function(B,C){var A=-1;
this.storage.map(function(I,F){var D=I.getCell(F);
if(D){var E=ug.flyChild(D,".inner");
var G=E.getSize();
var H=E.getOffsetsTo(this.inner);
if((B>=H[0])&&(B<H[0]+G.width)&&(C>=H[1])&&(C<H[1]+G.height)){A=F
}}},this);
return A
},dragTo:function(A){var B=(this.dragIndex<A)?1:-1;
while(this.dragIndex!=A){this.dragIndex+=B;
this.fireEvent("select",this.dragIndex,this.dragEv)
}this.setFocusIndex(A,this.dragEv,true)
},onMouseUp:function(B){B.preventDefault();
if(this.scrollDir){Ext.TaskMgr.stop(this.scrollTask)
}var A=Ext.getDoc();
A.un("mousemove",this.onMouseMove,this);
A.un("mouseup",this.onMouseUp,this);
A.un("selectstart",this.stopSelect,this)
},stopSelect:function(A){A.stopEvent();
return false
},onBackspaceKey:function(A,B){B.stopEvent()
},onSelectKey:function(A,B){this.onKeyEvent(B,false)
},onActionKey:function(A,B){this.onKeyEvent(B,true)
},onKeyEvent:function(C,B){if(this.readOnly){return 
}var A={type:"key",ctrlKey:C.ctrlKey,shiftKey:C.shiftKey};
this.fireEvent("select",this.focusIndex,A);
if(B){this.fireEvent("action",A)
}},onStorageResize:function(A){this.el.scrollTo("top",0);
if((this.focusIndex<0)&&(A>0)){this.setFocusIndex(0,null,true)
}},onBeforeStorageInsert:function(A,B){if(this.focusIndex>=A){this.focusIndex+=B
}else{if(this.focusIndex<0){this.focusIndex=0
}}},onStorageInsert:function(A,B){this.onStorageChange(A,B)
},onBeforeStorageRemove:function(A,B){if(this.focusIndex>=A+B){this.focusIndex-=B
}else{if(this.focusIndex>=A){this.onRemoveFocus=Math.min(A,this.storage.getSize()-B-1)
}}this.destroyCells(A,A+B)
},destroyCells:function(B,A){this.storage.map(B,A,function(E,D){var C=E.getCell(D);
if(C){Ext.removeNode(C);
E.setCell(D,null)
}})
},onStorageRemove:function(A,B){if(typeof this.onRemoveFocus=="number"){this.setFocusIndex(-1,null,true);
this.setFocusIndex(this.onRemoveFocus,null,true);
delete this.onRemoveFocus
}},onStorageChange:function(A,B){this.storage.map(A,A+B,function(H,F){var C=H.getCell(F);
if(!C){C=this.buildCell(H,F);
H.setCell(F,C)
}else{var E=H.getDatum(F);
if(E){var G=Ext.fly(C);
if(G.hasClass("loading")){G.removeClass("loading");
var D=ug.flyChild(G,".inner");
D.update("")
}this.renderer.render(E,C)
}}},this)
},buildCell:function(F,D,E){var C=F.getDatum(D);
var B=this.renderer.cls;
if(!C){B=B+" loading"
}if(this.hasFocus&&(D==this.focusIndex)){B=B+" focused"
}if(F.isSelected(D)){B=B+" selected"
}if(F.isDisabled(D)){B=B+" disabled disabledCell"
}var A=this.createCell(D,B,E);
if(C){this.renderer.render(C,A)
}else{ug.flyChild(A,".inner").update("Loading...")
}return A
},createCell:function(B,A){},onBeforeStorageReset:function(){this.inReset=true;
this.focusIndex=-1;
this.destroyCells(0,this.storage.getSize());
this.el.scrollTo("top",0,false);
this.onMessage(null)
},onStorageReset:function(){this.inReset=false
},onSelectionChange:function(B,A){this.storage.mapIndices(B,function(E,D){var C=E.getCell(D);
if(C){Ext.fly(C).removeClass("selected")
}});
this.storage.mapIndices(A,function(E,D){var C=E.getCell(D);
if(C&&!E.isDisabled(D)){Ext.fly(C).addClass("selected")
}})
},onNavigatePrevious:function(A){this.onNavigate(this.focusIndex-1,A)
},onNavigateNext:function(A){this.onNavigate(this.focusIndex+1,A)
},onNavigateFirst:function(A){this.onNavigate(0,A)
},onNavigateLast:function(A){this.onNavigate(this.storage.getSize()-1,A)
},onNavigate:function(A,C){var B={type:"key",ctrlKey:C.ctrlKey,shiftKey:C.shiftKey};
this.setFocusIndex(this.storage.clamp(A),B)
},findValidIndex:function(B){var C=this.storage.clamp(B);
var D=(C<this.focusIndex)?-1:1,A=false;
while(this.storage.isDisabled(C)){C+=D;
if((C<0)||(C>=this.storage.getSize())){if(A){return -1
}else{D=-D;
C+=2*D;
A=true
}}}return C
},setFocusIndex:function(E,B,C){var D=this.focusIndex;
this.focusIndex=(E<0)?-1:this.findValidIndex(E);
if(D!=this.focusIndex){if(this.hasFocus){var A=this.storage.getCell(D);
if(A){Ext.fly(A).removeClass("focused")
}A=this.storage.getCell(this.focusIndex);
if(A){Ext.fly(A).addClass("focused")
}if((C!==true)&&(this.focusIndex>=0)){this.scrollToVisible(this.focusIndex)
}}this.fireEvent("focuschange",this.focusIndex,B||{})
}},scrollToVisible:function(B){if(this.storage.contains(B)){var D=this.getCellBox(B);
if(D){var E=this.el.getScroll().top;
var C=this.el.getHeight(true);
var A=E-D.y;
var F=D.y+D.height-E-C;
if(A>0){this.el.scroll("up",A,this.animScroll)
}else{if(F>0){this.el.scroll("down",F,this.animScroll)
}}}}},getCellBox:function(C){var A=this.storage.getCell(C);
if(!A){return null
}var B=ug.flyChild(A,".inner");
var D=B.getSize();
var E=B.getOffsetsTo(this.inner);
return Ext.apply(D,{x:E[0],y:Math.round(E[1])})
}});
ug.FlowPanel=function(A){ug.FlowPanel.superclass.constructor.call(this,Ext.apply({},A,{cls:"flowPanel"}))
};
Ext.extend(ug.FlowPanel,ug.DataPanel,{initEvents:function(){ug.FlowPanel.superclass.initEvents.apply(this,arguments);
this.keyNav=new Ext.KeyNav(this.el,{left:this.onNavigatePrevious,right:this.onNavigateNext,down:this.onNavigateVertical,up:this.onNavigateVertical,pageUp:this.onNavigatePage,pageDown:this.onNavigatePage,home:this.onNavigateFirst,end:this.onNavigateLast,scope:this})
},onNavigateVertical:function(D){var G=(D.getKey()==D.DOWN)?1:-1;
var A=this.storage.getCell(this.focusIndex);
if(A){var C=this.getCellPosition(A);
var B=this.locateCell(this.focusIndex,G,function(I,H,J){if((G>0)?(J.middle>=C.bottom):(J.middle<C.top)){return Ext.apply(J,{index:I})
}});
if(B){var F=-1,E=100000;
this.locateCell(B.index-G,G,function(I,H,K){if((G>0)?(K.middle>=B.bottom):(K.middle<B.top)){return true
}var J=Math.abs(K.center-C.center);
if(J<E){F=I;
E=J
}});
if(F!=-1){this.onNavigate(F,D)
}}}},onNavigatePage:function(E){var A=this.storage.getCell(this.focusIndex);
if(A){var H=(E.getKey()==E.PAGE_DOWN)?1:-1;
var D=this.el.getHeight(true);
var C=this.getCellPosition(A);
var B=null;
this.locateCell(this.focusIndex,H,function(J,I,K){if(Math.abs(K.middle-C.middle)>D){return true
}B=Ext.apply(K,{index:J})
});
if(B){var G=-1,F=100000;
this.locateCell(B.index+H,-H,function(J,I,L){if((H<0)?(L.middle>=B.bottom):(L.middle<B.top)){return true
}var K=Math.abs(L.center-C.center);
if(K<F){G=J;
F=K
}});
if(G!=-1){this.onNavigate(G,E)
}}}},locateCell:function(C,G,D){var F=this.storage.getSize();
for(C+=G;
(C>=0)&&(C<F);
C+=G){var B=this.storage.getCell(C);
if(B){var E=this.getCellPosition(B);
var A=D.call(this,C,B,E);
if(A){return A
}}}},getCellPosition:function(A){var B=ug.flyChild(A,".inner");
var D=B.getOffsetsTo(this.inner);
var C=B.getSize(true);
return{left:D[0],center:D[0]+C.width/2,right:D[0]+C.width,top:D[1],middle:D[1]+C.height/2,bottom:D[1]+C.height}
},onStorageInsert:function(B,D){var C=(B+D<this.storage.getSize())?this.storage.getCell(B+D):null;
this.storage.map(B,B+D,function(G,F){var E=this.buildCell(G,F,C);
G.setCell(F,E)
},this);
if(C){var A=this.buildCell(this.storage,B+D,C);
this.storage.setCell(B+D,A);
Ext.removeNode(C)
}ug.FlowPanel.superclass.onStorageInsert.call(this,B,D)
},onStorageRemove:function(B,D){if((B==0)&&(this.storage.getSize()>0)){var A=this.storage.getCell(0);
if(A){var C=(this.storage.getSize()>1)?this.storage.getCell(1):null;
Ext.removeNode(A);
A=this.buildCell(this.storage,0,C);
this.storage.setCell(0,A)
}}ug.FlowPanel.superclass.onStorageRemove.call(this,B,D)
},createCell:function(C,A,E){var B=(C>0)?", ":"";
var D={tag:"span",cls:"cell "+A,cn:[B,{tag:"span",cls:"inner"}]};
return E?Ext.DomHelper.insertBefore(E,D):Ext.DomHelper.append(this.inner.dom,D)
}});
ug.SelectionModel=function(A){Ext.apply(this,A||{},{singleSelect:true,selectFocus:false});
ug.SelectionModel.superclass.constructor.call(this);
this.addEvents("selectionchange","selectionchanged")
};
Ext.extend(ug.SelectionModel,Ext.util.Observable,{ctrlMode:true,shiftStart:-1,init:function(B,A){this.storage=B;
B.on({beforeremove:this.onBeforeStorageRemove,remove:this.onChange,reset:this.onChange,scope:this});
A.on("focuschange",this.onFocusChange,this);
A.on("select",this.onSelect,this)
},onFocusChange:function(A,B){this.onSelect(A,Ext.applyIf({type:"focus",xtype:B&&B.type},B))
},onBeforeStorageRemove:function(A,C){var B=[];
this.storage.map(A,A+C,function(E,D){if(E.isSelected(D)){B.push(D)
}});
if(B.length){this.fireEvent("selectionchange",B,[])
}},onChange:function(){this.fireEvent("selectionchanged")
},onSelect:function(H,I){var B=[],E=[];
if(this.singleSelect){if(this.selectFocus||(I.type!="focus")||I.ctrlKey||I.shiftKey){if((H<0)||!this.storage.isSelected(H)){B=this.storage.clearSelection();
if(H>=0){this.storage.setSelected(H,true);
E.push(H)
}}}}else{if((I.type!="drag")&&(I.type!="focus")){this.ctrlMode=I.ctrlKey?!this.storage.isSelected(H):true
}if(((I.type!="drag")&&(I.xtype!="drag")&&!I.shiftKey)||(this.shiftStart<0)){this.shiftStart=H
}if(I.ctrlKey){if(this.storage.setSelected(H,this.ctrlMode)){if(this.ctrlMode){E.push(H)
}else{B.push(H)
}}}else{if(I.shiftKey||(I.type=="drag")){B=this.storage.clearSelection();
var G=Math.min(H,this.shiftStart),F=1+Math.max(H,this.shiftStart);
while(G<F){this.storage.setSelected(G,true);
E.push(G);
++G
}}else{if(I.type!="focus"){B=this.storage.clearSelection();
if(H>=0){this.storage.setSelected(H,true);
E.push(H)
}}}}}var G=0,F=0,C=E.length,A=B.length;
while((G<C)&&(F<A)){if(E[G]<B[F]){++G
}else{if(E[G]>B[F]){++F
}else{var D=1;
while((G+D<C)&&(F+D<A)&&(E[G+D]==B[F+D])){++D
}E.splice(G,D);
B.splice(F,D);
A-=D;
C-=D
}}}if(C||A){this.fireEvent("selectionchange",B,E);
this.fireEvent("selectionchanged")
}},clearSelection:function(){var A=this.storage.clearSelection();
if(A.length>0){this.fireEvent("selectionchange",A,[]);
this.fireEvent("selectionchanged")
}},hasSelection:function(){return this.storage.getSelectCount()>0
},getSelected:function(){var A=this.storage.getSelection();
return A.length?this.storage.getDatum(A[0]):null
}});

