Ext.ns("feyaSoft.oilAccount.share.search");feyaSoft.oilAccount.share.search.ListProduct=function(config){this.config=config;this.myPageSize=20;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:10,hidden:true},{header:"Photo",width:110,dataIndex:"imagepath",fixed:true,renderer:this.renderPhoto.createDelegate(this)},{header:"Product Name",width:250,dataIndex:"productName"},{header:"Company",width:250,dataIndex:"company"},{header:"companyId",width:10,dataIndex:"companyId",hidden:true},{header:"Description",dataIndex:"keywords",width:10,hidden:true},{header:"Country",width:70,dataIndex:"country"}]);itemCM.defaultSortable=true;this.itemStore=new Ext.data.JsonStore({url:"accountProductsEquipment/list",remoteSort:true,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","country","company","companyId"],checkIndexes:["productName"],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.ListProduct.superclass.constructor.call(this,{region:"center",store:this.itemStore,cls:"oilaccount-search-items-searchField",cm:itemCM,sm:selectBoxModel,loadMask:{msg:"loading data ..."},tbar:this.menubar,plugins:[this.searchfield],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=108 valign='top'><div id='oilaccount-search-company-img'><img name='companyImage' id="+record.data.id+"  width='100px'  style='cursor:pointer' src='"+record.data.imagepath+"'></a></div></td><td>"+record.data.keywords+"</td></tr></table>";return"x-grid3-row-expanded"}}})}else{feyaSoft.oilAccount.share.search.ListProduct.superclass.constructor.call(this,{region:"center",store:this.itemStore,cls:"oilaccount-search-items-searchField",cm:itemCM,sm:selectBoxModel,loadMask:{msg:"loading data ..."},tbar:[],plugins:[this.searchfield],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=108><div id='oilaccount-search-company-img'><img name='companyImage' id="+record.data.id+"  width='100px' style='cursor:pointer' src='"+record.data.imagepath+"'></a></div></td><td>"+record.data.keywords+"</td></tr></table>";return"x-grid3-row-expanded"}}})}this.on("rowclick",this.onRowclick,this)};Ext.extend(feyaSoft.oilAccount.share.search.ListProduct,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.companyId+"&productId="+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}})},loadKeyword:function(name){this.searchfield.clearQuery();this.searchfield.setValue(name)},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""},onRowdblclick:function(grid,rowIndex,e){var data=this.itemStore.getAt(rowIndex).data;data.url="accountCompany?id="+data.companyId+"&productId="+data.id;this.showTab(data,false)},onRowclick:function(grid,rowIndex,e){var data=this.itemStore.getAt(rowIndex).data;data.url="accountCompany?id="+data.companyId+"&productId="+data.id;this.showTab(data,true)},showTab:function(data,isHide){var uniqueId="myProductSearch-"+data.companyId;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.productName,uniqueId,isHide,data.companyId,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})}});
