简体   繁体   中英

show message box ext window beforeclose event

I want to show message box when user click (X) button of ext window, and on 'ok' button of message box window will close. I wrote the code but it closes window first than show message box. Here is the code:

var assignReportFlag = 0;
var assignReportLoader = function(title,url){   
var panel = new Ext.FormPanel({
    id: 'arptLoader',
    height: 485,
    border: false,
    layout: 'fit',      
    autoScroll: true,
    method:'GET',
    waitMsg: 'Retrieving form data',
    waitTitle: 'Loading...',
    autoLoad: {url: url,scripts: true}
});

var cqok = new Ext.Button({
    text:'OK',
    id:'1',
    handler: function(){            
        if(assignReportFlag == 1){
            assignReportFlag = 0;
            Ext.MessageBox.alert('Status', 'Changes has been saved successfully',showResult);
        }else{
            assignReportWindow.close();         
        }           
    }
});

var assignReportWindow = new Ext.Window({       
    layout:'fit',
    title: title,       
    height:Ext.getBody().getViewSize().height - 60,
    width:Ext.getBody().getViewSize().width-20,
    closable: true,
    modal:true,
    resizable: false,
    autoScroll:true,
    plain: true,
    border: false,
    items: [panel],
    buttons: [cqok],
    listeners:{
        beforeclose:function(){
            if(assignReportFlag == 1){
                assignReportFlag = 0;
                Ext.MessageBox.alert('Status', 'Changes has been saved successfully',showResult);
            }else{
                assignReportWindow.destroy();           
            }
        }
    }
});

function showResult(btn){       
    assignReportWindow.destroy();   
};

assignReportWindow.show();
};

Thanks

在您的beforeclose侦听器中返回 false 以停止触发关闭事件。

This works fine for me.Have a look

http://jsfiddle.net/DrjTS/266/

var cqok = new Ext.Button({
text:'OK',
id:'1',
handler: function(){            
        Ext.MessageBox.alert('Status', 'Changes has been saved successfully',showResult);
    }
 });

Ext.create('Ext.panel.Panel', {
title: 'Hello',
width: 200,
renderTo: Ext.getBody(),
items:[
        {
xtype:'button',
text:'SUBMIT',
            handler:function(thisobj)
            {
                Ext.create('Ext.window.Window', {
                id:'W',
                height: 200,
                width: 400,
                layout: 'fit',
                buttons: [cqok],
                listeners:{
                beforeclose:function(){
                            Ext.MessageBox.alert('Status', 'Changes has been saved');
                        }
                }    
                }).show();
            }
        }
       ]

    });

    function showResult(btn){       
    Ext.getCmp('W').destroy();   
    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM