PDA

View Full Version : Reset activeitem on change TabPanel‏



kevinv1990
17 Apr 2011, 1:33 PM
Hello everyone,

I'm rewriting my WebApp at the moment, started from scratch and using a much better architecture, so managing the code will be real easy. Here is the current version: http://webservices.hireserve.nl/kevin/HireApp/ . I don't know why but for some reason on google Chrome the tabbar below misses 5 pixels or so. But this is no problem on iPhone.

I want that if I change between tabs, the first Item of that tab is shown. This because long story short: I want to use 1 toolbar docked above, this toolbar has a back handler than shows the previous panel, those panels i pop and push in an array. But when I change between tabs, the array must be empty of course, otherwise when the back button will be shown when he is not needed and other problems.

I wrote a little code already:


hireserve.controllers.resetviews = function() {
// all views (all with card layout), must be reset
var tabpanels = [];
var tabpanel = Ext.getCmp('TabPanel');
if(tabpanel.getComponent(0)) {
tabpanels.push(tabpanel.getComponent(0));
if(tabpanel.getComponent(1)) {
tabpanels.push(tabpanel.getComponent(1));
if(tabpanel.getComponent(2)) {
tabpanels.push(tabpanel.getComponent(2));
if(tabpanel.getComponent(3)) {
tabpanels.push(tabpanel.getComponent(3));
if(tabpanel.getComponent(4)) {
tabpanels.push(tabpanel.getComponent(4));
}
}
}
}
}
for(var i = 0; i < tabpanels.length; i++) {
Ext.getCmp(tabpanels[i].id).setActiveItem(0);
}
}


That code works, all the views of every tab in the tabpanel will reset to the first item defined (mostly the home item of that tab).

Now the only problem is, I don't know when I should call this function. I wanted to do it in a listener on the tabbar from the tabpanel, listener "change" as name. But when I do that, a tiny second you see the homepanel of the current tab you are on before it shows you the new main tab panel.

By the way, got the twitter thing working on the first panel when you start the app, feel free to copy the source :) (press on "Volg ons op twitter").


Thanks for reading and I hope you can help,

Kevin