ExtJs中为GridPanel行添加右键操作

右键部分代码:

var varmenu = null; 
/*doorGrid右键事件开始*/
var contextmenu=new Ext.menu.Menu({
	id:'theContextMenu',
	// Create the menu
	items:[{
		text: '禁止通行',
		iconCls: 'manage',
		handler: function(){
			/** 将holderId,doorId这条记录删掉即解除了门禁权限 */
			var holderIds = "";
			if(holderIdAlls != null && holderIdAlls != "") {
				holderIds = holderIdAlls;
				holderIdAlls = "";
			} else {
				var array = holderGrid.getSelectionModel().getSelections();
				for(var i=0; i<array.length; i++) {
					if(holderIds==""){
					  holderIds = array[i].data.id;
					}else{
					  holderIds = holderIds + "," + array[i].data.id;
					}
				}
			}
			if(holderIds != null || holderIds!=""){
				Ext.Ajax.request({
					url: './jxy/doorsystem/cancelRuleFromHolderAction',
					success: function(response, options){
						Ext.Msg.show({
							msg: Ext.decode(response.responseText).success,
							buttons: Ext.Msg.OK
						});
						doorStore.load({ params: { start: 0, limit: allPageSize} });
					},
					failure: function(response, options){
						Ext.Msg.show({
							msg: Ext.decode(response.responseText).failure,
							buttons: Ext.Msg.ERROR
						}); 
					},
					params: { ruleId: "", holderId: holderIds, doorId: doorId }
				});
			}else{
				Ext.Ajax.request({
					url: './jxy/doorsystem/cancelRuleFromHolderAction',
					success: function(response, options){
						Ext.Msg.show({
							msg: Ext.decode(response.responseText).success,
							buttons: Ext.Msg.OK
						});
						doorStore.load({ params: { start: 0, limit: allPageSize} });
					},
					failure: function(response, options){
						Ext.Msg.show({
							msg: Ext.decode(response.responseText).failure,
							buttons: Ext.Msg.ERROR
						}); 
					},
					params: { ruleId: "", holderId: holderId, doorId: doorId }
				});
			}
		}
	},'-'],
	listeners:{
		//beforeshow:function(menu){...}
		'beforerender':function(menu){
			varmenu = menu;
		}
	}
}); 
var flag = 0;
doorGrid.on('rowcontextmenu',function(grid,rowIndex,e){
	e.preventDefault();
	grid.getSelectionModel().selectRow(rowIndex);
	contextmenu.showAt(e.getXY());
	var selectionModel = grid.getSelectionModel();    
	var record = selectionModel.getSelected();
	if(!(record==null||record==undefined)){
		doorId = record.get('id');
	}
	varmenu.removeAll();
	varmenu.add({
		text: '禁止通行',
		iconCls: 'manage',
		handler: function(){
			/** 将holderId,doorId这条记录删掉即解除了门禁权限 */
			var holderIds = "";
			if(holderIdAlls != null && holderIdAlls != "") {
				holderIds = holderIdAlls;
				holderIdAlls = "";
				flag = 1;
			} else {
				flag = 0;
				var array = holderGrid.getSelectionModel().getSelections();
				for(var i=0; i<array.length; i++) {
					if(holderIds==""){
					  holderIds = array[i].data.id;
					}else{
					  holderIds = holderIds + "," + array[i].data.id;
					}
				}
			}
			if(holderIds != null || holderIds!=""){
				Ext.Ajax.request({
					url: './jxy/doorsystem/cancelRuleFromHolderAction',
					success: function(response, options){					
						holderStore.load({ params: { start: 0, limit: allPageSize} });
					},
					failure: function(response, options){
						Ext.Msg.show({
							msg: Ext.decode(response.responseText).failure,
							buttons: Ext.Msg.ERROR
						}); 
					},
					params: { ruleId: ruleId, holderId: holderIds, doorId: doorId }
				});
			}else{
				Ext.Ajax.request({
					url: './jxy/doorsystem/cancelRuleFromHolderAction',
					success: function(response, options){
						Ext.Msg.show({
							msg: Ext.decode(response.responseText).success,
							buttons: Ext.Msg.OK
						});
						holderStore.load({ params: { start: 0, limit: allPageSize} });
					},
					failure: function(response, options){
						Ext.Msg.show({
							msg: Ext.decode(response.responseText).failure,
							buttons: Ext.Msg.ERROR
						}); 
					},
					params: { ruleId: ruleId, holderId: holderId, doorId: doorId }
				});
			}
		}
	});
	varmenu.add('-');
	Ext.Ajax.request({  
		url:'./jxy/doorsystem/queryAllRulesAction',  
		success:function(response){  
			var items = response.responseText; 
			var array = holderGrid.getSelectionModel().getSelections();
			var itemArr = items.split(",");
			for(var i = 0; i < itemArr.length; i++){
				text = itemArr[i].split("-")[1];
				ruleId = itemArr[i].split("-")[0];
				var menuItem = new Ext.menu.Item({ 
					text: text,
					iconCls: 'manage',
					id: ruleId,
					listeners:{
						click: function(){
							ruleId = this.id;
						}
					},
					handler: function(){
						/** ruleId,holderId,doorId这三个参数都获得到了,直接下载即可,就是修改数据库rtd */
						/** 如果数据库中已经有记录了,则直接删掉再添加一条记录即可 */
						/** 没有有记录的话,则直接添加一条记录即可,在后台处理 */
						var holderIds = "";
						if(holderIdAlls != null && holderIdAlls != "") {
							holderIds = holderIdAlls;
							holderIdAlls = "";
							flag = 1;
						} else {
							flag = 0;
							var array = holderGrid.getSelectionModel().getSelections();
							for(var i=0; i<array.length; i++) {
								if(holderIds==""){
								  holderIds = array[i].data.id;
								}else{
								  holderIds = holderIds + "," + array[i].data.id;
								}
							}
						}
						if(holderIds != null || holderIds!=""){
							Ext.Ajax.request({
								url: './jxy/doorsystem/downRuleToHolderAction',
								success: function(response, options){
									var endRoleTime = new Ext.Window({//生成一个 ExtJS 视窗 组件对象
										width:300,  
										height:100,
										plain : true, 
										closeAction:"close",  
										title:'添加规则结束时间',
										modal:true,
										id: 'addruletime',
										labelAlign: 'right',
										items : [{
											xtype: 'panel',
											width: 300,
											labelAlign: 'right',
											border : true,
											items : [{
												layout: 'form',
												items: [{
													layout: 'column',
													xtype : 'datefield',
													format : 'Y-m-d',
													id : 'endRuleTime',
													name : 'endRuleTime',
													selectOnFocus : true,
													editable : false,
													style: 'margin-left:20;', 
													fieldLabel: ' 规则结束时间',
													width : 120												
												},{
													layout: 'column',
													items:[
														new Ext.Button({
															text : '保存',
															width: 40,
															iconCls: 'save',
															style: 'margin-left:50;', 
															handler : function() {
																if(Ext.getCmp('endRuleTime').getValue()==""){
																	Ext.Msg.show({
																		msg:"请先选择规则结束时间,然后再点保存!",
																		buttons: Ext.Msg.OK
																	});
																	return false;
																}
																var endRuleTime = Ext.util.Format.date(Ext.getCmp('endRuleTime').getValue(),'Y-m-d'); 
																Ext.Ajax.request({
																	url: './jxy/doorsystem/updateEndRoleTimes',
																	success: function(response, options){
																		Ext.Msg.show({
																			msg: Ext.decode(response.responseText).success,
																			buttons: Ext.Msg.OK
																		});
																		endRoleTime.close();
																	},
																	failure: function(response, options){
																		Ext.Msg.show({
																			msg: Ext.decode(response.responseText).failure,
																			buttons: Ext.Msg.ERROR
																		}); 
																	},
																	params: { ruleId: ruleId, holderIds: holderIds, doorId: doorId, endRuleTime: endRuleTime }
																})																
															}
														}),new Ext.Button({
															text : "取消",
															iconCls: 'cancel', 
															listeners :{
																click : function(){
																	endRoleTime.close();
																}
															}
														})
													]
												}]
											}]
										}]
									});
									endRoleTime.show();
									holderStore.load({ params: { start: 0, limit: allPageSize} });
								},
								failure: function(response, options){
									Ext.Msg.show({
										msg: Ext.decode(response.responseText).failure,
										buttons: Ext.Msg.ERROR
									}); 
								},
								params: { ruleId: ruleId, holderId: holderIds, doorId: doorId ,flag :flag }
							});
						}else{
							Ext.Ajax.request({
								url: './jxy/doorsystem/downRuleToHolderAction',
								success: function(response, options){
									Ext.Msg.show({
										msg: Ext.decode(response.responseText).success,
										buttons: Ext.Msg.OK
									});
									holderStore.load({ params: { start: 0, limit: allPageSize} });
								},
								failure: function(response, options){
									Ext.Msg.show({
										msg: Ext.decode(response.responseText).failure,
										buttons: Ext.Msg.ERROR
									}); 
								},
								params: { ruleId: ruleId, holderId: holderId, doorId: doorId ,flag :flag}
							});
						}
					}
				}); 
				if(text){
					varmenu.add(menuItem);
				}
			}
		},
		params: {doorId: doorId }
	});
}); 
/*grid右键事件结束*/


 

效果图:


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值