Ext.ux.TargetSelector=Ext.extend(Ext.Window,{cls:"targetSelector",modal:true,width:500,height:500,closable:false,dataUrl:false,noBrowse:false,addRequiresTarget:false,currentPath:false,selectedRecord:false,scope:false,params:{},currentFolderData:false,emptyText:"There are no folders in here",layout:"fit",initComponent:function(){this.maximized=FR.UI.layout.isPhone;this.draggable=!FR.UI.layout.isPhone;this.resizable=!FR.UI.layout.isPhone;this.initBrowser();this.backButton=new Ext.Button({cls:"backButton",iconCls:"fa-arrow-left",handler:this.goUp,scope:this,hidden:this.noBrowse});this.folderName=new Ext.Toolbar.TextItem({cls:"folderName"});if(this.defaultFolderName){this.folderName.setText(this.defaultFolderName)}Ext.each(this.buttons,function(btn){btn.scope=this},this);Ext.apply(this,{tbar:new Ext.Toolbar({cls:"topToolbar",items:[this.backButton,this.folderName,"->",{iconCls:"fa-refresh",handler:function(){this.listPanel.store.reload()},scope:this},{iconCls:"fa-close",cls:"closeButton",handler:function(){this.hide()},scope:this}]}),items:[this.listPanel],buttons:this.buttons});Ext.ux.TargetSelector.superclass.initComponent.apply(this,arguments)},initBrowser:function(){var cols=[{flex:"0 0 45px",style:"text-align:center",tpl:'<i class="fa fa-fw fa-lg {iconCls}"></i>'},{flex:"1",tpl:"{text}"}];if(!this.noBrowse){cols.push({flex:"0 0 45px",tpl:'<div class="frBtn x-btn-icon"><i class="fa fa-fw fa-chevron-right"></i></div>'})}this.listPanel=new Ext.list.ListView({singleSelect:true,loadingText:FR.T("Loading..."),emptyText:FR.T(this.emptyText),store:new Ext.data.JsonStore({url:this.dataUrl,root:"items",fields:["iconCls","text","pathname","path","section","perms"],listeners:{add:function(store,records){Ext.each(records,function(record){this.prepareRecord(record)},this)},load:function(store,records){this.currentFolderData=store.reader.jsonData;this.folderName.setText(this.currentFolderData.folderName||this.defaultFolderName||"");Ext.each(records,function(record){this.prepareRecord(record).commit()},this);if(this.onSelectionChange){this.onSelectionChange.apply(this)}if(this.onLoad){this.onLoad.apply(this)}},loadexception:function(proxy,req,resp){try{var rs=Ext.decode(resp.responseText)}catch(er){}if(rs&&rs.msg){FR.UI.feedback(rs.msg)}},scope:this}}),columns:cols,listeners:{click:function(list,idx,node,e){if(this.noBrowse){return false}if(e.getTarget("div.frBtn")){this.load(list.store.getAt(idx).get("path"))}},dblclick:function(list,idx,node,e){if(this.noBrowse){return false}this.load(list.store.getAt(idx).get("path"))},selectionchange:function(list,sel){this.selectedRecord=sel[0]?list.getRecord(sel[0]):false;if(this.onSelectionChange){this.onSelectionChange.apply(this)}},scope:this}})},addRecord:function(data){var s=this.listPanel.store;var r=new s.recordType(data);s.addSorted(r);this.listPanel.select(r);this.listPanel.scrollToRecord(r)},prepareRecord:function(record){if(!record.data.path){record.data.path=this.currentPath+"/"+(record.data.pathname||record.data.text)}if(!record.data.iconCls){record.data.iconCls="fa-folder"}return record},load:function(path){this.currentPath=path;this.listPanel.store.removeAll();if(!this.noBrowse){if(!this.defaultFolderName){this.folderName.setText("")}this.parentPath=FR.utils.pathInfo(this.currentPath).dirname;this.backButton.setVisible(this.parentPath)}this.listPanel.store.baseParams.path=path;this.listPanel.store.load()},goUp:function(){this.load(this.parentPath)},getSelectedPath:function(){return this.selectedRecord?this.selectedRecord.get("path"):this.currentPath}});