右键部分代码:
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右键事件结束*/
效果图: