MODx.browser.RTE=function(A){A=A||{};Ext.Ajax.defaultHeaders={modAuth:A.auth};Ext.Ajax.extraParams={HTTP_MODAUTH:A.auth};this.ident="modx-browser-"+Ext.id();this.view=MODx.load({xtype:"modx-browser-view",onSelect:{fn:this.onSelect,scope:this},prependPath:A.prependPath||null,prependUrl:A.prependUrl||null,ident:this.ident});MODx.browserOpen=true;this.tree=MODx.load({xtype:"modx-tree-directory",onUpload:function(){this.view.run();},scope:this,prependPath:A.prependPath||null,hideFiles:A.hideFiles||true,ident:this.ident,rootVisible:true,rootId:"/",rootName:_("files"),listeners:{afterUpload:{fn:function(){this.view.run();},scope:this}}});this.tree.on("click",function(B,C){this.load(B.id);},this);Ext.applyIf(A,{title:_("modx_browser"),layout:"border",renderTo:document.body,id:this.ident+"-viewport",onSelect:MODx.onBrowserReturn||function(B){},items:[{id:this.ident+"-browser-tree",cls:"modx-pb-browser-tree",region:"west",width:250,height:"100%",split:true,items:this.tree,autoScroll:true},{id:this.ident+"-browser-view",cls:"modx-pb-view-ct",region:"center",autoScroll:true,width:450,items:this.view,tbar:this.getToolbar()},{id:this.ident+"-img-detail-panel",cls:"modx-pb-details-ct",region:"east",split:true,width:200,minWidth:200,maxWidth:300},{id:this.ident+"-south",cls:"modx-pb-buttons",region:"south",split:false,bbar:["->",{id:this.ident+"-ok-btn",text:_("ok"),handler:this.onSelect,scope:this,width:200},{text:_("cancel"),handler:this.hide,scope:this,width:200}]}]});MODx.browser.RTE.superclass.constructor.call(this,A);this.config=A;};Ext.extend(MODx.browser.RTE,Ext.Viewport,{filter:function(){var A=Ext.getCmp("filter");this.view.store.filter("name",A.getValue(),true);this.view.select(0);},setReturn:function(A){this.returnEl=A;},load:function(A){A=A||"";this.view.run({dir:A,wctx:MODx.ctx});},sortImages:function(){var A=Ext.getCmp("sortSelect").getValue();this.view.store.sort(A,A=="name"?"asc":"desc");this.view.select(0);},reset:function(){if(this.rendered){Ext.getCmp("filter").reset();this.view.getEl().dom.scrollTop=0;}this.view.store.clearFilter();this.view.select(0);},getToolbar:function(){return[{text:_("filter")+":"},{xtype:"textfield",id:"filter",selectOnFocus:true,width:100,listeners:{render:{fn:function(){Ext.getCmp("filter").getEl().on("keyup",function(){this.filter();},this,{buffer:500});},scope:this}}}," ","-",{text:_("sort_by")+":"},{id:"sortSelect",xtype:"combo",typeAhead:true,triggerAction:"all",width:100,editable:false,mode:"local",displayField:"desc",valueField:"name",lazyInit:false,value:"name",store:new Ext.data.SimpleStore({fields:["name","desc"],data:[["name",_("name")],["size",_("file_size")],["lastmod",_("last_modified")]]}),listeners:{select:{fn:this.sortImages,scope:this}}},"-",{icon:MODx.config.template_url+"images/restyle/icons/refresh.png",cls:"x-btn-icon",tooltip:{text:_("tree_refresh")},handler:function(){this.load();},scope:this}];},onSelect:function(C){var B=this.view.getSelectedNodes()[0];var E=this.config.onSelect||this.onSelectHandler;var D=this.view.lookup;var A=this.config.scope;if(B&&E){var C=D[B.id];Ext.callback(E,A||this,[C]);this.fireEvent("select",C);if(window.top.opener){window.top.close();window.top.opener.focus();}}},onSelectHandler:function(A){Ext.get(this.returnEl).dom.value=unescape(A.url);}});Ext.reg("modx-browser-rte",MODx.browser.RTE);