Ext.ns("feyaSoft.oilAccount.account.home");feyaSoft.oilAccount.account.home.PreferSitesWin=function(config){this.config=config||{};this.menubar=[{text:"Add Cat",iconCls:"addItem",handler:function(){new feyaSoft.oilAccount.account.home.CreateEditPreferSiteCategory({myOwner:this})},scope:this},{text:"Add Site",iconCls:"addItem",handler:function(){var node=this.fileTree.selModel.selNode;if(node){new feyaSoft.oilAccount.account.home.CreateEditPreferSite({myOwner:this,categoryId:node.id})}else{Ext.MessageBox.alert("Errors","Please select one of node to process.")}},scope:this},"-",{text:"Edit Cat",iconCls:"editItem",handler:function(){var node=this.fileTree.selModel.selNode;if(node){new feyaSoft.oilAccount.account.home.CreateEditPreferSiteCategory({myOwner:this,id:node.id})}else{Ext.MessageBox.alert("Errors","Please select one of node to process.")}},scope:this}];this.urlLoader=new Ext.tree.TreeLoader({dataUrl:"accountPreferredSiteCategory/listTree",baseParams:{id:"0",activeOnly:"yes"}});this.fileTree=new Ext.tree.TreePanel({id:"PreferSitesWin-file-tree",loader:this.urlLoader,rootVisible:false,lines:false,border:false,autoScroll:true,root:new Ext.tree.AsyncTreeNode({text:"ROOT",expandable:true,draggable:false,cls:"folder",expanded:true,id:"0"})});this.fileTree.on("click",this.onClickHandler,this);if(USR_GLOBAL_INFO.myPermssion=="7"){this.westPanel=new Ext.Panel({region:"west",split:true,width:220,height:400,collapsible:true,border:true,layout:"fit",tbar:this.menubar,layoutConfig:{animate:true},items:[this.fileTree]})}else{this.westPanel=new Ext.Panel({region:"west",split:true,width:220,height:400,collapsible:true,border:true,layout:"fit",layoutConfig:{animate:true},items:[this.fileTree]})}this.centerPanel=new feyaSoft.oilAccount.account.home.PreferSitesList(this.config);feyaSoft.oilAccount.account.home.PreferSitesWin.superclass.constructor.call(this,{title:"Add Favorite Site",width:800,height:400,layout:"border",plain:true,shim:false,modal:true,animCollapse:false,constrainHeader:true,items:[this.westPanel,this.centerPanel]});this.show();this.fileTree.getLoader().on("load",function(){try{this.fileTree.getRootNode().firstChild.select();var folderId=this.fileTree.getRootNode().firstChild.id;this.centerPanel.reloadByCategory(folderId)}catch(e){}},this,{single:true})};Ext.extend(feyaSoft.oilAccount.account.home.PreferSitesWin,Ext.Window,{reloadTree:function(){this.fileTree.root.reload({delay:750})},reload:function(){this.centerPanel.reload()},onContextMenu:function(node,e){if(!this.meun){this.menu=new Ext.menu.Menu({id:"menus",items:[{id:"editCategory",iconCls:"editItem",text:"Edit",scope:this,handler:function(){var node=this.fileTree.selModel.selNode;new feyaSoft.oilAccount.account.home.CreateEditPreferSiteCategory({myOwner:this,id:node.id})}}]})}node.select();this.menu.showAt(e.getXY())},onClickHandler:function(node,obj,options){this.centerPanel.reloadByCategory(node.id)}});feyaSoft.oilAccount.account.home.PreferSitesList=function(config){this.config=config||{};Ext.apply(this,config);var selectBoxModel=new Ext.grid.CheckboxSelectionModel();selectBoxModel.on("selectionchange",function(sm){if(sm.getSelections().length==1){Ext.getCmp("preferSite-delete-button").enable();Ext.getCmp("preferSite-edit-button").enable()}else{Ext.getCmp("preferSite-delete-button").disable();Ext.getCmp("preferSite-edit-button").disable()}},this);var cm=new Ext.grid.ColumnModel([{id:"id",header:"Identify",dataIndex:"id",width:100,hidden:true},{header:"Photo",dataIndex:"",sortable:true,width:110,fixed:true},{header:"OrderIn",dataIndex:"orderIn",width:10,hidden:true},{header:"url",dataIndex:"url",width:10,hidden:true},{header:"Name",dataIndex:"name",sortable:true,width:200,renderer:this.renderName}]);this.siteStore=new Ext.data.JsonStore({autoDestroy:true,url:"accountPreferredSite/list",fields:[]});this.menubar=[{id:"preferSite-edit-button",text:"Edit",iconCls:"editItem",disabled:true,handler:function(){var record=this.getSelectionModel().getSelected();new feyaSoft.oilAccount.account.home.CreateEditPreferSite({myOwner:this,editId:record.data.id})},scope:this},"-",{id:"preferSite-delete-button",text:"Delete",tooltip:"Delete the selected item",iconCls:"remove",disabled:true,handler:function(){var record=this.getSelectionModel().getSelected();this.deleteItem(record)},scope:this}];if(USR_GLOBAL_INFO.myPermssion=="7"){feyaSoft.oilAccount.account.home.PreferSitesList.superclass.constructor.call(this,{region:"center",border:true,layout:"fit",cm:cm,sm:selectBoxModel,autoScroll:false,stripeRows:true,store:this.siteStore,tbar:this.menubar,forceLayout:true,viewConfig:{forceFit:true,enableRowBody:true,getRowClass:function(record,rowIndex,p,store){var siteId="site_url-"+record.data.id;p.body="<table><tr><td><div id='oilaccount-prefer-site-img'><img style='width:100px;' src='"+record.data.imagepath+"'></div></td><td>&nbsp;&nbsp;</td><td WIDTH=500>"+record.data.description+"<br><br><div class='preferSites-button'><input name='prefersite' type='button' id="+siteId+" value='Add Me'></div></td></tr></table>";return"x-grid3-row-expanded"}}})}else{feyaSoft.oilAccount.account.home.PreferSitesList.superclass.constructor.call(this,{region:"center",border:true,layout:"fit",cm:cm,autoScroll:false,stripeRows:true,store:this.siteStore,forceLayout:true,viewConfig:{forceFit:true,enableRowBody:true,getRowClass:function(record,rowIndex,p,store){var siteId="site_url-"+record.data.id;p.body="<table><tr><td><div id='oilaccount-prefer-site-img'><img style='width:100px;' src='"+record.data.imagepath+"'></div></td><td>&nbsp;&nbsp;</td><td WIDTH=500>"+record.data.description+"<br><br><div class='preferSites-button'><input name='prefersite' type='button' id="+siteId+" value='Add Me'></div></td></tr></table>";return"x-grid3-row-expanded"}}})}this.on("render",this.onRenderFn,this)};Ext.extend(feyaSoft.oilAccount.account.home.PreferSitesList,Ext.grid.GridPanel,{onRenderFn:function(p){p.body.on("click",this.onBodyClickFn,this)},onBodyClickFn:function(e){var target=e.getTarget();if(target.name=="prefersite"){var id=target.id;var parts=id.split("-");id=parseInt(parts[parts.length-1]);this.addImage(id)}},addImage:function(id){var type=this.config.myOwner.getType();Ext.Ajax.request({url:"accountSite/create",params:{type:type,preferSiteId:id},success:function(result,request){var backObj=Ext.util.JSON.decode(result.responseText);if(backObj.success){this.config.myOwner.reload();this.ownerCt.close()}else{Ext.MessageBox.alert("Error Message",backObj.info)}},failure:function(){Ext.Message.msgStay("Error","Fail to connect!",2000)},scope:this})},reloadByCategory:function(categoryId){this.siteStore.baseParams={categoryId:categoryId};this.siteStore.load()},reload:function(){this.siteStore.reload()},renderPhoto:function(value,metaData,record,rowIndex,colIndex,store){return value?'<img src="'+value+'"/>':""},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 item: "+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:"accountPreferredSite/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.siteStore.load()}else{Ext.MessageBox.alert("Error",jsonData.info)}},failure:function(result,request){Ext.MessageBox.alert("Failed","Internal Error, please try again")},scope:this})}}});feyaSoft.oilAccount.account.home.CreateEditPreferSiteCategory=function(config){this.myOwner=config.myOwner;Ext.QuickTips.init();Ext.form.Field.prototype.msgTarget="side";var name=new Ext.form.TextField({fieldLabel:"Category",allowBlank:false,name:"name",anchor:"90%"});var orderIn=new Ext.form.TextField({fieldLabel:"Order Seq",allowBlank:false,name:"orderIn",anchor:"90%"});var active=new Ext.ux.ComboBox({selectOnFocus:true,editable:false,mode:"local",triggerAction:"all",name:"active",fieldLabel:"Active",xtype:"combo",emptyText:"Select a status...",allowBlank:false,store:["Yes","No"]});var description=new Ext.form.TextArea({fieldLabel:"Description",name:"description",height:150,anchor:"90%"});var posurl="accountPreferredSiteCategory/createUpdate";var title="Add New Category";if(config&&config.id){title="Edit Existing Category"}var formPanel=new Ext.form.FormPanel({id:"formPanel",baseCls:"x-plain",labelWidth:120,url:posurl,defaultType:"textfield",items:[name,orderIn,active,description]});feyaSoft.oilAccount.account.home.CreateEditPreferSiteCategory.superclass.constructor.call(this,{title:title,width:500,height:280,minWidth:400,minHeight:200,layout:"fit",bodyStyle:"padding:10px;",buttonAlign:"center",shim:false,animCollapse:false,constrainHeader:true,modal:true,items:formPanel,buttons:[{text:"Save/Close",handler:function(){if(formPanel.form.isValid()){var params={};if(config&&config.id){params={id:config.id}}formPanel.form.submit({waitMsg:"Processing",params:params,failure:function(form,action){Ext.MessageBox.alert("Error Message",action.result.errorInfo)},success:function(form,action){Ext.Message.msgStay("Confirm",action.result.info,2000);this.myOwner.reloadTree();this.close()},scope:this})}else{Ext.MessageBox.alert("Errors","Please fix the errors noted.")}},scope:this},{text:"Cancel",handler:function(){this.close()},scope:this}]});this.on("afterlayout",function(){if(config.id){Ext.Ajax.request({url:"accountPreferredSiteCategory/load",method:"POST",params:{id:config.id},success:function(result,request){var jsonData=Ext.util.JSON.decode(result.responseText);if(jsonData.success=="true"){var data=jsonData.data[0];name.setValue(data.name);orderIn.setValue(data.orderIn);if(data.description){description.setValue(data.description.replace("\\n","\n"))}active.setValue("Yes")}},failure:function(result,request){Ext.MessageBox.alert("Failed","Internal Error, please try again")},scope:this})}},this,{single:true});this.show()};Ext.extend(feyaSoft.oilAccount.account.home.CreateEditPreferSiteCategory,Ext.Window,{});
