PDA

View Full Version : Can a Panel with a Card Layout and Multiple Panels Be Reset to the Default Panel?



markwyner
17 Mar 2011, 2:11 PM
I have a tabpanel comprising a few panels (stripped out irrelevant code):


AppName.ItemsDetails = new Ext.Panel({
id: 'items_details',
dockedItems: [{
xtype: 'toolbar',
items: [{
handler: function() {
AppName.ItemsWrapper.setActiveItem('items_panel');
}
}]
}]
});
AppName.ItemsPanel = new Ext.Panel({
id: 'items_panel',
items: [{
listeners: {
itemtap: function() {
AppName.ItemsWrapper.setActiveItem('items_details');
}
}
}]
});
AppName.ItemsWrapper = new Ext.Panel({
layout: 'card',
items: [AppName.ItemsPanel,AppName.ItemsDetails]
});
AppName.Viewport = new Ext.TabPanel({
items: [AppName.ItemsWrapper,AppName.AnotherWrapper,AppName.AnotherWrapper]
});

What I Expect to Happen:


I tap into ItemsWrapper which loads ItemsPanel
I tap a list item which loads ItemsDetails
I tap a tab in the Viewport tabpanel which leaves ItemsWrapper behind and loads another wrapper
I tap the tab in the Viewport tabpanel which reloads ItemsWrapper's default view: ItemsPanel


What Actually Happens:

When I tap the tab in the Viewport tabpanel which reloads ItemsWrapper it loads that panel in its previous state, with ItemsDetails in view. In other words, I expect the wrapper panel to always load its default child panel. Instead, it loads whatever child panel was last in view.

What I'd Like Help With:

I'm wondering how I can reset the wrapper panel when tapping one of the tabs in the tabpanel so that it is ready to go with its default child panel any time I tap back to it.

Any help would be greatly appreciated.

Thanks in advance.

markwyner
2 Apr 2011, 9:58 AM
I don't suppose anyone has an answer for this one? I think it's pretty fundamental but I can't find information about it.

This also applies to restarting the application when it's on a phone, rather than being served as a web page. So I use Xcode to install the app on my provisioned iPhone. I open and use it for a bit then quit out of it. When I restart the app again it goes to whatever screen was in view when it quit. I'm looking for a way to essentially reset the app so it begins from the very first card as if it were being started for the very first time.

Sometimes it's appropriate to leave views as they were. However, there are times when it's also appropriate to reset everything.

So, in short, what kind of call can you make to reset an entire card on both start up of the app and when entering any given card via setActiveItem?

I'd love any help on this. It's plaguing me throughout my development, putting big roadblocks in place for me.

Thanks!

patrickhamann
23 Jun 2011, 7:09 AM
Hi Mark,

Did you ever find a solution to this problem? I agree with you it must be an easy/fundamental solution, but just can't find any documentation on how too.

Thanks

digil
23 Jun 2011, 7:18 AM
I don't have code for you, but it sounds like you want to add a tap listener on the button in the tabbar that will call setActiveItem every time. Is this right?

patrickhamann
23 Jun 2011, 7:23 AM
Hi Digil,

Thanks for the speedy response, I actually had sovled it already using a similar idea to yours using an onBeforeCardSwitch listener function.


onBeforeCardSwitch: function(newCard, oldCard, animated) { do stuff.. }

and setting the active item on the newCard and oldCard back to 0 in the array. Works perfectly!

Thanks

digil
23 Jun 2011, 7:28 AM
Hi Digil,

Thanks for the speedy response, I actually had sovled it already using a similar idea to yours using an onBeforeCardSwitch listener function.


onBeforeCardSwitch: function(newCard, oldCard, animated) { do stuff.. }

and setting the active item on the newCard and oldCard back to 0 in the array. Works perfectly!

Thanks

Even better! I like that better, a bit more robust.

markwyner
23 Jun 2011, 9:02 AM
I did. I actually apply a listener to the wrapper to activate the panel I want to load first:


listeners: {
activate: function() {
ListsWrapper.setActiveItem('lists_panel');
}
}

So every time the wrapper is activated it sets "lists_panel" to active.

Cheers.

haseeb
4 Jul 2011, 8:10 PM
Hi Digil,

The setActiveItem(0) is fine which i have tried already. Now the million dollar question is it possible to reset the card's state. If i can get that my app would be faster after loading it for the first time. For the sake of resetting the app, everytime when my user clicks on the logout button i refresh my index.html ie my app entry file to reset the app state.

Any help on this would be appreciated.

regards,
Haseeb