PDA

View Full Version : Change view on load



martinbroos
19 Jun 2011, 1:23 PM
Maybe this is a noob question but i can't get it to work...
I want to change view after a check if sessionstorage is set.

The check seems to work but the moment of changing view gives me errors.
In initComponent it is to early to change view cause a this moment the viewport isn't loaded yet.

So I added a listener with an afterrender function but still it gives me the error:

Uncaught TypeError: Cannot call method 'setActiveItem' of undefined
beheerpaneel.controllers.Menu.Ext.Controller.index cMenu.js:8

Anyone knows how i can change view without the use of a click event? cause when i do it on button click it works. But ofcourse i want to do this automaticly.

My code :



......

listeners: {
render: function(){

console.log('test');
isLoggedIn();
}
},
initComponent: function() {

beheerpaneel.views.Login.superclass.initComponent.apply(this, arguments);

}
});

function isLoggedIn()
{
//check if user is logged in
var object = userStorage.last();

if(object)
{
var isLoggedIn = object.data.isLoggedIn;
console.log(isLoggedIn);
}

if(isLoggedIn)
{

//load stores
beheerpaneel.stores.Pages.load();
beheerpaneel.stores.Orders.load();
beheerpaneel.stores.Customers.load();

//no need for login form
Ext.dispatch({
controller: beheerpaneel.controllers.Menu,
action: 'index',
animation: {type:'slide', direction:'down'}
});
}
}