Joy
Joy

Reputation: 406

ExtJS close window before opening other window

I want to close window before opening other window, I've tried to do as bellow but it doesn't work, is there someone who can help me?

Snippet of my code:

listeners: {
    click: function() {
        var win = new Ext.window.Window({
            constrain: true,
            height: 300,
            title: 'Window',
            width: 300,
            closeAction: 'hide'
        });
        if (win.isVisible() !== true) {
            win.show();
        } else {
            win.close();
        }
    }
}

Upvotes: 2

Views: 2247

Answers (3)

Alexandre Neukirchen
Alexandre Neukirchen

Reputation: 2783

You need to add the beforeclose event to your window. In it you call the new window.

Ext.application({
    name: 'Fiddle',
    launch: function() {
        let i = 1;
        function create_window(title) {
            var win = new Ext.window.Window({
                constrain: true,
                height: 150,
                title: 'Window ' + title,
                width: 300,
                closeAction: 'hide',
                listeners: {
                    beforeclose: function (sender, options) {
                        i++;
                        create_window(i);
                        return true;
                    }
                }
            });
            if (win.isVisible() !== true) {
                win.show();
            } else {
                win.close();
            }    
        }
        create_window(i);
    }
});
<script src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all.js"></script>
<link type="text/css" rel="stylesheet" href="http://cdn.sencha.com/ext/gpl/4.2.0/resources/css/ext-all.css")/>

Upvotes: 0

Gilsha
Gilsha

Reputation: 14589

You can use Ext.WindowManager.

Ext.create('Ext.Button', {
  text: 'Click me',
  renderTo: Ext.getBody(),
  listeners: {
    click: function() {
      Ext.WindowManager.each(function(cmp) {
        cmp.close();
      });
      Ext.create('Ext.window.Window', {
        constrain: true,
        height: 300,
        title: 'Window',
        width: 300,
        closeAction: 'hide'
      }).show();
    }
  }
})
<script src="http://cdn.sencha.com/ext/gpl/4.2.0/ext-all.js"></script>
<link href="http://cdn.sencha.com/ext/gpl/4.2.0/resources/css/ext-all.css" rel="stylesheet" />

Upvotes: 1

LellisMoon
LellisMoon

Reputation: 5030

var win = new Ext.window.Window({
            constrain: true,
            height: 300,
            title: 'Window',
            width: 300,
            closeAction: 'hide',
            listeners:{
                beforeclose:function(){
                    Ext.Msg.alert('Close','You\'re closing Window',function(){
                        var win2== new Ext.window.Window({
                            constrain: true,
                            height: 300,
                            title: 'Window2',
                            width: 300,
                            closeAction: 'hide'
                        });
                        win2.show();
                    });
                }
            }
        });
        win.show();

Upvotes: 0

Related Questions