Ext.namespace('SWeb.core'); SWeb.core.Cache = function() { var instance = null; var cache = new Ext.util.MixedCollection(); return { getInstance : function() { if (instance == null) instance = this; return instance; }, putData : function(key,data) { if (cache.containsKey(key)) { var map = cache.get(key); if(map.containsKey('sign-'+key)){ var signData=map.get('sign-'+key); var old=data.get('sign-'+key); old.status=signData.status; cache.replace(key,data); } } else { cache.add(key, data); } }, getData : function(key) { return cache.get(key); }, clearData : function() { for (var i = 0, count = cache.keys.length; i < count; i++) { var data = cache.get(cache.keys[i]); if (typeof data == 'object') { cache.replace(cache.keys[i], data.status); } } }, getAllData:function(){ return cache.items; } } }(); SWeb.core.LightBaseWindow = Ext.extend(Ext.Window, { listeners : { 'beforeadd' : function(ct, cp, pos) { var data = SWeb.core.Cache.getData(cp.helpCls); if (data != undefined) { var help = data.get('help-' + cp.helpCls); cp.help = { helpClass : cp.helpCls, url : help.url }; var signData = data.get('sign-' + cp.cls); return !signData ? true : signData.status; } else { return true; } }, 'close':function(){ var helpWnd=Ext.getCmp('id-help-wnd'); if(helpWnd != undefined){ helpWnd.close(); } } }, createHelp : function() { var data = new Array(); this.cascade(function(arg) { if (arg.help != undefined) { data.push(arg.help); } }); return data; }, appendProps : function(props) { return Ext.apply(props, { plugins : props.noChelps?null:new SWeb.plugin.Help() }); } }); SWeb.core.HeavyBaseWindow=Ext.extend(Ext.Window,{}); SWeb.core.BaseWindow = function(props) { SWeb.core.BaseWindow.superclass.constructor.call(this, this.appendProps(props)); } Ext.extend(SWeb.core.BaseWindow, READ_FROM_WHERE == FRAMEWORK_LIGHT ? SWeb.core.LightBaseWindow : SWeb.core.HeavyBaseWindow); Ext.reg('baseWnd', SWeb.core.BaseWindow); SWeb.core.LightFormPanel = Ext.extend(Ext.FormPanel, { listeners : { 'beforeadd' : function(ct, cp, pos) { var data = SWeb.core.Cache.getData(cp.helpCls); if (data != undefined) { var help = data.get('help-' + cp.helpCls); cp.help={helpClass:cp.helpCls,url:help.url}; var signData=data.get('sign-' + cp.cls); return !signData?true:signData.status; } else { return true; } }, 'render':function(ct){ if(this.provider){ var reqProvider=Ext.apply(this.provider,{scope:this}); this.provider=new SWeb.com.DataProvider(reqProvider); } }, 'show' : function() { this.focusFirstItem(); } }, focusFirstItem : function(){ }, appendProps : function(props) { var reValue; if (!props.plugins) { reValue = Ext.apply(props, { plugins : new SWeb.plugin.Help() }); } else if(props.plugins instanceof Array){ var temp=props.plugins; temp.push(new SWeb.plugin.Help()); reValue = this.props=Ext.apply(props, { plugins : temp }); }else{ var temp=[props.plugins,new SWeb.plugin.Help()]; reValue=Ext.apply(props, { plugins : temp }); } return reValue; }, createHelp:function(){ var data = new Array(); this.cascade(function(arg) { if (arg.help != undefined) { data.push(arg.help); } }); return data; } }); SWeb.core.HeavyFormPanel = Ext.extend(Ext.FormPanel, { appendProps : function(props) { return props; } }); SWeb.core.BaseFormPanel = function(props) { SWeb.core.BaseFormPanel.superclass.constructor.call(this, this.appendProps(props)); } Ext.extend(SWeb.core.BaseFormPanel, READ_FROM_WHERE == FRAMEWORK_LIGHT ? SWeb.core.LightFormPanel : SWeb.core.HeavyFormPanel); Ext.reg('baseForm', SWeb.core.BaseFormPanel); SWeb.core.LightBasePanel = Ext.extend(Ext.Panel, { listeners : { 'beforeadd' : function(ct, cp, pos) { var data = SWeb.core.Cache.getData(cp.helpCls); if (data != undefined) { var help = data.get('help-' + cp.helpCls); cp.help={helpClass:cp.helpCls,url:help.url}; var signData=data.get('sign-' + cp.cls); return !signData?true:signData.status; } else { return true; } }, 'render' : function(ct) { if (this.provider) { var reqProvider = Ext.apply(this.provider, { scope : this }); this.provider = new SWeb.com.DataProvider(reqProvider); } }, 'show' : function() { this.focusFirstItem(); } }, focusFirstItem : function(){ }, appendProps : function(props) { var reValue; if (!props.plugins) { reValue = Ext.apply(props, { plugins : new SWeb.plugin.Help() }); } else if(props.plugins instanceof Array){ var temp=props.plugins; temp.push(new SWeb.plugin.Help()); reValue = this.props=Ext.apply(props, { plugins : temp }); }else{ var temp=[props.plugins,new SWeb.plugin.Help()]; reValue=Ext.apply(props, { plugins : temp }); } return reValue; }, constructor : function(config) { config.autoWidth = false; SWeb.core.LightBasePanel.superclass.constructor.call(this, this.appendProps(config)); }, createHelp:function(){ var data = new Array(); this.cascade(function(arg) { if (arg.help != undefined) { data.push(arg.help); } }); return data; } }); SWeb.core.HeavyBasePanel=Ext.extend(Ext.Panel,{ show : function() { SWeb.core.HeavyBasePanel.superclass.show.call(this); if (this.autoHide) { var pane = this; this.getEl().fadeIn({ duration : this.period, endOpacity : 0.7, easing : 'easeOut', callback : function() { pane.hide(); pane.findParentByType(SWeb.core.BasePanel).doLayout(); } }); } }, render : function(ct, pos) { SWeb.core.HeavyBasePanel.superclass.render.call(this, ct, pos); var result = SWeb.core.BusAuthCheck.checkData({ id : this.id, type : UI_ELEMENT_TYPE_PANEL }, this); if (result != null || result != undefined) { this.boTypeId = result.boTypeID; this.genDataAuth = result.genDataAuth; var rightButtonID = this.id + '-button'; if (this.genDataAuth) { var panel = Ext.getCmp(this.id + '-buttons'); if (panel != undefined) { panel.addButton({ text : '分配数据权限', id : rightButtonID }, this.dealDataAuth, this); } } } }, dealDataAuth : function() { var data = this.getSelctedRecord(); if (data == null) { Ext.MessageBox.alert("提示", "请选择要操作的数据"); return; } var roleId = data.id != undefined ? data.id : data.pkid; var panel = eval('new SWeb.systemRightManager.dataAuthMgr.assDataAuthManager()'); var boTypeID = this.getBoTypeID(); panel.showWin(boTypeID, roleId); }, getBoTypeID : function() { return this.boTypeId; }, hasDataAuth : function() { return this.genDataAuth; }, setSelctedRecord : function(value) { this.clumnRecord = value; }, getSelctedRecord : function() { return this.clumnRecord; }, checkRightButtonState : function(buttonState) { if (buttonState) { Ext.getCmp(this.id + '-button').enable(); } else { Ext.getCmp(this.id + '-button').disable(); } } }); SWeb.core.BasePanel = function(props) { this.props = props; this.autoHide = props.autoHide != undefined ? props.autoHide : false; this.period = props.period != undefined ? props.period : 5; SWeb.core.BasePanel.superclass.constructor.call(this,props); } Ext.extend(SWeb.core.BasePanel, READ_FROM_WHERE == FRAMEWORK_LIGHT ? SWeb.core.LightBasePanel:SWeb.core.HeavyBasePanel); Ext.reg('basePanel', SWeb.core.BasePanel); SWeb.core.LightBaseButton=Ext.extend(Ext.Button,{ constructor:function(config){ if (config.data) { var action = new SWeb.cmp.SubmitAction({ text : config.text, handlers : [config.handler], handler : config.handler, data : config.data, parser : config.parser, sender : config.sender, scope : this }); SWeb.core.LightBaseButton.superclass.constructor.call(this, action); }else{ SWeb.core.LightBaseButton.superclass.constructor.call(this); } } }); SWeb.core.HeavyBaseButton = Ext.extend(Ext.Button, { initComponent : function() { SWeb.core.HeavyBaseButton.superclass.initComponent.call(this); if (this.props.isCheck == undefined) { this.props.isCheck = false; } }, render : function(ct, pos) { SWeb.core.BusAuthCheck.check({ id : this.id, type : UI_ELEMENT_TYPE_BUTTON }, SWeb.core.BaseButton.superclass.render, this, ct, pos); } }); SWeb.core.BaseButton = function(props) { this.props = props; SWeb.core.BaseButton.superclass.constructor.call(this,props); } Ext.extend(SWeb.core.BaseButton, READ_FROM_WHERE == FRAMEWORK_LIGHT ? SWeb.core.LightBaseButton:SWeb.core.HeavyBaseButton); Ext.reg('baseButton', SWeb.core.BaseButton); SWeb.core.BaseGridView = Ext.extend(Ext.grid.GridView, { doRender : function(cs, rs, ds, startRow, colCount, stripe) { var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount - 1; var tstyle = 'width:' + this.getTotalWidth() + ';'; var buf = [], cb, c, p = {}, rp = { tstyle : tstyle }, r; for (var j = 0, len = rs.length; j < len; j++) { r = rs[j]; cb = []; var rowIndex = (j + startRow); for (var i = 0; i < colCount; i++) { c = cs[i]; p.id = c.id; p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : ''); p.attr = p.cellAttr = ""; var rvalue = r.data[c.name]; if (c.encode) { rvalue = Fwlib.util.FwUtil.encode(rvalue); } if (c.encodeBlank) { rvalue = rvalue.replace(FW_REGEX_VIEW.GUANGDASERVICE6, ' '); } p.value = c.renderer(rvalue, p, r, rowIndex, i, ds); p.style = c.style; if (p.value == undefined || p.value === "") { p.value = " "; } if (this.markDirty && r.dirty && typeof r.modified[c.name] !== 'undefined') { p.css += ' x-grid3-dirty-cell'; } cb[cb.length] = ct.apply(p); } var alt = []; if (stripe && ((rowIndex + 1) % 2 == 0)) { alt[0] = "x-grid3-row-alt"; } if (r.dirty) { alt[1] = " x-grid3-dirty-row"; } rp.cols = colCount; if (this.getRowClass) { var classRow; if (classRow = this.getRowClass(r, rowIndex, rp, ds)) { alt[2] = classRow; } } rp.alt = alt.join(" "); rp.cells = cb.join(""); buf[buf.length] = rt.apply(rp); } return buf.join(""); }, getColumnData : function() { var cs = [], cm = this.cm, colCount = cm.getColumnCount(); for (var i = 0; i < colCount; i++) { var name = cm.getDataIndex(i); var config = cm.config[i]; cs[i] = { name : (typeof name == 'undefined' ? this.ds.fields.get(i).name : name), renderer : cm.getRenderer(i), id : cm.getColumnId(i), style : this.getColumnStyle(i), encode : config.encode, encodeBlank : config.encodeBlank }; } return cs; } }); SWeb.core.LightBaseGrid = Ext.extend(Ext.grid.GridPanel, { viewConfig : { forceFit : true, autoFill : true, enableRowBody : true }, render : function(ct, pos) { SWeb.core.LightBaseGrid.superclass.render.call(this, ct, pos); var data = SWeb.core.Cache.getData(this.helpCls); if (data != undefined) { var helpObj=data.get('help-' + this.helpCls); this.help = {helpClass:this.helpCls,url:helpObj.url}; } }, intercepter : function(props) { if (!props.plugins) { this.props = Ext.apply(props, { plugins : props.noChelps?null:new SWeb.plugin.Help() }); } else if(props.plugins instanceof Array){ var temp=props.plugins; temp.push(new SWeb.plugin.Help()); this.props = this.props=Ext.apply(props, { plugins : props.noChelps?null:temp }); }else{ var temp=[props.plugins,new SWeb.plugin.Help()]; this.props=Ext.apply(props, { plugins : props.noChelps?null:temp }); } }, createHelp:function() { return [this.help]; }, getView : function() { if (!this.view) { this.view = new SWeb.core.BaseGridView(this.viewConfig); } return this.view; }, enableHdMenu :false }); SWeb.core.HeavyBaseGrid=Ext.extend(Ext.grid.GridPanel,{ intercepter : function(props) { var columns = [DATA_AUTH_EXSIT, DATA_AUTH_READ, DATA_AUTH_MANAGE, DATA_AUTH_TYPE, DATA_AUTH_WRITE]; if (props.store.reader != undefined) { if (props.store.reader instanceof Ext.data.JsonReader) { this.replaceJsonReader(props, columns); } if (props.store.reader instanceof Ext.data.XmlReader) { this.replaceXmlReader(props, columns); } } }, replaceXmlReader : function(props, columns) { }, replaceStoreField : function(props, columns) { var fields = this.decorate(props.store.fields, columns); Ext.apply(props.store.fields, fields); this.props = props; }, replaceJsonReader : function(props, columns) { var temp = props.store.reader.meta.fields == undefined ? props.store.fields.items : props.store.reader.meta.fields; var fields = this.decorate(temp, columns); Ext.apply(props.store.reader, new Ext.data.JsonReader({ totalProperty : props.store.reader.meta.totalProperty, root : props.store.reader.meta.root, fields : fields })) this.props = props; }, decorate : function(fields, columns) { for (var i = 0; i < columns.length; i++) { if (columns[i] == DATA_AUTH_TYPE) { fields.push({ name : columns[i], type : 'int' }); } else { fields.push({ name : columns[i], type : 'boolean' }); } } return fields; }, listeners : { 'click' : function(eventObj) { var value = this.getSelectionModel().getSelected(); if (value == 'undefined' || value == undefined || this.findParentByType(SWeb.core.BasePanel) == null) { return; } var parentPanel = this.findParentByType(SWeb.core.BasePanel).items.items[0]; var hasDataAuth = parentPanel.hasDataAuth(); parentPanel.setSelctedRecord(value.data); if (value != undefined && hasDataAuth) { SWeb.core.BusAuthCheck.push(value); var keys = [DATA_AUTH_READ, DATA_AUTH_MANAGE, DATA_AUTH_WRITE]; for (var i = 0; i < keys.length; i++) { if (value.get(keys[i])) { var btns = SWeb.core.BusAuthCheck .getDataAuthItems(keys[i]); for (var j = 0; btns != undefined && j < btns.length; j++) { if (parentPanel.getBoTypeID() == btns[j].boTypeId) { Ext.getCmp(btns[j].id).enable(); } } } else { var btns = SWeb.core.BusAuthCheck .getDataAuthItems(keys[i]); for (var j = 0; btns != undefined && j < btns.length; j++) { if (parentPanel.getBoTypeID() == btns[j].boTypeId) { Ext.getCmp(btns[j].id).disable(); } } } } parentPanel.checkRightButtonState(value.get(keys[1])); SWeb.core.BusAuthCheck.pop(); } }, 'destroy' : function(p) { } }, initComponent : function() { SWeb.core.HeavyBaseGrid.superclass.initComponent.call(this); this.getStore().addListener('beforeload', function(scope, options) { }, this); }, enableHdMenu :false }); SWeb.core.BaseGrid = function(props) { SWeb.core.BaseGrid.superclass.constructor.createInterceptor(this .intercepter(props)).call(this, this.props); } Ext.extend(SWeb.core.BaseGrid, READ_FROM_WHERE == FRAMEWORK_LIGHT ? SWeb.core.LightBaseGrid:SWeb.core.HeavyBaseGrid); Ext.reg('baseGrid', SWeb.core.BaseGrid); SWeb.core.LightBaseTree = Ext.extend(Ext.tree.TreePanel, { intercepter : function(props) { this.props.singleExpand = true; } }); SWeb.core.HeavyBaseTree = Ext.extend(Ext.tree.TreePanel, { intercepter : function(props) { } }); SWeb.core.BaseTree = function(props) { this.props=props; SWeb.core.BaseTree.superclass.constructor.createInterceptor(this .intercepter(props)).call(this, this.props); } Ext.extend(SWeb.core.BaseTree, READ_FROM_WHERE == FRAMEWORK_LIGHT ? SWeb.core.LightBaseTree:SWeb.core.HeavyBaseTree); Ext.reg('baseTree', SWeb.core.BaseTree); SWeb.core.BusAuthCheck = function() { var cache = new Ext.util.MixedCollection(); var array = new Array(); function accessData(type, data) { var key = ''; switch (type) { case 1 : key = DATA_AUTH_READ; break; case 2 : key = DATA_AUTH_WRITE; break; case 3 : key = DATA_AUTH_MANAGE; break; } if (cache.containsKey(key)) { cache.get(key).push(data); } else { cache.add(key, [data]) } } return { push : function(value) { if (value != null) { if (array.length == 1) { array.pop(); } array.push(value); } }, pop : function() { var value = array.pop(); return value; }, check : function(params, handler, el, ct, pos) { var obj = Ext.lib.Ajax.getConnectionObject().conn; obj.open('POST', String.format('busLoad.do?id={0}&&type={1}', params.id, params.type), false); obj.send(null); var result = obj.responseText; if (result == 'true') { handler.call(el, ct, pos); } else { } }, checkData : function(params, panel) { var id; var genDataAuth; var obj = Ext.lib.Ajax.getConnectionObject().conn; obj.open('POST', String.format('dataLoad.do?id={0}&&type={1}', params.id, params.type), false); obj.send(null); requestcomplete(obj, obj); if (obj.responseText != '[]') { var data = Ext.util.JSON.decode(obj.responseText); for (i = 0; i < data.length; i++) { id = data[i].boTypeId; genDataAuth = data[i].hasDataAuth; accessData(data[i].dataAuthType, data[i]); } } return { boTypeID : id, genDataAuth : genDataAuth }; }, getDataAuthItems : function(key) { return cache.get(key); }, release : function() { var keys = [DATA_AUTH_READ, DATA_AUTH_MANAGE, DATA_AUTH_WRITE]; for (var i = 0; i < keys.length; i++) { var temp = cache.get(keys[i]); if (temp != undefined) { for (var j = 0; temp.length != 0 && j < temp.length; j++) { Ext.getCmp(temp[j].id).enable(); } } } }, clearCache : function() { cache = null; } } }();