Arkady
Arkady

Reputation: 393

Ext.Msg.confirm - Object [object Window] has no method '...'

I am trying to set up a confirmation message on push of a logout button, where if the users clicks 'yes' then is redirected to panel control in a container called 'myContainer'. The message appears fine but when I select 'yes' I get an error (assuming because the container is not initialized). I have a reference set up on my controller to the container, but that does not seem to help. Any advise on how to handle confirmation correctly like this is appreciated. Thanks

Confirmation message:

onLogoutTap: function(button, e, options) {
Ext.Msg.confirm("Logout", "Do you wish to continue?", function(button){
    if (button == 'yes') {
    //doesn't work:
        this.getMyContainer().setActiveItem(1);
    } else {
        return false;
    }
});
}

myContainer reference in Controller

myContainer: '#myContainer'

Error message:

Uncaught TypeError: Object [object Window] has no method 'getMyContainer'

Upvotes: 1

Views: 5100

Answers (3)

Titouan de Bailleul
Titouan de Bailleul

Reputation: 12949

A little trick I often use is this

onLogoutTap: function(button, e, options) {
  var controller = this;
  Ext.Msg.confirm("Logout", "Do you wish to continue?", function (button) {
    if (button == 'yes') {
    //doesn't work:
        controller.getMyContainer().setActiveItem(1);
    } else {
        return false;
    }
  });
}

Like so, you can still access the function object with the keyword this.

Hope this helps

Upvotes: 5

olegtaranenko
olegtaranenko

Reputation: 3850

another way is

onLogoutTap: function(button, e, options) {
    Ext.Msg.confirm("Logout", "Do you wish to continue?", function(button){
        if (button == 'yes') {
        //DOES WORK!!
            this.getMyContainer().setActiveItem(1);
        } else {
            return false;
        }
    }, this);
}

just add the 'scope' parameter after function definition.

Upvotes: 0

Thiem Nguyen
Thiem Nguyen

Reputation: 6365

Here:

function(button){
    if (button == 'yes') {
    //doesn't work:
        this.getMyContainer().setActiveItem(1);
    } else {
        return false;
    }

this refers to your function object, not controller.

If you want to call that method of your controller, try:

Ext.getApplication().getController("your_controller_name").getMyContainer();

Hope it helps.

Upvotes: 1

Related Questions