Ext.ns("feyaSoft.oilAccount.share.search");feyaSoft.oilAccount.share.search.ListCompany=function(config){this.config=config;this.myPageSize=10;var selectBoxModel=new Ext.grid.CheckboxSelectionModel();this.locationStore=new Ext.data.Store({reader:new Ext.data.JsonReader({id:"id"},[{name:"id",type:"int"},{name:"name",type:"string"}]),url:"accountCompanyRegion/list"});var itemCM=new Ext.grid.ColumnModel([{id:"id",header:"Identify",dataIndex:"id",width:100,hidden:true},{header:"Photo",width:180,dataIndex:"imagepath",fixed:true,renderer:this.renderPhoto.createDelegate(this)},{header:"Company",width:250,dataIndex:"name",renderer:this.renderName},{header:"Description",dataIndex:"description",width:10,hidden:true},{header:"Location",width:70,dataIndex:"conCountry"},{header:"Sub Category",width:70,dataIndex:"subCategory"}]);this.itemStore=new Ext.data.JsonStore({url:"accountCompany/list",fields:[]});var bbar=new Ext.PagingToolbar({pageSize:this.myPageSize,store:this.itemStore,displayMsg:"Displaying {0} - {1}",plugins:new Ext.ux.ProgressBarPager(),displayInfo:true});this.searchfield=new Ext.ux.grid.Search({disableIndexes:["id","imagepath","conCountry"],width:350,position:"top"});if(this.config!=null&&this.config.loginButtonAppear){this.menubar=[{text:"&nbsp;&nbsp;Sign in&nbsp;&nbsp;",pressed:true,tooltip:"Signin to the oilaccount system",handler:function(){this.checkLogin()},scope:this},"&nbsp;"];feyaSoft.oilAccount.share.search.ListCompany.superclass.constructor.call(this,{region:"center",store:this.itemStore,cls:"oilaccount-search-items-searchField",cm:itemCM,sm:selectBoxModel,loadMask:{msg:"loading data ..."},plugins:[this.searchfield],tbar:this.menubar,bbar:bbar,border:true,autoScroll:true,viewConfig:{forceFit:true,enableRowBody:true,rowSelectorDepth:100,getRowClass:function(record,rowIndex,p,store){var imgId="selected_img_-"+record.data.id;p.body="<table><tr><td WIDTH=178><div id='oilaccount-search-company-img'><img name='companyImage' id="+record.data.id+"  width='170px' style='cursor:pointer' src='"+record.data.imagepath+"'></a></div></td><td>"+record.data.description+"</td></tr></table>";return"x-grid3-row-expanded"}}})}else{feyaSoft.oilAccount.share.search.ListCompany.superclass.constructor.call(this,{region:"center",store:this.itemStore,cls:"oilaccount-search-items-searchField",cm:itemCM,sm:selectBoxModel,loadMask:{msg:"loading data ..."},plugins:[this.searchfield],tbar:[],bbar:bbar,border:true,autoScroll:true,viewConfig:{forceFit:true,enableRowBody:true,rowSelectorDepth:100,getRowClass:function(record,rowIndex,p,store){var imgId="selected_img_-"+record.data.id;p.body="<table><tr><td WIDTH=178><div id='oilaccount-search-company-img'><img name='companyImage' id="+record.data.id+"  width='170px' style='cursor:pointer' src='"+record.data.imagepath+"'></a></div></td><td>"+record.data.description+"</td></tr></table>";return"x-grid3-row-expanded"}}})}this.on("rowclick",this.onRowclick,this)};Ext.extend(feyaSoft.oilAccount.share.search.ListCompany,Ext.grid.GridPanel,{initLoadData:function(){this.locationStore.load();this.itemStore.load({params:{start:0,limit:this.myPageSize}})},onRenderFn:function(p){p.body.on("click",this.onBodyClickFn,this)},onBodyClickFn:function(e){var target=e.getTarget();if(target.name=="companyImage"){var id=target.id;var data=this.itemStore.getById(id).data;data.url="accountCompany?id="+data.id;this.showTab(data,false)}},loadAll:function(){this.searchfield.clearQuery();this.itemStore.baseParams={};this.itemStore.load({params:{start:0,limit:this.myPageSize}})},loadCategory:function(id){this.searchfield.clearQuery();this.itemStore.baseParams={categoryId:id};this.itemStore.load({params:{start:0,limit:this.myPageSize}})},loadRegion:function(id){this.searchfield.clearQuery();this.itemStore.baseParams={regionId:id};this.itemStore.load({params:{start:0,limit:this.myPageSize}})},reload:function(){this.itemStore.reload()},renderPhoto:function(value,metaData,record,rowIndex,colIndex,store){return""},renderName:function(value,metaData,record,rowIndex,colIndex,store){return"<b>"+value+"</b>"},deleteItem:function(rd){Ext.Msg.show({title:"Confirm Delete",msg:"Do you really want to delete this company: "+rd.data.name,icon:Ext.Msg.QUESTION,buttons:Ext.Msg.YESNO,fn:this.onDeleteConfirm,scope:this,record:rd})},onDeleteConfirm:function(button_id,text,options){if(button_id=="yes"){Ext.Ajax.request({url:"accountCompany/archive",method:"POST",params:{id:options.record.data.id},success:function(result,request){var jsonData=Ext.util.JSON.decode(result.responseText);if(jsonData.success=="true"){this.itemStore.load()}else{Ext.MessageBox.alert("Error",jsonData.errorInfo)}},failure:function(result,request){Ext.MessageBox.alert("Failed","Internal Error, please try again")},scope:this})}},onRowdblclick:function(grid,rowIndex,e){var data=this.itemStore.getAt(rowIndex).data;data.url="accountCompany?id="+data.id;this.showTab(data,false)},onRowclick:function(grid,rowIndex,e){var data=this.itemStore.getAt(rowIndex).data;data.url="accountCompany?id="+data.id;this.showTab(data,true)},showTab:function(data,isHide){var uniqueId="myCompanySearch-"+data.id;if(data.url=="blank"||data.url==null||data.url.trim().length==0){Ext.MessageBox.alert("Errors","This url is empty, can not open it.")}else{Ext.getCmp("oilaccount-account-mainPanel").loadSimpleUrl(data.url,data.name,uniqueId,isHide,data.id)}},checkLogin:function(){Ext.Ajax.request({url:"userWholeAccess/isUserLogin",success:function(result,request){var jsonData=Ext.decode(result.responseText);if(jsonData.success=="true"){window.location.href="myAccount"}else{new feyaSoft.oilAccount.share.search.LoginWin()}},failure:function(result,request){new feyaSoft.oilAccount.share.search.LoginWin()},scope:this})}});
