Ext tabPanel中的panel关闭时提示用户是否要关闭窗口

来源:互联网 发布:如何看网络3d蓝光电影 编辑:程序博客网 时间:2024/05/29 06:58
var t = false;//判断是否要关闭
var tabPs = window.tabs;//获得定义为全局的tablePanel对象
    var curPanel = tabPs.getActiveTab();//获得当前活动的panel
    curPanel.on('beforeclose',function(){
    //判断是否关闭
Ext.Msg.show({
       title:'提示',
       msg:'是否关闭本窗口',
       icon: Ext.MessageBox.QUESTION,
       buttons: {yes:i18n_saveButton,no:i18n_cancel},
       fn: function(option)
       {
       if(option=='yes')
       {
       t = true;
       curPanel.destroy();//调用销毁
       }else{
       tabPs.activate(curPanel);
       return false;
       }
       }
});
return false;
    });
    curPanel.on(
    'beforedestroy',function(tab){//在销毁对象前,判断用户是否要关闭窗口,好像在点击关闭按钮时,ext就异步开始销毁页面元素,所以不这样时,前面的Ext.Msg.alert()就显示不出来
    if(false == t){
    return false;
    }
    return true;
    }
    );
 
--------------------------------------------------------------------------------------------------

用Ext.TabPanel实现的table,如何实现关闭动作在鼠标mouseup时执行,而不是鼠标mousedown时执行? 

 
 

解法1:修改ExtJs中TabPanel的源代码。
1、在initEvents函数中增加如下语句:
this.strip.on('mouseup', this.onStripMouseUp, this);
2、增加mouseup事件对应的函数onStripMouseUp
onStripMouseUp : function(e){
 if(e.button != 0)
 {
     return;
 }
 e.preventDefault();
 var t = this.findTargets(e);
 if(t.close)
 {
     this.remove(t.item);
     return;
 }
},
3、修改mousedown事件对应的函数onStripMouseDown,去掉以下语句
if(t.close)
{
    this.remove(t.item);
    return;
}

解法2:自定义TabPanel,继承自Ext.TabPanel

var TabPanel = Ext.extend(Ext.TabPanel, {
       //给initEvents中增加关闭按钮的mouseup事件,以及关联事件对应的函数

      //增加mouseup事件对应的函数onStripMouseUp

      //重写mousedown事件对应的函数onStripMouseDown
  });