Ext.onReady(function(){ Ext.QuickTips.init(); Ext.loadMask = new Ext.LoadMask(Ext.getBody(), {msg:"加载中..."}); /** * author : sumin * time : 2011-3-28 *(0不可见1可用2不可用) * * 将菜单的id作为session的name * @memberOf {TypeName} */ Ext.override(Ext.Button,{ initComponent: Ext.Button.prototype.initComponent.createSequence(function(){ this.on({ beforerender : function(btn){ var buttonResource = {}; for(var i=0;i<ziyuanlist.length;i++){ if(ziyuanlist[i].panelid == btn.id){ buttonResource.panelid = ziyuanlist[i].panelid; buttonResource.ziyuanzhuangtai = ziyuanlist[i].ziyuanzhuangtai } } if(buttonResource.panelid == btn.id){ btn.hidden = buttonResource.ziyuanzhuangtai == 0 //不可见的状态 btn.disabled = buttonResource.ziyuanzhuangtai == 2//不可编辑的状态 alert(buttonResource.ziyuanzhuangtai) } } }); }) }) /** * @ author sumin * @time 2011 3 25 * 需要一个store,加载后台module类 * */ zyerp.system.PrimaModuleStore = Ext.extend(Ext.data.JsonStore,{ proxy : new Ext.data.HttpProxy({ url: '/zyerp/module/module!loadPrimaModules', method : "POST" }), autoLoad : false, root : "list", //不要使用Reader,会报TypeError: record is undefined totalProperty : "total", idProperty : "id", fields : [ { name : "primaModuleId", mapping : "primaModuleId", type : "int" }, { name : "panelId", mapping : "panelId", type : "string" }, { name : "name", mapping : "name", type : "string" }, { name : "visible", mapping : "visible", type : "boolean" }, { name : "icon", mapping : "icon", type : "string" }, { name : "orderNum", mapping : "orderNum", type : "int" }, { name : "resources", mapping : "resources", type : "array" } ], constructor : function(conf) { conf = conf || {}; Ext.applyIf(conf, this); zyerp.system.PrimaModuleStore.superclass.constructor.call(this, conf ); } });
/** * @auther sumin * @time 2011 3 25 21:59 * 单击事件 导航树节点单击出后加载相应界面 * contentPanel 分成每一个window的center */ zyerp.system.moduleHandler = function (module, contentPanel){ //加载的界面放置到contentPanel中 if(Ext.getCmp(module.panelid)){ contentPanel.setActiveTab(Ext.getCmp(module.panelid)); }else{ if(! module.jsfile) return; Ext.loadMask.show(); Ext.Ajax.request({ url : module.jsfile, success : function(response) { eval(response.responseText); var tab = Ext.getCmp(module.panelid); tab.show(); contentPanel.add(tab); contentPanel.doLayout(true); contentPanel.setActiveTab(tab); Ext.loadMask.hide(); }, failure : function(response) { Ext.MessageBox.alert("错误", "系统加载失败,请稍后重试或联系管理员."); Ext.loadMask.hide(); } }); } } /** * author 苏民 * time 2011-3-25 * 导航树所在的panel */ zyerp.system.oERPPanel = new Ext.Panel({ title : "功能列表", region : "west", width : 180, height : 300, layout : 'accordion', collapsible : true, layoutConfig : { activeOnTop : false, animate : false }, listeners : { afterrender : function() { zyerp.system.moduleStore.load(); } } }); /** * author : sumin * time : 2011-3-25 * 导航树 * @memberOf {TypeName} */ zyerp.system.navigaterTree = Ext.extend(Ext.tree.TreePanel,{ split : true, width : 180, autoLoad : false, autoScroll : true, rootVisible : false, module : null, initComponent : function(){ var oThis = this; this.loader = new Ext.tree.TreeLoader({ dataUrl : "/zyerp/resource/resource!loadNavigaterTreeNode", method : "post", listeners : { beforeload : function(treeloader,node){ //所在的panel this.baseParams.moduleId = oThis.module.primaModuleId this.baseParams.nodeId = node.id; }, loadexception: function(oThis, node, response) { alert(Ext.util.JSON.encode(response)); } } }); /* 根节点 */ this.root = new Ext.tree.AsyncTreeNode({ id : "0", text : "客户目录", expanded : true, leaf : false });
zyerp.system.navigaterTree.superclass.initComponent.call(this); } })
/** * @author sumin * @time 2011 3 25 * 实现erp.sys.PrimaModuleStore 监听store 的load事件 * 监听的过程中,将导航栏的菜单画出 */ zyerp.system.moduleStore = new zyerp.system.PrimaModuleStore({ listeners: { beforeload : function(s,opt){ s.loadMask = new Ext.LoadMask(zyerp.system.oERPPanel.body,{ msg : "正在加载……" }) s.loadMask.show(); }, load : function(s, records, options){ s.each(function(r){ //获得模块 if(!r) return; var module = r.data; //创建一个panel //将panel放置在界面上一个window的导航panel中 //加载该module的submodules //将加载的submodules放置成一棵树 //设置树节点的单击事件:加载对应的界面 var primaPanel = new zyerp.system.navigaterTree({ title : module.name, module : module, listeners : { expand : function() { this.doLayout();// 重新布局 }, click : function(node,e){ if(node.isLeaf()){ var module = {}; module.jsfile = node.attributes.jsfile; module.panelid = node.attributes.panelid; zyerp.system.moduleHandler(module,zyerp.system.oContent) } } } }); zyerp.system.oERPPanel.add(primaPanel) primaPanel.doLayout(); }) zyerp.system.oERPPanel.doLayout(); s.loadMask.hide(); } } })
/** * author : sumin * time : 2011-3-25 * 导航树节点单击的js在这个tabpanel中渲染 * @param {Object} t * @param {Object} p */ zyerp.system.oContent = new Ext.TabPanel({ region : "center", resizeTabs:true, // turn on tab resizing minTabWidth: 115, tabWidth:135, enableTabScroll:true, defaults: {autoScroll:true}, plugins: new Ext.ux.TabCloseMenu(), listeners : { 'tabchange': function(t, p) { t.doLayout(); } } }) /** * author : sumin * time : 2011-3-25 * 我的工作台窗口 */ zyerp.system.oDeskWin = new Ext.Window({ title: "我的工作台", x: 20, y: 20, resizable: false, minimizable: true, maximizable: true, width: 200, height: 280, layout : "border", items:[zyerp.system.oERPPanel,zyerp.system.oContent] }); zyerp.system.oDeskWin.show();
})
