PDA

View Full Version : setActiveItem not working in Viewport



TDeBailleul
12 Dec 2011, 2:27 AM
Hi everyone,

I am currently working on authentication on my application. What I would like to do is displaying a panel with an authentication form if there are no credentials stored in the local storage OR displaying another panel if there are stored credentials.

I am currently doing this :



app.views.Viewport = function (config) {
Ext.apply(this, config);

this.user = null;
this.userLogin = new app.views.UserLogin();
this.bottomTabs = new app.views.BottomTabs();

app.views.Viewport.superclass.constructor.call(this, {
fullscreen: true,
layout: 'card',
cardSwitchAnimation: 'slide',
items: [
this.bottomTabs,
this.userLogin
]
});
};

Ext.extend(app.views.Viewport, Ext.Panel, {
initComponent: function () {
app.views.Viewport.superclass.initComponent.call(this);
console.log("launching initialCheckUser");
this.initialCheckUser();
},

initialCheckUser: function () {
console.log("initialCheckUser");
var credentials = window.localStorage.getItem("neroApp_credentials");
if (credentials == null || credentials == "reset") {
console.log("NO CREDS");
this.setActiveItem(this.userLogin);
}
else {
console.log("CREDS");
Ext.Ajax.defaultHeaders = {'Authorization':"Basic " + credentials};
this.checkLogin();
}
},

checkLogin: function () {
console.log("checkLogin");
Ext.Ajax.request({
url: app.stores.baseAjaxURL + '&jspPage=%2Fajax%2FgetUser.jsp', scope: this,
success: function(response, opts) {
var user = Ext.decode(response.responseText);
this.user = user;
this.loginPassed();
},
failure: function(response, opts) {
alert("error");
}
});
},

loginPassed: function() {
console.log("loginPassed");
this.bottomTabs.actualites.actualitesList.refreshActu(this.user, parseInt(window.localStorage.getItem("newsPerLoad")));
this.setActiveItem(this.bottomTabs);
}

});


Here is the log I get :



2011-12-12 11:05:34.634 app[1500:13403] [INFO] launching initialCheckUser
2011-12-12 11:05:34.635 app[1500:13403] [INFO] initialCheckUser
2011-12-12 11:05:34.635 app[1500:13403] [INFO] NO CREDS


The panel that is displayed at the end is the bottomTabs panel instead of the userLogin panel. Apparently the line supposed to set the userLogin panel active is not working for some reason.

If somebody could take a quick look at this problem that'd be great.

Thanks

mitchellsimoens
12 Dec 2011, 9:19 AM
Is this.userLogin present?

TDeBailleul
12 Dec 2011, 9:23 AM
I don't really know what you mean by 'present'. It should normally be created during initComponents.

mitchellsimoens
12 Dec 2011, 9:24 AM
What is this.userLogin when you are using setActiveItem?

TDeBailleul
12 Dec 2011, 9:28 AM
It is an Ext.Panel defined in another file as below



app.views.UserLogin.superclass.constructor.call(this, {
dockedItems: [this.toolbar],
cls:'auth',
layout: 'vbox',
items: [
this.neroText,
this.loginPanel,
this.passPanel
]
});


It works fine.