【原创】MessageBox设置默认按钮
方法1:此方法适用于Extjs按钮handler处理,一般在最前面说明
function changeMsgBoxFocus(buttonIdx) { function exmyth() { Ext.MessageBox.getDialog().buttons[buttonIdx].focus(); } exmyth.defer(100, this); } Ext.MessageBox.getDialog().addListener('show', changeMsgBoxFocus.createCallback(2));
Ext.MessageBox.buttonText.yes = 'Remove'; Ext.MessageBox.buttonText.no = 'Do nothing'; Ext.MessageBox.getDialog().on( { show: function() { Ext.MessageBox.getDialog().buttons[2].focus(); }, single:true //,delay:50 // maybe needed }); Ext.MessageBox.show( { title : 'Please confirm', msg : 'Do your really want to delete node \'' + this.curNode.text + '\'?', buttons : Ext.MessageBox.YESNO, fn : this.removeNodeConfirmHandleMsgBox, scope: this, animEl : this.tree, icon : Ext.MessageBox.QUESTION });
方法2:此方法适用于页面全局,一般在页面return的init方法中指定
Ext.MessageBox.getDialog().defaultButton = 2;
附上我项目模块的代码
1.Smsd.widget.AddressGroupBtn.js
Ext.ns("Smsd.widget"); var mgrAddrGroupForm; var mgrAddrGroupWin; var type; var groupTree; var root; var loader; /** * 管理组 * @author zhongmm * @class Smsd.widget.AddressGroupBtn * @extends Ext.Button */ Smsd.widget.AddressGroupBtn =Ext.extend(Ext.Button,{ text: "管理组", width: 50, back: function (){}, handler: function (btn) { function changeMsgBoxFocus(buttonIdx){ function exmyth() { Ext.MessageBox.getDialog().buttons[buttonIdx].focus(); } exmyth.defer(100, this); } Ext.MessageBox.getDialog().addListener('show', changeMsgBoxFocus.createCallback(2)); root = new Ext.tree.AsyncTreeNode( { // href : '', // hrefTarget : '_blank', // iconCls : "me-iconCls", id : "0", text : "个性化通讯录", leaf:false }); loader = new Ext.tree.TreeLoader( { dataUrl:Ext.sysd.getWithToken('/addressGroup/listAddressGroup.do'), method : 'POST' }); groupTree = new Ext.tree.TreePanel( { id : 'groupId', name : 'groupName', root : root, animate : false, containerScroll : true, autoScroll : true, loader:loader, width: 325, height: 200, line: true, border : true }); root.expand(false, true); //默认展开一级 var topBtn = new Ext.Toolbar({ autoHeight : true, items : [{xtype : 'tbseparator'}, {text : '新增',iconCls : 'silk_page_add',handler :function(){mgrAddrGroup(0);}}, {xtype : 'tbseparator'}, {text : '编辑',iconCls : 'silk_page_edit',handler :function(){ var selNode = groupTree.getSelectionModel().getSelectedNode(); if(!selNode) { Ext.Msg.alert(Sysd.Msg.AlertTitle,"请选择一条组信息!"); } else if(selNode.id == groupTree.getRootNode().id) { Ext.Msg.alert(Sysd.Msg.AlertTitle,"无法编辑根节点!"); } else { mgrAddrGroup(1); Ext.getCmp("groupId").setValue(selNode.id); Ext.getCmp("groupName").setValue(selNode.text); } }}, {xtype : 'tbseparator'}, {text : '删除',iconCls : 'silk_page_delete', handler :function(){ var selNode = groupTree.getSelectionModel().getSelectedNode(); if(!selNode) { Ext.Msg.alert(Sysd.Msg.AlertTitle,"请选择一条组信息!"); } else if(selNode.id == groupTree.getRootNode().id) { Ext.Msg.alert(Sysd.Msg.AlertTitle,"无法删除根节点!"); } else { countAddressGroup(selNode.id); } }}, {xtype : 'tbseparator'}, {text : '返回',iconCls : 'silk_application_home',handler :function(){win.close();btn.back()}}, {xtype : 'tbseparator'}, '->', new Ext.sysd.Helper({ moduleCode : '100600' }) ] }); //组管理主窗口 var win=new Ext.Window({ tbar:topBtn, title:'管理组', width:340, height:258, closable:false, layout:'column', modal : true, resizable:false, // draggable:false, closable:true, items:[groupTree]}); win.show(); //数据检验 function confirmGroupName() { var groupName = Ext.getCmp("groupName").getValue(); if("" == groupName) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "请输入组名!"); return false; } else if(20 < groupName.length) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "组名过长,不能大于20个字符,请重新输入!"); return false; } return true; } //新增,编辑组信息,成功刷新组管理树 function saveUpdateGroupName(type) { var groupId = Ext.getCmp("groupId").getValue(); var groupName = Ext.getCmp("groupName").getValue(); if(0 == type) { Ext.Ajax.request({ url : Ext.sysd.getWithToken('/addressGroup/saveAddressGroup.do'), method : 'post', params : { groupName:groupName }, success : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "保存成功!"); loader.load(root,function(){ root.expand(false, true); }); Ext.getCmp("mgrAddrGroupWin").close(); }, failure : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "保存失败!"); } }); } else if(1 == type) { Ext.Ajax.request({ url : Ext.sysd.getWithToken('/addressGroup/updateAddressGroup.do'), method : 'post', params : { groupId : groupId, groupName:groupName }, success : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "编辑成功!"); loader.load(root,function(){ root.expand(false, true); }); Ext.getCmp("mgrAddrGroupWin").close(); }, failure : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "编辑失败!"); } }); } } //新增,编辑组信息弹出窗口 function mgrAddrGroup(type) { mgrAddrGroupForm = new Ext.form.FormPanel({ width:200, height:100, frame:true, labelWidth:50, labelAlign:"right", defaultType:"textfield", items:[ {id:"groupId", name:"groupId",fieldLabel:"",hidden:true,hideLabel:true}, {id:"groupName", name:"groupName",fieldLabel:"组名",width:100,allowBlank:false}], buttons:[{text:"确认",iconCls : 'silk_tick',handler:function(){ var groupName = Ext.getCmp("groupName").getValue(); var selNode = groupTree.getSelectionModel().getSelectedNode(); if(1 == type && groupName == selNode.text) { mgrAddrGroupWin.hide(); } else { countAddressGroupByName(groupName,type); } }},{text:"取消",iconCls:'silk_cancel',handler:function(){ var groupName = Ext.getCmp("groupName").getValue(); var selNode = groupTree.getSelectionModel().getSelectedNode(); if(0 == type && "" != groupName) { //组名未保存,确定取消? Ext.Msg.confirm(Sysd.Msg.AlertTitle,"是否确定要取消,取消将不保存数据?",function(btn) { if('yes' == btn) { mgrAddrGroupWin.hide(); return true; } else { return false; } }); } else if(1 == type && "" != groupName && groupName != selNode.text) { //组名已修改,确定取消? Ext.Msg.confirm(Sysd.Msg.AlertTitle,"是否确定要取消,取消将不保存数据?",function(btn) { if('yes' == btn) { mgrAddrGroupWin.hide(); return true; } else { return false; } }); } else if(1 == type && groupName == selNode.text) { mgrAddrGroupWin.hide(); } else { mgrAddrGroupWin.hide(); } }}] }) mgrAddrGroupWin = new Ext.Window( { id:"mgrAddrGroupWin", title:0 == type?"新增组信息":"编辑组信息", width:210, height:150, frame:true, labelWidth:60, labelAlign:"right", defaultType:"textfield", autoHeight: true, resizable:false, closable:false, // draggable:false, modal:true, items:[mgrAddrGroupForm] }); mgrAddrGroupWin.on("hide",function(){mgrAddrGroupWin.destroy()}); mgrAddrGroupWin.show(); } //统计组中联系人信息 function countAddressGroup(groupId) { Ext.Ajax.request ({ url : Ext.sysd.getWithToken('/addressGroup/countAddressGroup.do'), method : 'post', params : { groupId:groupId }, failure : function(){ Ext.Msg.alert(Sysd.Msg.AlertTitle,"获取数据失败!"); return false; }, success : function(response){ var count = Ext.decode(response.responseText); if(count>0) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "该组有联系人信息,不能删除!"); return false; } else { comfirmDelete(); return true; } } }); return true; } //统计同名组数 function countAddressGroupByName(groupName,type) { Ext.Ajax.request ({ url : Ext.sysd.getWithToken('/addressGroup/countAddressGroupByName.do'), method : 'post', params : { groupName:groupName }, failure : function(){ Ext.Msg.alert(Sysd.Msg.AlertTitle,"获取数据失败!"); return false; }, success : function(response){ var count = Ext.decode(response.responseText); if(count>0) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "已经存在此组名,请重新输入!"); return false; } else { if(confirmGroupName()) { saveUpdateGroupName(type); } } } }); return true; } function comfirmDelete() { var selNode = groupTree.getSelectionModel().getSelectedNode(); Ext.Msg.confirm(Sysd.Msg.AlertTitle,"是否删除该组信息?",function(btn) { if('yes' == btn) { deleteAddressGroup(selNode.id); return true; } else { return false; } }); } //删除组信息 function deleteAddressGroup(groupId) { Ext.Ajax.request({ url : Ext.sysd.getWithToken('/addressGroup/deleteAddressGroup.do'), method : 'post', params : { groupId:groupId }, success : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "删除成功!"); loader.load(root,function(){ root.expand(false, true); }); }, failure : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "删除成功!"); } }); } } }); Ext.reg('addressGroupBtn', Smsd.widget.AddressGroupBtn);//管理组
2.sms.appSetup.js
Ext.ns("sms.appSetup"); var editLevelForm; var gridDirect; var formDirect; var winDirect; var editLevelWin; var gridMain; var storeMain; var timeBlock; var editTimeForm; var editTimeWin; var seqNum = 0; //序号递增初始值 var idArr; //业务代码 var timeStartArr; //已选择记录的起始时间数组 var timeEndArr //已选择记录的截止时间数组 var count; //已选择记录的时间段数 var iniCount; /** * 业务应用设置 * @author zhongmm */ sms.appSetup.main = function(){ var storeMain = new Ext.data.JsonStore({ url : Ext.sysd.getWithToken("/smsAppSetup/listAppSetup.do"), root : '', totalProperty : 'totalCount', autoLoad : false, fields : [{name:'SEQ_CODE',type:'string'}, {name:'BUSINESS_NAME',type:'string'}, {name:'SMS_LEVEL',type:'string'}, {name:'SMS_LEVEL_BAK',type:'string'}, {name:'TIME_START',type:'string'}, {name:'TIME_END',type:'string'}, {name:'BUSINESS_CODE',type:'string'}, {name:'BUSINESS_NAME_BAK',type:'string'} ] }); function setCenter(v) { return "<span style='width:100%;text-align:center;'>" + v + "</span>"; } var tb = new Ext.Toolbar({ autoHeight : true, items : ['-', { text : '级别编辑', iconCls : 'silk_page_edit', handler : function() { if(hasSelected()) { editLevel(); var businessCode = String(gridMain.getSelectionModel().getSelected().get("BUSINESS_CODE")); var businessName = String(gridMain.getSelectionModel().getSelected().get("BUSINESS_NAME_BAK")); var smsLevel = String(gridMain.getSelectionModel().getSelected().get("SMS_LEVEL_BAK")); Ext.getCmp("businessCode").setValue(businessCode); Ext.getCmp("businessName").setValue(businessName); Ext.getCmp("smsLevel").setValue(smsLevel); } } }, { xtype : 'tbseparator' }, { text : '发送时间编辑', iconCls : 'silk_page_edit', handler : function() { if(hasSelected()) { var timeBusinessCode = String(gridMain.getSelectionModel().getSelected().get("BUSINESS_CODE")); var timeBusinessName = String(gridMain.getSelectionModel().getSelected().get("BUSINESS_NAME_BAK")); var recordCount = gridMain.getStore().getCount(); timeStartArr=new Array(); timeEndArr=new Array(); for(var i = 0; i < recordCount; i++) { var id = gridMain.getStore().getAt(i).get("BUSINESS_CODE"); if(timeBusinessCode == id) { var timeStartValue = gridMain.getStore().getAt(i).get("TIME_START"); var timeEndValue = gridMain.getStore().getAt(i).get("TIME_END"); timeStartArr.push(timeStartValue); timeEndArr.push(timeEndValue); } } count = timeStartArr.length > timeEndArr.length ? timeStartArr.length :timeEndArr.length; iniCount = count; editTime(); for(var i = 0; i < count; i++) { Ext.getCmp("timeStart" + i ).setValue(timeStartArr[i]); Ext.getCmp("timeEnd" + i ).setValue(timeEndArr[i]); } Ext.getCmp("timeBusinessCode").setValue(timeBusinessCode); Ext.getCmp("timeBusinessName").setValue(timeBusinessName); } } },{ xtype : 'tbseparator' },{ text : '级别说明', iconCls : 'silk_application_view_detail', handler : function() { directLevel(); } },{ xtype : 'tbseparator' }, '->', new Ext.sysd.Update({ moduleCode : '500100' }), '-', new Ext.sysd.Suggest({ moduleCode : '500100' }), '-', new Ext.sysd.Helper({ moduleCode : '500100' }) ] }); gridMain=new Ext.grid.GridPanel({ title:"业务应用设置", tbar:tb, region:'center', height:240, store:storeMain, stripeRows : true, autoScroll : true, enableHdMenu:false, columns:[ { header : setCenter('序号'), align:'center', dataIndex : 'SEQ_CODE', width : 60, sortable : false },{ header : setCenter('业务应用'), dataIndex : 'BUSINESS_NAME', align:'center', width : 100, sortable : false },{ header : setCenter('短信级别'), dataIndex : 'SMS_LEVEL', align:'center', width : 100, sortable : false },{ header : setCenter('允许发送起始时间'), dataIndex : 'TIME_START', align:'center', width : 100, sortable : false },{ header : setCenter('允许发送截止时间'), align:'center', dataIndex : 'TIME_END', width : 100, sortable : false }], loadMask:{msg:"请稍等..."}, viewConfig : { forceFit : true } }); //合并单元格 gridMain.store.on("load",function(){ initSeq(); gridSpan(gridMain,"row","[SEQ_CODE],[BUSINESS_NAME],[SMS_LEVEL]","BUSINESS_NAME"); }); function createWindow(){ var mainWin = new Ext.Viewport({ title : '业务应用设置', layout : 'border', defauls : { column : 1 }, closable : false, draggable : false, resizable : false, items : [gridMain] }); mainWin.show(); } return { init : function() { Ext.MessageBox.getDialog().defaultButton = 2; createWindow(); gridMain.getStore().reload( /*{ params: { //默认显示第一页记录 start:0, limit:Ext.sysd.getPageSize() } }*/); } } }(); //选择记录判断 function hasSelected() { var selectModel = gridMain.getSelectionModel(); var selected = selectModel.hasSelection(); if(!selected) { Ext.Msg.alert(Sysd.Msg.AlertTitle,'请先选择一条记录再编辑!'); return false; } return true; } //数据检验 function confirmBusinessName() { var groupName = Ext.getCmp("groupName").getValue(); if("" == groupName) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "请输入组名!"); return false; } return true; } function setCenter(v) { return "<span style='width:100%;text-align:center;'>" + v + "</span>"; } function editLevel() { //发送状态 1成功 0 失败(根据回执判断是否失败) var arrData = [['0','0'], ['1','1'], ['2', '2'], ['3', '3'], ['4', '4']]; editLevelForm = new Ext.form.FormPanel({ width:200, height:100, frame:true, labelWidth:60, labelAlign:"right", buttonAlign:'center', defaultType:"textfield", items:[ {id:"businessName", name:"businessName",fieldLabel:"业务应用",width:100,disabled:true}, {fieldWith:60,fieldLabel : "级别",arrData:arrData,xtype:"arrayComboBox", id : 'smsLevel',name : 'smsLevel',width : 100}, {id:"businessCode", name:"businessCode",hideLabel:true,hidden:true}], buttons:[{text:"确认",iconCls : 'silk_tick',handler:function(){ updateLevel(); }}, {text:"取消",iconCls:'silk_cancel',handler:function(){editLevelWin.hide()}}] }); editLevelWin = new Ext.Window( { id:"editLevelWin", title:"编辑优先级别", width:210, height:132, // autoHeight: true, resizable:false, modal:true, items:[editLevelForm] }); editLevelWin.on("hide",function(){editLevelWin.destroy()}); editLevelWin.show(); } function updateLevel() { var businessCode = Ext.getCmp("businessCode").getValue(); var smsLevel = Ext.getCmp("smsLevel").getValue(); Ext.Ajax.request({ url : Ext.sysd.getWithToken('/smsAppSetup/updateAppSetup.do'), method : 'post', params : { businessCode:businessCode, smsLevel:smsLevel }, success : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "保存成功!"); // seqNum = 0; gridMain.getStore().reload( /*{ params: { //默认显示第一页记录 start:0, limit:Ext.sysd.getPageSize() } }*/); Ext.getCmp("editLevelWin").close(); }, failure : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "保存失败!"); } }); } //时间交错判断 function comfirmTimePeriod() { var timePeriodStartStr=""; var timePeriodEndStr=""; for(var i = 0; i < count; i++) { var timeStartCtrl = editTimeForm.getForm().findField("timeStart" + i); var timeEndCtrl = editTimeForm.getForm().findField("timeEnd" + i); if(timeStartCtrl) { timePeriodStartStr += timeStartCtrl.getValue()+","; timePeriodEndStr += timeEndCtrl.getValue()+","; } } timePeriodStartStr=timePeriodStartStr.substr(0,timePeriodStartStr.length-1); timePeriodEndStr=timePeriodEndStr.substr(0,timePeriodEndStr.length-1); var timePeriodStartArr = timePeriodStartStr.split(','); var timePeriodEndArr = timePeriodEndStr.split(','); var periodFlag = false;//默认不存在时间交错情况 for(var i = 0; i< timePeriodStartArr.length; i++) { for(var j = 0; j< timePeriodEndArr.length; j++) { if(i == j) { continue; } else { if((timePeriodStartArr[j] < timePeriodStartArr[i])&&(timePeriodStartArr[i]<timePeriodEndArr[j])) { periodFlag = true; break; } else if((timePeriodStartArr[j] < timePeriodEndArr[i])&&(timePeriodEndArr[i]<timePeriodEndArr[j])) { periodFlag = true; break; } } } } return periodFlag; } //时间段交错判断 function comfirmTimePeriodEqual() { var timePeriodStartStr=""; var timePeriodEndStr=""; for(var i = 0; i < count; i++) { var timeStartCtrl = editTimeForm.getForm().findField("timeStart" + i); var timeEndCtrl = editTimeForm.getForm().findField("timeEnd" + i); if(timeStartCtrl) { timePeriodStartStr += timeStartCtrl.getValue()+","; timePeriodEndStr += timeEndCtrl.getValue()+","; } } timePeriodStartStr=timePeriodStartStr.substr(0,timePeriodStartStr.length-1); timePeriodEndStr=timePeriodEndStr.substr(0,timePeriodEndStr.length-1); var timePeriodStartArr = timePeriodStartStr.split(','); var timePeriodEndArr = timePeriodEndStr.split(','); var periodFlag = false;//默认不存在时间段重复情况 for(var i = 0; i< timePeriodStartArr.length; i++) { for(var j = 0; j< timePeriodEndArr.length; j++) { if(i == j) { continue; } else { if((timePeriodStartArr[i] == timePeriodStartArr[j])&&(timePeriodEndArr[i]==timePeriodEndArr[j])) { periodFlag = true; break; } } } } return periodFlag; } //是否修改判断 function confirmModify() { var timePeriodStartStr=""; var timePeriodEndStr=""; for(var i = 0; i < count; i++) { var timeStartCtrl = editTimeForm.getForm().findField("timeStart" + i); var timeEndCtrl = editTimeForm.getForm().findField("timeEnd" + i); if(timeStartCtrl) { timePeriodStartStr += timeStartCtrl.getValue()+","; timePeriodEndStr += timeEndCtrl.getValue()+","; } } timePeriodStartStr=timePeriodStartStr.substr(0,timePeriodStartStr.length-1); timePeriodEndStr=timePeriodEndStr.substr(0,timePeriodEndStr.length-1); var timePeriodStartArr = timePeriodStartStr.split(','); var timePeriodEndArr = timePeriodEndStr.split(','); var flag = false;//默认未修改 if(timePeriodStartArr.length != iniCount || timePeriodEndArr.length != iniCount) { flag = true; } else { for(i = 0; i < count; i++) { if(-1 == timeStartArr.indexOf(timePeriodStartArr[i])) { flag = true; break; } if(-1 == timeEndArr.indexOf(timePeriodEndArr[i])) { flag = true; break; } var index = timeStartArr.indexOf(timePeriodStartArr[i]); if(timeEndArr[index] != timePeriodEndArr[i]) { flag = true; break; } } } return flag; } function updateTime() { var timeStartStr = ""; var timeEndStr = ""; var submitFlag = true;//是否提交标志 for(var i = 0; i < count; i++) { var timeStartCtrl = editTimeForm.getForm().findField("timeStart" + i); var timeEndCtrl = editTimeForm.getForm().findField("timeEnd" + i); if(timeStartCtrl) { if("" == timeEndCtrl.getValue()||"" == timeStartCtrl.getValue()) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "时间不能为空,请重新输入!"); submitFlag = false; break; } else if(timeEndCtrl.getValue() <= timeStartCtrl.getValue()) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "截止时间必须大于起始时间,请重新输入!"); submitFlag = false; break; } else if(comfirmTimePeriodEqual()) { Ext.Msg.alert(Sysd.Msg.AlertTitle,"时间段重复,请重新检查输入!"); submitFlag = false; break; } /* else if(comfirmTimePeriod())//前两个判断已经排除一些非法情况,所以comfirmTimePeriod()不需再判断 { Ext.Msg.alert(Sysd.Msg.AlertTitle,"时间段交错,请重新检查输入!"); submitFlag = false; break; } */ else { timeStartStr += timeStartCtrl.getValue()+","; timeEndStr += timeEndCtrl.getValue()+","; } } } if(submitFlag&&!confirmModify()) { submitFlag = false; editTimeWin.close(); } if(submitFlag) { timeEndStr=timeEndStr.substring(0,timeEndStr.lastIndexOf(",")); timeStartStr=timeStartStr.substring(0,timeStartStr.lastIndexOf(",")); timeBusinessCode = Ext.getCmp("timeBusinessCode").getValue(); timeBusinessName = Ext.getCmp("timeBusinessName").getValue(); Ext.Ajax.request({ url : Ext.sysd.getWithToken('/smsAppSetup/updateTimeAppSetup.do'), method : 'post', params : { businessCode:timeBusinessCode, businessName:timeBusinessName, timeStartStr:timeStartStr, timeEndStr:timeEndStr }, success : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "修改成功!"); // seqNum = 0; gridMain.getStore().reload( /*{ params: { //默认显示第一页记录 start:0, limit:Ext.sysd.getPageSize() } }*/); Ext.getCmp("editTimeWin").close(); }, failure : function(response) { Ext.Msg.alert(Sysd.Msg.AlertTitle, "修改失败!"); } }); } } function addTimeControl(id) { var timeStartId = "timeStart" + id; var timeEndId = "timeEnd" + id; var timeStartField = new Ext.form.TimeField({id:timeStartId, name:timeStartId, fieldLabel:"起始时间",width:90,format:"H:i:s",increment:30,editable : false,allowBlank:false}); var timeEndField = new Ext.form.TimeField({id:timeEndId, name:timeEndId, fieldLabel:"截止时间",width:90,format:"H:i:s",increment:30,editable : false,allowBlank:false}); var removeTimeBtn = {id:"removeTimeBtn"+id,xtype:"button", style:"padding-left:3px", text:"",iconCls:"silk_page_delete", handler:function(event){ var timeSetId = (event.id).replace("removeTimeBtn","editTimeFieldSet"); var timeSet = Ext.getCmp(timeSetId); if("" == timeStartField.getValue() && "" == timeEndField.getValue()) { confirmShowAddControl(); editTimeForm.remove(timeSet,true); } else { Ext.Msg.confirm(Sysd.Msg.AlertTitle,"是否删除该时间段?",function(btn) { if('yes' == btn) { confirmShowAddControl(); editTimeForm.remove(timeSet,true); return true; } else { return false; } }); } }}; var addTimeBtn = {id:"addTimeBtn"+id,xtype:"button",text:"",iconCls:"silk_page_add", handler:function(event){ addTimeControl(count++); } }; var block = { layout:"column", items:[ {layout:"form",width:168,labelWidth:60,items:[timeStartField]}, {layout:"form",width:168,labelWidth:60,items:[timeEndField]}, {layout:"form",width:30,items:[removeTimeBtn]}, {layout:"form",width:30,items:[addTimeBtn]} ] }; var editTimeFieldSet = new Ext.Panel({ id:"editTimeFieldSet"+id, layout:'form', border:false, items:[block] }); editTimeForm.add(editTimeFieldSet); editTimeForm.doLayout(); } function confirmShowAddControl() { if(2 == editTimeForm.items.length) { Ext.getCmp("showAddControl").show(); } } function editTime() { editTimeForm = new Ext.form.FormPanel({ width:420, // autoWidth:true, height:213, frame:true, labelWidth:60, layout:"form", forceFit:true, autoScroll:"auto", bodyStyle : 'overflow-x:hidden; overflow-y:auto; padding:3px', labelAlign:"right", buttonAlign:"center", buttons:[{text:"确认",iconCls : 'silk_tick',handler:function(){ updateTime(); }}, {text:"取消",iconCls:'silk_cancel',handler:function(){ Ext.Msg.confirm(Sysd.Msg.AlertTitle,"是否确定要取消,取消将不保存数据?",function(btn) { if('yes' == btn) { editTimeWin.close(); return true; } else { return false; } }); }}] }); var bussiness = { layout:"column", items:[ {layout:"form",items:[{id:"timeBusinessName",xtype:"textfield",width:150,name:"timeBusinessName",fieldLabel:"业务应用",disabled:true}]}, {layout:"form",items:[{id:"timeBusinessCode", xtype:"textfield",name:"timeBusinessCode",hideLabel:true, hidden:true}]}, {layout:"form",bodyStyle: 'padding-left:100px', items:[{id:"showAddControl", xtype:"button",text:"增加一行", hidden:true, width:75, iconCls : 'silk_page_add',handler:function(){ Ext.getCmp("showAddControl").hide(); addTimeControl(count++); }}]}] } var businessSet = new Ext.Panel({ id:"businessSet", border:false, items:[bussiness] }); editTimeForm.add(businessSet); for(var i = 0; i < count; i++) { var timeStartId = "timeStart" + i; var timeEndId = "timeEnd" + i; var timeStartField = new Ext.form.TimeField({id:timeStartId, name:timeStartId, fieldLabel:"起始时间",width:90,format:"H:i:s",increment:30,editable : false, allowBlank:false}); var timeEndField = new Ext.form.TimeField({id:timeEndId, name:timeEndId, fieldLabel:"截止时间",width:90,format:"H:i:s",increment:30,editable : false, allowBlank:false}); var addTimeBtn = {id:"addTimeBtn"+i,xtype:"button",text:"",iconCls:"silk_page_add", handler:function(event){ addTimeControl(count++); } }; var removeTimeBtn = {id:"removeTimeBtn"+i, style:"padding-left:3px", xtype:"button",text:"",iconCls:"silk_page_delete", handler:function(event){ var id = (event.id).replace("removeTimeBtn","editTimeFieldSet"); var timeSet = Ext.getCmp(id); Ext.Msg.confirm(Sysd.Msg.AlertTitle,"是否删除该时间段?",function(btn) { if('yes' == btn) { confirmShowAddControl(); editTimeForm.remove(timeSet,true); return true; } else { return false; } }); }}; var block = { layout:"column", items:[ {layout:"form",width:168,items:[timeStartField]}, {layout:"form",width:168,items:[timeEndField]}, {layout:"form",width:30,items:[removeTimeBtn]}, {layout:"form",width:30,items:[addTimeBtn]} ] }; var editTimeFieldSet = new Ext.Panel({ id:"editTimeFieldSet"+i, layout:'form', border:false, items:[block] }); editTimeForm.add(editTimeFieldSet); editTimeForm.doLayout(); } editTimeWin = new Ext.Window( { id:"editTimeWin", title:"编辑发送时间", width:434, height:245, resizable:false, modal:true, items:[editTimeForm] }); editTimeWin.on("close",function(){ timeStartArr=[]; timeEndArr=[]; count = 0; }); editTimeWin.show(); } function directLevel() { var direct = [ ["0","0说明"], ["1","1说明"], ["2","2说明"], ["3","3说明"], ["4","4说明"]] var proxy = new Ext.data.MemoryProxy(direct); var reader = new Ext.data.ArrayReader({}, [ {name: "did", type: "string", mapping: 0}, {name: "dname", type: "string", mapping: 1} ]); var storeDirect = new Ext.data.Store({ proxy: proxy, reader: reader, autoLoad: true //即时加载数据 }); //级别说明 gridDirect= new Ext.grid.GridPanel({ height:130, store:storeDirect, stripeRows:true, loadMask:{msg:"请稍等..."}, viewConfig : { forceFit : true }, columns:[ { header:setCenter('级别'), dataIndex:'did', align:'center', width:20, sortable:true }, { header:setCenter('级别说明'), dataIndex:'dname', align:'left', width:100, sortable:false }] }); formDirect = new Ext.form.FormPanel( { layout:'fit', buttonAlign:'center', autoHeight:true, autoWidth:true, frame:true, buttons:[{text:"返回",iconCls : 'silk_application_home',handler:function(){ Ext.getCmp("winDirect").close(); }}], items:[gridDirect] }); //说明弹出窗口 winDirect = new Ext.Window( { id:"winDirect", title:"级别说明", width:450, height:205, resizable:false, draggable:false, modal:true, items:[formDirect] }); winDirect.show(); } function initSeq() { seqNum = 0; var recordCount = gridMain.getStore().getCount(); idArr=new Array(); for(var i = 0; i < recordCount; i++) { var seqCode = gridMain.getStore().getAt(i).get("SEQ_CODE"); if(-1 == idArr.indexOf(seqCode)) { idArr.push(seqCode); gridMain.getStore().getAt(i).set("SEQ_CODE",String(++seqNum)); } else { gridMain.getStore().getAt(i).set("SEQ_CODE",String(seqNum)); } } } function gridSpan(grid, rowOrCol, cols, sepCol) { var array1 = new Array(); var arraySep = new Array(); var count1 = 0; var count2 = 0; var index1 = 0; var index2 = 0; var aRow = undefined; var preValue = undefined; var firstSameCell = 0; var allRecs = grid.getStore().getRange(); if (rowOrCol == "row") { count1 = grid.getColumnModel().getColumnCount(); count2 = grid.getStore().getCount(); } else { count1 = grid.getStore().getCount(); count2 = grid.getColumnModel().getColumnCount(); } for (i = 0; i < count1; i++) { if (rowOrCol == "row") { var curColName = grid.getColumnModel().getDataIndex(i); var curCol = "[" + curColName + "]"; if (cols.indexOf(curCol) < 0) continue; } preValue = undefined; firstSameCell = 0; array1[i] = new Array(); for (j = 0; j < count2; j++) { if (rowOrCol == "row") { index1 = j; index2 = i; } else { index1 = i; index2 = j; } var colName = grid.getColumnModel().getDataIndex(index2); if (sepCol && colName == sepCol) arraySep[index1] = allRecs[index1].get(sepCol); var seqOldValue = seqCurValue = "1"; if (sepCol && index1 > 0) { seqOldValue = arraySep[index1 - 1]; seqCurValue = arraySep[index1]; } if (allRecs[index1].get(colName) == preValue && (colName == sepCol || seqOldValue == seqCurValue)) { //alert(colName + "======" + seqOldValue + "======" + seqCurValue); allRecs[index1].set(colName, " "); array1[i].push(j); if (j == count2 - 1) { //var index = firstSameCell + Math.round((j + 1 - firstSameCell) / 2 - 1); var index = firstSameCell;//首行显示数值 if (rowOrCol == "row") { allRecs[index].set(colName, preValue); } else { allRecs[index1].set(grid.getColumnModel().getColumnId(index), preValue); } } } else { if (j != 0) { //var index = firstSameCell + Math.round((j + 1 - firstSameCell) / 2 - 1); var index = firstSameCell;//首行显示数值 if (rowOrCol == "row") { allRecs[index].set(colName, preValue); } else { allRecs[index1].set(grid.getColumnModel().getColumnId(index), preValue); } } firstSameCell = j; preValue = allRecs[index1].get(colName); allRecs[index1].set(colName, " "); if (j == count2 - 1) { allRecs[index1].set(colName, preValue); } } } } grid.getStore().commitChanges(); //添加所有分隔线 var rCount = grid.getStore().getCount(); for (i = 0; i < rCount; i ++) { for (j = 0; j < grid.getColumnModel().getColumnCount(); j ++) { aRow = grid.getView().getCell(i,j); if (i == 0) { aRow.style.borderTop = "none"; aRow.style.borderLeft = "1px solid #ccc"; } else if (i == rCount - 1) { aRow.style.borderTop = "1px solid #ccc"; aRow.style.borderLeft = "1px solid #ccc"; aRow.style.borderBottom = "1px solid #ccc"; } else { aRow.style.borderTop = "1px solid #ccc"; aRow.style.borderLeft = "1px solid #ccc"; } if(j == grid.getColumnModel().getColumnCount()-1) aRow.style.borderRight = "1px solid #ccc"; if(i == rCount-1) aRow.style.borderBottom = "1px solid #ccc"; //aRow.style.borderBottom = "1px solid #ccc"; } } //去除合并的单元格的分隔线 for (i = 0; i < array1.length; i++) { for (j = 0; j < array1[i].length; j++) { if (rowOrCol == "row") { aRow = grid.getView().getCell(array1[i][j],i); aRow.style.borderTop = "none"; } else { aRow = grid.getView().getCell(i, array1[i][j]); aRow.style.borderLeft = "none"; } } } } Ext.onReady(sms.appSetup.main.init,sms.appSetup.main);