封装包括:
权限封装、通用界面组件。
封装的js截图:
封装后,实现一个签章查询模块的代码如下:
/** * Created by IntelliJ IDEA. User: yinbin Date: 12-3-15 Time: 下午2:18 To change * this template use File | Settings | File Templates. */ window.signature_signatureList = function() { /** * Created by IntelliJ IDEA. User: yinbin Date: 12-3-15 Time: 下午2:18 To * change this template use File | Settings | File Templates. */ Ext.ns("Signature"); // toolbar/gridPanel首字母小写,因为是function Ext.ns("Signature.toolbar");// 工具栏 Ext.ns("Signature.gridPanel");// 列表 Ext.ns("Signature.viewport");// // urls Signature.urls = { modelList : 'signature/signatureList.action', depnameInfo : 'signature/selectDepInfo.action' }; // ============================================================================================*工具栏 Signature.toolbar = function() { var toolbar = new Common.Toolbar( { buttonsShow : arguments[0] }); // ===========================================================================================签章 var disable = false; var organizationunitData = Enum.jsonToComboStore(Enum.c_sign_unit); var organizationunitEmpty = '所有'; var a = Ext.Ajax.request( { url : Signature.urls.depnameInfo, params : {}, async : true, callback : function(options, success, response) { var responseData = Ext.decode(response.responseText); if (responseData != null && responseData != '') { disable = true; organizationunitData = [[responseData, 1]]; organizationunitEmpty = responseData; } } }); toolbar.regSignatureHandler(function() { var selections = Ext.getCmp('SignatureGridPanel') .getSelectionModel().getSelections(); if (selections.length != 1) { Common.Alt .msg(Common.Alt.WARNING, 0, '提示', '请您选择一条数据进行操作!', ''); return; } else { var record = selections[0]; var ccode = record.data.CODE; var cdoctype = record.data.DOCTYPE; window.openSignPage(ccode,cdoctype); } }); // ============================================================================================查询 toolbar.regQueryHandler(function() { var mainForm = new Ext.form.FormPanel( { region : 'center', defaultType : 'textfield', bodyStyle : 'padding:5px 30px 1', frame : true, defaults : { border : true, labelAlign : 'right', labelWidth : 60, value : '' }, items : [ { fieldLabel : '单据号', name : 'todoEntity.code', width : 180 }, { fieldLabel : '客户名称', name : 'todoEntity.cusname', width : 150 }, { xtype : 'combo', name : 'todoEntity.depname', triggerAction : 'all', fieldLabel : '工贸名称', emptyText : organizationunitEmpty, store : new Ext.data.SimpleStore( { fields : [ 'label', 'value' ], data : organizationunitData }), displayField : 'label', valueField : 'label', disabled : disable, hiddenName : 'todoEntity.depname', editable : false, mode : 'local' },{ fieldLabel : '海尔分公司代码', name : 'todoEntity.fgscode', width : 150 }, { fieldLabel : '客户签章时间', name : 'todoEntity.cusqzdate', xtype : 'datefield', format : 'Y-m-d', readOnly: true, width : 150 }, { fieldLabel : '文档生成时间', name : 'todoEntity.createdate', xtype : 'datefield', format : 'Y-m-d', readOnly: true, width : 150 }, { xtype : 'combo', name : 'todoEntity.doctype', triggerAction : 'all', fieldLabel : '文档类型', emptyText : '所有', store : new Ext.data.SimpleStore( { fields : [ 'label', 'value' ], data : Enum.jsonToComboStore(Enum.c_sign_type) }), displayField : 'label', valueField : 'value', hiddenName : 'todoEntity.doctype', editable : false, mode : 'local' } ] }); return new Common.QueryWindow( { width : 400, height : 300, layout : 'border', items : [ mainForm ], queryHandler:function(){ Utils.reloadGridPanelStore(mainForm,'SignatureGridPanel'); } }); }); return toolbar; }; // ============================================================================================列表 Signature.gridPanel = function() { var gridPanel = GridPanelUtil.getPagingAndSortGp('SignatureGridPanel', Signature.urls.modelList, [ new Ext.grid.CheckboxSelectionModel(), { header : '单据号', width : 150, dataIndex : 'CODE' }, { header : '文档类型', dataIndex : 'DOCTYPE', width : 100, renderer : function(v) { return Enum.c_sign_type.getValue(v); } }, { header : '客户编码', dataIndex : 'CUSCODE', width : 80 }, { header : '客户名称', dataIndex : 'CUSNAME', width : 200 }, { header : '海尔分公司代码', dataIndex : 'FGSCODE', width : 100 }, { header : '海尔分公司名称', dataIndex : 'FGSNAME', width : 220 }, { header : '工贸名称', dataIndex : 'DEPNAME', width : 100 }, { header : '客户签章人名称', dataIndex : 'CUSQZNAME', width : 100 }, { header : '客户签章时间', dataIndex : 'CUSQZDATE', width : 150, renderer : function(value) { var time = value; var sb = ''; for ( var i = 0; i < time.length; i++) { if ('T' == time.charAt(i)) { sb += ' '; continue; } sb += time.charAt(i); } if (sb == '2000-06-01 00:00:00') { return ''; } return sb; } }, { header : '海尔签章人名称', dataIndex : 'HAIERQZNAME', width : 100 }, { header : '海尔签章时间', dataIndex : 'HAIERQZDATE', width : 150, renderer : function(value) { var time = value; var sb = ''; for ( var i = 0; i < time.length; i++) { if ('T' == time.charAt(i)) { sb += ' '; continue; } sb += time.charAt(i); } return sb; } }, { header : '签章状态', dataIndex : 'STATE', width : 100, renderer:function(value){ return Enum.c_sign_state.getValue(value); } }, { header:'文档生成时间', dataIndex:'CREATEDATE', width:150, renderer:function (value) { var time = value; var sb = ''; for (var i = 0; i < time.length; i++) { if ('T' == time.charAt(i)) { sb += ' '; continue; } sb += time.charAt(i); } return sb; } }]); return gridPanel; }; // ============================================================================================ // 权限 return Power.getTabPanel(Signature, 'signature_signatureList'); };
实现模块管理的代码如下:
window.systemManage_modeManage = function () { Ext.ns("Model"); // Model.toolbar 工具栏 // Ext.ns("Model.gridPanel");// 列表 // Ext.ns("Model.viewport");// // urls Model.urls = { menuButtonsGp:'modelManager/listMenuButtons.action', // cmenuCombo:'modelManager/comboList.action', // csupmenuCombo:'modelManager/csupmenuComboList.action', // addModel:'modelManager/addModel.action', // findButtonsForModel:'modelManager/findButtonsForModel.action', // deleteModel:'modelManager/deleteModel.action', // modelList:'modelManager/modelList.action', // updateModel:'modelManager/updateModel.action'// }; // ============================================================================================*工具栏 Model.toolbar = function () { var toolbar = new Common.Toolbar({ buttonsShow:arguments[0] }); // 返回父级菜单的combo给mainform function getCsupmenunameCombo(v) { var comboStore = new Ext.data.Store({ autoLoad:true, proxy:new Ext.data.HttpProxy({ url:Model.urls.csupmenuCombo }), reader:new Ext.data.JsonReader({ root:'comboList', fields:[ // 上级菜单名称 { name:'CSUPMENUNAME' }, // 上级菜单code { name:'CSUPMENUCODE' } ] }) }); // 如果存在就是要在修改 if (v) { comboStore.on("load", function (ds, records, o) { for (var i = 0; i < records.length; i++) { if (records[i].data.CSUPMENUNAME == v) { csupmenuname .setRawValue(records[i].data.CSUPMENUNAME); // return false; } } }); } var csupmenuname = new Ext.form.ComboBox({ id:'supermenu', xtype:'combo', fieldLabel:'上级菜单', name:'csupmenucode', displayField:'CSUPMENUNAME', valueField:'CSUPMENUCODE', hiddenName:'csupmenucode', lazyInit:false, allowBlank:false, typeAhead:true, autoShow:true, triggerAction:'all', // forceSelection:true, // selectOnFocus:true, store:comboStore, // emptyText:'此菜单将放置到您选择的菜单里面', anchor:'90%' }); csupmenuname.on('change', function (self, newValue, oldValue) { }); return csupmenuname; } // 返回排序的combo给mainform function getIorderCombo(v) { var comboStore2 = new Ext.data.Store({ autoLoad:true, proxy:new Ext.data.HttpProxy({ url:Model.urls.cmenuCombo }), reader:new Ext.data.JsonReader({ root:'comboList' }, [ { name:'IORDER', mapping:'IORDER' }, { name:'CMENUNAVI', mapping:'CMENUNAVI' } ]) }); if (v) { comboStore2.on("load", function (ds, records, o) { for (var i = 0; i < records.length; i++) { if (records[i].data.IORDER == v) { iorder.setRawValue(records[i].data.CMENUNAVI); } } }); } var iorder = new Ext.form.ComboBox({ id:'iorder2', xtype:'combo', fieldLabel:'排序', name:'iorder', displayField:'CMENUNAVI', valueField:'IORDER', hiddenName:'iorder', lazyInit:false, allowBlank:false, typeAhead:true, autoShow:true, triggerAction:'all', // forceSelection:true, // selectOnFocus:true, store:comboStore2, // emptyText:'此菜单将放置到您选择的菜单后面', anchor:'90%' }); return iorder; } // 返回是否激活的combo给mainform function getBdelCombo(v) { var bdelValue = ''; if (v == 1) { bdelValue = "否"; } else if (v == 0) { bdelValue = "是"; } else { bdelValue = "是"; } return new Ext.form.ComboBox({ id:'bdel', xtype:'combo', name : 'bdel', triggerAction:'all', fieldLabel:'是否有效', store:new Ext.data.SimpleStore({ fields:['label', 'value'], data:[ ["是", 0], ["否", 1] ] }), displayField:'label', mode:'local', value:bdelValue, valueField:'value', allowBlank:false, anchor:'80%' }); } //=================================================增加================================== toolbar.regAddHandler(function () { var addHandler = arguments.callee; var menuButtonsStore = new Ext.data.JsonStore({ autoLoad:true, root:'menuButtonList', fields:[ { name:'ISYSCODE' }, // 按钮名称 { name:'CBTNNAME' }, // 关键字 { name:'CKEY' }, // 排序 { name:'IORDER' }, // 备注 { name:'CMEMO' }, // 按钮事件 { name:'CFUNCTION' }, // 按钮图标 { name:'ICON' } ], proxy:new Ext.data.HttpProxy({ url:Model.urls.menuButtonsGp }) }); var sm = new Ext.grid.CheckboxSelectionModel(); var menuButtonsGridPanel = new Ext.grid.GridPanel({ id:'menuButtonsGridPanel', region:'south', height:138, store:menuButtonsStore, sm:sm, columns:[sm, { id:'ISYSCODE', header:"按钮主键", dataIndex:'ISYSCODE', width:40, sortable:true }, { header:"按钮名称", dataIndex:'CBTNNAME', width:100, sortable:true }, { header:"关键字", dataIndex:'CKEY', width:100, align:'right', sortable:true }, { header:"按钮图标", dataIndex:'ICON', width:60, sortable:true }, { header:"事件方法", dataIndex:'CFUNCTION', width:60, sortable:true }, { header:"备注", dataIndex:'CMEMO', width:100, sortable:true }, { header:"排序", dataIndex:'IORDER', width:40, sortable:true }] }); /** * 添加主表单 */ var mainForm = new Ext.form.FormPanel({ region:'center', bodyStyle:'padding:1px 1px 1', frame:true, defaults:{ border:true, labelAlign:'right', labelWidth:60 }, items:[ { layout:'column', items:[ { columnWidth:0.5, layout:'form', items:[ { id:"cmenuname", xtype:'textfield', fieldLabel:"模块名称", allowBlank:false, blankText:'请输入!', name:"cmenuname", anchor:'80%', listeners:{ render:function (c) { setTimeout(function () { c.focus(true, true); }, 500); } } } ] }, { columnWidth:0.5, layout:'form', items:[getBdelCombo()] } ] }, { layout:'column', items:[ { columnWidth:1, layout:'form', items:[ { id:'cico', xtype:'textfield', disabled:true, fieldLabel:"菜单图标", blankText:'以后扩展', name:"cico", anchor:'90%', value:'', colspan:2 }, { id:'curl', xtype:'textfield', fieldLabel:"url", emptyText:'非父级菜单url路径是必填项目', name:"curl", anchor:'90%' }, getCsupmenunameCombo(), getIorderCombo() ] } ] } ] }); var saveHandler = function (c) { // 通过数组注入参数传到后台 var values = mainForm.getForm().getValues(); // 要返回的参数 var params = []; // 获取menu下面你的button按钮 // for循环里面的ret的写法等价于:在外面定义一个var ret = []; // 同时注意如果if判断条件里面的是(0,"",null,undefined)结果是false;其他的是true var selections = menuButtonsGridPanel.getSelectionModel() .getSelections(); for (var i = 0, ret = []; i < selections.length; i++) { ret.push(selections[i].get('ISYSCODE')); } if (ret.length) { params['modelButtonEntity.ibuttonid'] = ret; } // 获取到上级菜单的name var supermenu = Ext.getCmp('supermenu'); params['modelButtonEntity.csupmenuname'] = supermenu.lastSelectionText; for (p in values) { if ('bdel' == p) { if ('是' == values[p].bdel) { params['modelButtonEntity.sysMenuentity.bdel'] = 0;// 获取到是否可用,并传入需要的参数0或者1 } else { params['modelButtonEntity.sysMenuentity.bdel'] = 1;// 获取到是否可用,并传入需要的参数0或者1 } // 其他的属性按照同一个规则修改成需要的属性 } else { params['modelButtonEntity.sysMenuentity.' + p] = values[p] } } mainForm.getForm().submit({ clientValidation:true, url:Model.urls.addModel, params:params, success:function (form, action) { Ext.getCmp('ModelGridPanel').getStore().reload(); var msgBox = Ext.MessageBox.show({ title:'提示', msg:'添加成功,是否继续添加?继续添加(enter),否(esc)', buttons:Ext.MessageBox.YESNO, fn:function (btn) { win.close(); if ("yes" == btn) { addHandler(); } }, icon:Ext.MessageBox.QUESTION }); }, failure:function (form, action) { var msgBox = Ext.MessageBox.show({ title:'提示', msg:'添加失败,是否继续添加?继续添加(enter),否(esc)', buttons:Ext.MessageBox.YESNO, fn:function (btn) { win.close(); if ("yes" == btn) { addHandler(); } }, icon:Ext.MessageBox.QUESTION }); switch (action.failureType) { case Ext.form.Action.CLIENT_INVALID : Common.Alt .msg(Common.Alt.ERROR, 2, "Failure", "Form fields may not be submitted with invalid values"); break; case Ext.form.Action.CONNECT_FAILURE : Common.Alt.msg(Common.Alt.ERROR, 2, "Failure", "Ajax communication failed"); break; case Ext.form.Action.SERVER_INVALID : Common.Alt.msg(Common.Alt.ERROR, 2, "Failure", action.result.msg); } } }); }; var win = new Common.SaveWindow({ width:580, height:350, layout:'border', items:[mainForm, menuButtonsGridPanel], saveHandler:saveHandler }); win.show(); }); toolbar.regEditHandler(function () { var record = Ext.getCmp('ModelGridPanel').getSelectionModel() .getSelections();// 获取你选择的行 if (record == null || record == "") { Common.Alt .msg(Common.Alt.WARNING, 0, '提示', '请选择要{0}的数据!', "修改"); return; } var recordData = record[0].data; if (!recordData || !recordData.CMENUCODE) { return; } /** * 选中gridpanel中的数据,根据self.cmenucode * * @param {Object} * self */ function selectMenuButtonsRow(self) { Ext.Ajax.request({ url:Model.urls.findButtonsForModel, params:{ 'cmenucode':self.cmenucode }, success:function (response) { // [1,3,6,8] var ibuttonids = Ext.util.JSON .decode(response.responseText); if (ibuttonids && ibuttonids.length > 0) { // var mbgp = Ext.getCmp('MenuButtonsGridPanel') // .getSelectionModel(); // mbgp.selectRows(ibuttonids); // 先全部选中然后获取所有的column var selectModel = Ext .getCmp('MenuButtonsGridPanel') .getSelectionModel(); // 获取到selectModel里面数据的方法: selectModel.selectAll(); var allColumns = selectModel.selections; var seletedButtons = []; for (var i = 0; i < allColumns.length; i++) { // 菜单所具有的所有的buttons --》ibuttonids for (var j = 0; j < ibuttonids.length; j++) { // 如果相等就把这条数据的下标记录下来,做成[0,1,2,3],因为gridpanel的选择是根据下标来选择的,下标从0开始; if (allColumns.items[i].data.ISYSCODE == ibuttonids[j]) { seletedButtons.push(i); } } } // 根据json里面返回的crolecode判断,tab2中哪一条该选择; // 最后清空select,再选择想要的; selectModel.clearSelections(); selectModel.selectRows(seletedButtons); } }, failure:function () { Common.Alt.msg(Common.Alt.ERROR, 2, '提示', '服务器出现错误,稍后再试!'); } }); } /** * menubuttons gridpanel * * @memberOf {TypeName} * @return {TypeName} */ function getMenuButtonsGridPanel() { getMenuButtonsGridPanel.menuButtonsStore = new Ext.data.JsonStore({ cmenucode:recordData.CMENUCODE, autoLoad:true, root:'menuButtonList', fields:[ { name:'ISYSCODE' }, // 按钮名称 { name:'CBTNNAME' }, // 关键字 { name:'CKEY' }, // 排序 { name:'IORDER' }, // 备注 { name:'CMEMO' }, // 按钮事件 { name:'CFUNCTION' }, // 按钮图标 { name:'ICON' } ], proxy:new Ext.data.HttpProxy({ url:Model.urls.menuButtonsGp }), listeners:{ load:function (self, records, options) { selectMenuButtonsRow(this); } } }); var sm = new Ext.grid.CheckboxSelectionModel(); getMenuButtonsGridPanel.menuButtonsGridPanel = new Ext.grid.GridPanel({ id:'MenuButtonsGridPanel', region:'south', height:138, bodyStyle:'padding:1px 1px 1px 1px', store:getMenuButtonsGridPanel.menuButtonsStore, sm:sm, columns:[sm, { id:'ISYSCODE', header:"按钮主键", dataIndex:'ISYSCODE', width:60, sortable:true }, { header:"按钮名称", dataIndex:'CBTNNAME', width:100, sortable:true }, { header:"关键字", dataIndex:'CKEY', width:100, align:'right', sortable:true }, { header:"按钮图标", dataIndex:'ICON', width:60, sortable:true }, { header:"事件方法", dataIndex:'CFUNCTION', width:60, sortable:true }, { header:"备注", dataIndex:'CMEMO', width:100, sortable:true }, { header:"排序", dataIndex:'IORDER', width:40, sortable:true }] }); return getMenuButtonsGridPanel.menuButtonsGridPanel; } /** * 给mainform下面的menubutton的grid的复选框赋值 * * @param cmenucode */ function setDefaultSelected(cmenucode) { getMenuButtonsGridPanel.menuButtonsStore.cmenucode = cmenucode; getMenuButtonsGridPanel.menuButtonsStore.reload(); } /** * 修改主表单 */ var mainForm = new Ext.form.FormPanel({ region:'center', bodyStyle:'padding:1px 1px 1', frame:true, defaults:{ border:true, labelAlign:'right', labelWidth:60 }, items:[ { layout:'column', items:[ { columnWidth:0.5, layout:'form', items:[ { id:'cmenucode', xtype:'hidden', name:"cmenucode", value:recordData.CMENUCODE, allowBlank:false }, { id:'isyscode', xtype:'hidden', name:"isyscode", value:recordData.ISYSCODE, allowBlank:false }, { id:"cmenuname", xtype:'textfield', fieldLabel:"模块名称", allowBlank:false, blankText:'请输入!', name:"cmenuname", value:recordData.CMENUNAME, anchor:'80%', listeners:{ render:function (c) { setTimeout(function () { c.focus(true, true); }, 500); } } } ] }, { columnWidth:0.5, layout:'form', items:[getBdelCombo(recordData.BDEL)] } ] }, { layout:'column', items:[ { columnWidth:1, layout:'form', items:[ { id:'cico', xtype:'textfield', disabled:true, fieldLabel:"菜单图标", allowBlank:false, blankText:'以后扩展', name:"cico", anchor:'90%', value:'', colspan:2 }, { id:'curl', xtype:'textfield', fieldLabel:"url", allowBlank:false, emptyText:'非父级菜单url路径是必填项目', name:"curl", value:recordData.CURL ? recordData.CURL : "./", anchor:'90%' }, getCsupmenunameCombo(recordData.CSUPMENUNAME), getIorderCombo(recordData.IORDER) ] } ] } ] }); // 修改按钮集合 var buttons = []; if (record.length > 1) {// 》1表示拥护选择了多条数据进行编辑 var scaler = 0; // 计数器,上一条,下一条计数 /** * <,>上一条,下一条编辑数据调用的:重新给表单赋值方法 * * @param rd */ function setFormValue(rd) { try { mainForm.findById('cmenucode').setValue(rd.CMENUCODE); mainForm.findById('isyscode').setValue(rd.ISYSCODE); mainForm.findById('cmenuname').setValue(rd.CMENUNAME); mainForm.findById('curl').setValue(rd.CURL); mainForm.findById('cico').setValue(rd.CICO); mainForm.findById('bdel').setValue(rd.BDEL == 1 ? "否" : "是"); // console.log(rd.CSUPMENUCODE); mainForm.findById('supermenu') .setValue(rd.CSUPMENUCODE); // console.log(rd.IORDER); mainForm.findById('iorder2').setValue(rd.IORDER); } catch (e) { } } // 《上一条数据按钮 var preButton = new Ext.Button({ text:' < ', style:'margin-right:10px', handler:function () { try { var i = --scaler; var recordData = record[i].data; win.setTitle('修改 <' + recordData.CMENUNAME + '>'); setDefaultSelected(recordData.CMENUCODE); setFormValue(recordData); nextButton.enable(); } catch (e) { preButton.disable(); } } }); buttons.push(preButton); /** * >按钮的click事件处理 */ var nextButtonHandler = function () { try { var i = ++scaler; var recordData = record[i].data; win.setTitle('修改 <' + recordData.CMENUNAME + '>'); setDefaultSelected(recordData.CMENUCODE); setFormValue(recordData); preButton.enable(); return false; } catch (e) { nextButton.disable(); return true; } }; var isLastUpdateItem = function (scaler) { try { var s = scaler; var i = ++scaler; var recordData = record[i].data; return false; } catch (e) { return true; } }; /** * update的ajax请求回调处理 */ function ajaxUpdateCall() { var isLastItem = isLastUpdateItem(scaler); if (!isLastItem) { // 多条数据编辑的情况 Ext.MessageBox.show({ title:'提示', msg:'修改成功,是否继续修改?继续修改(enter),否(esc)', buttons:Ext.MessageBox.OKCANCEL, fn:function (btn) { if ("cancel" == btn) { win.close(); } else { nextButtonHandler(); } }, icon:Ext.MessageBox.QUESTION }); } else { // 只有一条数据或者是最后一条数据 Ext.MessageBox.show({ title:'提示', msg:'修改成功,确定(enter)', buttons:Ext.MessageBox.OK, fn:function (btn) { if ("ok" == btn) { win.close(); } }, icon:Ext.MessageBox.INFO }); } } // 》下一条修改数据按钮 var nextButton = new Ext.Button({ text:' > ', style:'margin-right:320px', handler:nextButtonHandler }); buttons.push(nextButton); } var updateHandler = function () { // 通过数组注入参数传到后台 var values = mainForm.getForm().getValues(); var params = []; // 获取到上级菜单的name var supermenu = Ext.getCmp('supermenu'); params['modelButtonEntity.csupmenuname'] = supermenu.lastSelectionText; for (p in values) { if ('bdel' == p) { var bdel = Ext.getCmp('bdel'); if ("是" == bdel.lastSelectionText) { params['modelButtonEntity.sysMenuentity.bdel'] = 0;// 获取到是否可用,并传入需要的参数0或者1 } else { params['modelButtonEntity.sysMenuentity.bdel'] = 1;// 获取到是否可用,并传入需要的参数0或者1 } // 其他的属性按照同一个规则修改成需要的属性 } else { params['modelButtonEntity.sysMenuentity.' + p] = values[p] } } // 获取menu下面你的button按钮 // for循环里面的ret的写法等价于:在外面定义一个var ret = []; // 同时注意如果if判断条件里面的是(0,"",null,undefined)结果是false;其他的是true var selections = getMenuButtonsGridPanel.menuButtonsGridPanel .getSelectionModel().getSelections(); for (var i = 0, ret = []; i < selections.length; i++) { ret.push(selections[i].get('ISYSCODE')); } if (ret.length) { params['modelButtonEntity.ibuttonid'] = ret; } mainForm.getForm().submit({ clientValidation:true, url:Model.urls.updateModel, params:params, success:function (form, action) { Ext.getCmp('ModelGridPanel').getStore().reload(); try { ajaxUpdateCall(); } catch (e) { Ext.MessageBox.show({ title:'提示', msg:'修改成功!确定(enter)', buttons:Ext.MessageBox.OK, fn:function (btn) { win.close(); }, icon:Ext.MessageBox.INFO }); } }, failure:function (form, action) { switch (action.failureType) { case Ext.form.Action.CLIENT_INVALID : Common.Alt.msg(0, 0, 0, "表单字段的值不合法"); break; case Ext.form.Action.CONNECT_FAILURE : Common.Alt.msg(0, 0, 0, "异步连接超时"); break; case Ext.form.Action.SERVER_INVALID : Common.Alt.msg(0, 0, 0, "修改失败"); } } }); }; var win = new Common.UpdateWindow({ title:'修改 <' + recordData.CMENUNAME + '>', width:580, height:350, layout:'border', items:[mainForm, getMenuButtonsGridPanel()], updateHandler:updateHandler, buttons:buttons }); win.show(); }); // ================================================================================= toolbar.regQueryHandler(function () { // if (Model.queryWindow) { // Model.queryWindow.show(); // return; // } var comboStore = new Ext.data.Store({ reader:new Ext.data.JsonReader({ root:'comboList', fields:[ // 上级菜单名称 { name:'CSUPMENUNAME' }, // 上级菜单code { name:'CSUPMENUCODE' } ] }), proxy:new Ext.data.HttpProxy({ url:Model.urls.csupmenuCombo }) }); function reloadModelGridPanelStore() { var modelGridPanelStore = Ext.getCmp('ModelGridPanel') .getStore(); var params = mainForm.getForm().getValues(); params.start = 0; modelGridPanelStore.load({ params:params }); } var mainForm = new Ext.form.FormPanel({ region:'center', bodyStyle:'padding:2px 2px 0', frame:true, defaults:{ border:true, labelAlign:'right' }, defaultType:'textfield', items:[ { fieldLabel:'模块名称', name:'modelForm.cmenuname', listeners:{ render:function (c) { setTimeout(function () { c.focus(true, true); }, 500); } } }, { fieldLabel:'url', name:'modelForm.curl' }, { xtype:'combo', fieldLabel:'上级菜单', name:'modelForm.csupmenucode', triggerAction:'all', store:comboStore, displayField:'CSUPMENUNAME', valueField:'CSUPMENUCODE', hiddenName:'modelForm.csupmenucode', listeners:{ select:function (combo, record, index) { reloadModelGridPanelStore(); } } }, { xtype:'combo', id:'bdel', name:'modelForm.bdel', triggerAction:'all', fieldLabel:'是否有效', width:100, store:new Ext.data.SimpleStore({ fields:['label', 'value'], data:[ ["有效", "0"], ["无效", "1"] ] }), displayField:'label', valueField:'value', hiddenName:'modelForm.bdel', editable:false, mode:'local', listeners:{ select:function (combo, record, index) { reloadModelGridPanelStore(); } } } ] }); var win = new Common.QueryWindow({ width:350, height:200, layout:'border', items:[mainForm], queryHandler:reloadModelGridPanelStore }); win.show(); }); // ============================================================================================== toolbar.regDeleteHandler(function () { var record = Ext.getCmp('ModelGridPanel').getSelectionModel() .getSelections();// 获取你选择的行 if (record != null && record != "") { Ext.MessageBox.confirm("提示", "确定删除已选数据?", function (ret) { if (ret == "yes") { var isyscodes = new Array(record.length); for (var i = 0; i < record.length; i++) { isyscodes[i] = record[i].get("ISYSCODE"); } Ext.Ajax.request({ url:Model.urls.deleteModel, params:{ 'isyscodes':isyscodes }, success:function (response) { var result = Ext.util.JSON .decode(response.responseText); if (result.success) { Common.Alt.msg(Common.Alt.WARNING, 0, "提示", "删除成功!"); } else { Common.Alt.msg(Common.Alt.WARNING, 0, "提示", "删除失败!"); } Ext.getCmp('ModelGridPanel').getStore() .reload(); }, failure:function () { Common.Alt.msg(Common.Alt.ERROR, 2, '提示', '服务器出现错误,稍后再试!'); } }); } }) } else { Common.Alt.msg(Common.Alt.WARNING, null, "提示", "请选择要删除的数据!"); } }); return toolbar; }; // ============================================================================================列表 Model.gridPanel = function () { var store = new Ext.data.Store({ autoLoad:true, proxy:new Ext.data.HttpProxy({ url:Model.urls.modelList }), /* * listeners : { 'beforeload' : function() { this.baseParams = { * limit : 200 } } }, */ // baseParams:{satrt:0,limit:15}, reader:new Ext.data.JsonReader({ totalProperty:'totalCount', root:'totalList', id:'ISYSCODE' }, Ext.data.Record.create([ { name:'ISYSCODE', type:'int' }, { name:'CMENUCODE', type:'string' }, { name:'CMENUNAME', type:'string' }, { name:'CSUPMENUNAME', type:'string' }, { name:'CSUPMENUCODE', type:'string', hidden:true } , { name:'CMENUNAVI', type:'string' }, { name:'IORDER', type:'int' }, { name:'CURL', type:'string' }, { name:'CHELPDOCNAME', type:'string' }, { name:'BDEL', type:'string' } ])) }); var columns = new Ext.grid.ColumnModel([ new Ext.grid.CheckboxSelectionModel(), { header:'主键', dataIndex:'ISYSCODE', hidden:true }, { header:'模块编码', dataIndex:'CMENUCODE', width:100 }, { header:'模块名称', dataIndex:'CMENUNAME', width:100 }, { header:'上级模块', dataIndex:'CSUPMENUNAME', width:100 }, { header:'层级', dataIndex:'CMENUNAVI', width:200 }, { header:'排序', dataIndex:'IORDER', width:50 }, { header:'URL', dataIndex:'CURL', width:200 }, { header:'帮助文档名称', dataIndex:'CHELPDOCNAME', width:150 }, { header:'是否有效', width:100, dataIndex:'BDEL', renderer:function (value) { // console.log(value); if (value == 1) { return '有效'; } else { return '无效'; } } }]); columns.defaultSortable = true; var gridPanel = new Ext.grid.GridPanel({ id:"ModelGridPanel", region:'center', loadMask:true, stripeRows:true, store:store, cm:columns, view:new Ext.grid.GridView({ forceFit:false }), sm:new Ext.grid.CheckboxSelectionModel(), bbar:new Ext.PagingToolbar({ pageSize:12, store:store, displayInfo:true, displayMsg:'显示第 {0} 条到 {1} 条记录,一共 {2} 条', emptyMsg:"没有记录" }), listeners:{ 'beforeload':function () { this.baseParams = { limit:12 }; } } }); return gridPanel; }; // ============================================================================================ return Power.getTabPanel(Model, 'systemManage_modeManage'); };
代码中:可以随意组合extjs的组件,只要最后return的是一个panel对象即可。