WM.Website={createWebsiteGroupSelection:function(id,divIdForReturnMsg,inputFieldParentId){var domNode=Ext.get("WebsitePopupWindow");if(domNode!=null){return}var ajaxUrl="../frontend/Ajax/WebsiteControl.php";var treeGridTitle=wmGetText("Overview");var assignParentId=function(parentId,inputFieldParentId){Ext.getDom(inputFieldParentId).value=parentId};var gridDataStoreMappingArr=[{name:"dataId",type:"int",mapping:"dataId"},{name:"text",type:"string",mapping:"text"},{name:"parentDataId",type:"string",mapping:"parentDataId"},{name:"company",type:"string",mapping:"company"},{name:"primaryWeb",type:"string",mapping:"primary_web"},{name:"websitesel",type:"string",mapping:"websitesel"},{name:"applicationCustomerId",type:"string",mapping:"applicationCustomerId"},{name:"public_custnum",type:"string",mapping:"public_custnum"}];var gridColumnModelObj=new Ext.grid.ColumnModel({columns:[{header:wmGetText("ID"),dataIndex:"dataId",width:30},{header:wmGetText("Name"),dataIndex:"text",width:160,renderer:Ext.ux.renderTextWithCustomerId},{header:wmGetText("Company"),dataIndex:"company",width:150},{header:wmGetText("Web"),dataIndex:"primaryWeb",width:160}]});var wmExplorerBaseObj=new WMExplorerBase(customConfigObj,explorerType);var customConfigObj={container:{type:"window",extJsConfig:{title:treeGridTitle},topToolbars:[{extJsConfig:{items:[{id:"searchField",xtype:"textfield",emptyText:wmGetText("Enter search..."),name:"searchField",enableKeyEvents:true,allowBlank:true,listeners:{specialkey:function(thisTextField,e){var keyCode=e.getKey();if(keyCode==13){e.stopEvent();var thisContainer=wmExplorerBaseObj.getContainer();thisContainer.getLayout().setActiveItem(1);var searchPhrase=Ext.getCmp("searchField").getValue().trim();if(searchPhrase!=""){var contents=wmExplorerBaseObj.getContents();var grid=contents[1];grid.getStore().baseParams={method:"getGroupSearchDataNodes",searchPhrase:searchPhrase};grid.getStore().load()}}}}},{iconCls:"wmTbarSearch",text:wmGetText("Search"),tooltip:wmGetText("Start the search"),xtype:"button",style:"border-spacing: 0px;",handler:function(){var thisContainer=wmExplorerBaseObj.getContainer();thisContainer.getLayout().setActiveItem(1);var searchPhrase=Ext.getCmp("searchField").getValue().trim();if(searchPhrase!=""){var contents=wmExplorerBaseObj.getContents();var grid=contents[1];grid.getStore().baseParams={method:"getGroupSearchDataNodes",searchPhrase:searchPhrase};grid.getStore().load()}}},{id:"ShowTree",iconCls:"iconOverview",text:wmGetText("Overview"),tooltip:wmGetText("Show tree view"),handler:function(){var thisContainer=wmExplorerBaseObj.getContainer();thisContainer.getLayout().setActiveItem(0)}}]}}]},contents:[{type:"tree",config:{ajaxUrl:ajaxUrl,baseParams:{method:"getDefaultTreeData"},extJsOnEvents:{beforeload:function(node){if(node.isRoot==true){this.loader.baseParams={method:"getDefaultTreeData"}}else{this.loader.baseParams={method:"getTreeDataForNode",nodeDataId:node.attributes.dataId}}},click:function(node){if(node.isRoot!=true){var thisContainer=wmExplorerBaseObj.getContainer();WM.Website.changeWebsiteSel(node.attributes.websitesel,thisContainer)}},contextmenu:function(node,e){e.stopEvent();node.select();var id=node.attributes.dataId;if(id){var clickCoords=e.getXY();var contextMenu=new Ext.menu.Menu({items:[{text:wmGetText("Select all websites from folder"),handler:function(){contextMenu.destroy();if(window.confirm(wmGetText("Are you sure? This Request can take a long time!"))){var thisContainer=wmExplorerBaseObj.getContainer();WM.Website.changeToMultiWebsites(id,thisContainer,ajaxUrl)}}}]});contextMenu.showAt([clickCoords[0],clickCoords[1]])}}},rootTreeNode:{extJsConfig:{isRoot:true}},treeSorter:{extJsConfig:{folderSort:false,dir:"asc"}}}},{type:"grid",config:{ajaxUrl:ajaxUrl,baseParams:{method:"getDefaultTreeData"},extJsOnEvents:{rowclick:function(grid,rowIndex,e){var rowRecord=grid.store.getAt(rowIndex);var thisContainer=wmExplorerBaseObj.getContainer();WM.Website.changeWebsiteSel(rowRecord.data.websitesel,thisContainer)}},gridDataStoreMappingArr:gridDataStoreMappingArr,gridColumnModelObj:gridColumnModelObj,skipLoading:1}}]};try{var explorerType="treeOnlyWithSearch";var isInitialized=wmExplorerBaseObj.init(customConfigObj,explorerType);if(isInitialized==true){wmExplorerBaseObj.createWMExplorer()}}catch(e){Ext.MessageBox.alert("",e)}},changeWebsiteSel:function(id,thisWin){if(id!=""){dataController[defaultDataControllerNum].partialReset();dataController[defaultDataControllerNum].setParameter("apiParamsObj.websiteGroups",null);thisWin.destroy();window.location.href="index.php?websitesel="+id+"&websiteGroups=off"}},changeToMultiWebsites:function(groupId,thisWin,ajaxUrl){var websites=null;if(groupId>0){Ext.Ajax.request({url:ajaxUrl,success:function(response){websites=Ext.decode(response.responseText);if(websites.errors){alert(websites.errors.errorMsg)}else{if(websites!=""){thisWin.destroy();dataController[defaultDataControllerNum].partialReset();if(websites.length==1){dataController[defaultDataControllerNum].setParameter("apiParamsObj.websiteGroups",null);window.location.href="index.php?websitesel="+websites.join(",")+"&websiteGroups=off"}else{dataController[defaultDataControllerNum].setParameter("apiParamsObj.websiteGroups",websites.join(","));window.location.href="index.php?websiteGroups="+websites.join(",")}}else{alert(wmGetText("Ajax error"))}}},failure:function(response){alert(wmGetText("HTTP error"))},params:{method:"getPublicCustnums",group_id:groupId}})}}};Ext.onReady(function(){function initWebsitesel(){var customerWebsitesel=Ext.get("customerWebsite");if(typeof(customerWebsitesel)=="object"&&customerWebsitesel!=null){customerWebsitesel.on("focus",function(){WM.Website.createWebsiteGroupSelection("customerWebsiteWindow","","customerWebsite")})}var customerWebsiteselIcon=Ext.get("customerWebsiteSelectIcon");if(typeof(customerWebsitesel)=="object"&&customerWebsitesel!=null){customerWebsiteselIcon.on("click",function(){WM.Website.createWebsiteGroupSelection("customerWebsiteWindow","","customerWebsite")})}}initWebsitesel()});