PDA

View Full Version : Events/Actions repeating on controller



mvosantos
29 Sep 2012, 1:14 PM
Hello guys,
I created tabpanel to place many tabs with a gridpanel (CustomersList.js).
If I create two tabs with the same view, the controller repeat the actions the number of tabs/gridpanel I create.
For instance: I create two tabs and on tab 2 I click on a item of my toolbar.
The event fires twice.
If I create three tabs with the same view, the event fires three times.

How can I fix my controller to fire the event just one time?

vietits
30 Sep 2012, 12:17 AM
It seems that your controller init is called many times! It's better to post your code here because it's hard to say without looking at your code.

metalinspired
30 Sep 2012, 9:55 AM
It seem to me that you haven't specified your selectors correctly for controller this.control() function.
You should post this.control() part of your controller code.
you need to make both of those panels unique.
For example, if you code your this.control() function like this


this.control({
'window > tab': {
some event: function() { // do something... }
}
});
it will fire "some event" as many times as much shown tabs you have.
There are two ways of dealing with this.
Either specify selector for each tab:


this.control({
'window > tab[name=tab1]': {
some event: function() { // do something... }
},
'window > tab[name=tab2]': {
some event: function() { // do something... }
},
and so on
});
or put switch statemant in your selector:


this.control({
'window > tab': {
some event: function(el) {
switch (el.name) {
case "tab1":
//some code
break;
case "tab2":
//some other code
break;
}
}
}
});

Hope I'm not too confusing as I'm dead tired right now :S

flanders
30 Sep 2012, 11:40 AM
If the same handler function is fired multiple times it is most likely that vietits is right. Can be checked with one simple log message. I think the suggestion from metalinspired is less advisable it would introduce a new handler for every tab, which you would not want (if there are 0..* instances that should all be treated the same way. (You just need your handler to work from the provide instance, not do a general query for your component)

We do on-the-run instantiation of controlelrs to, and we created a new function init() on a controller that does two things:
- Provide an error if this.isInitialized is true
- Set this.isInitialized to true.

We have had a number of occasions where controllers were inited multiple times. (F.e. due to internal ext changes that reacted with our custom work) Now we call callParent() in ever controller init and we see it straight away if we mess up.

Can recommend it. Sorry, felt like typing a book in the WOW que... :P

metalinspired
30 Sep 2012, 12:13 PM
Book worth reading :)
I find it easier to write my applications without using controllers.

flanders
30 Sep 2012, 12:21 PM
Thnx

And yea, I saw that in the other post ;) Its not a discussion to have here although my fingers are itching to write a sequal :P