PDA

View Full Version : Controller listen to custom events in Architect 2



lrochfort
24 Apr 2012, 2:46 AM
Hi,

I want to decouple my Controller from my View, and as such do not want my Controller to listen to events raised by particular View components, but rather to application specific events that are raised by the View.

For instance, have the List select event fire an editRow event in the View and then have the Controller listen for this event and act accordingly.

When adding a Controller Action in Architect 2 I'm not able to manually enter and EventBinding name, only select one of the standard ones for the component type.

Is what I want to do sensible and is there an Architect 2 construct for it?

Any advice would be appreciated.

Regards,
Laurence.

kubens
24 Apr 2012, 2:56 AM
You can add a listener in the init method of your controller:



init: function(application) {
this.addManagedListener(application, 'i18nChange', me.onI18nChange, me);
},
onI18nChange: function() {
alert('onI18nChange');
}

lrochfort
24 Apr 2012, 3:14 AM
Thank you kubens.

FYI, addManagedListener is deprecated and has been replaced by addListener. http://docs.sencha.com/touch/2-0/#!/api/Ext.mixin.Observable-method-addManagedListener

kubens
24 Apr 2012, 3:45 AM
not for ExtJS4 :-?

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.app.Controller-method-addManagedListener

rklowe01
4 May 2012, 8:16 AM
but how would you fire an event from say, a button press, that would be handled by the controller. I added the following line to my button handler:

this.fireEvent('CustomEvent', button);

and my controller is set up to listed for onCustomEvent.

But when I press the button , the controller function onCustomEvent is not called.

If this can't work in Architect, is there another way to just call a controller function directly from within a button press handler? (or a way to call a global function)?

Thanks in advance...

oldroy
4 May 2012, 9:37 AM
I'd like to know the same thing. In complex apps this would be something that architect would need to allow. Seems that controlling all components and their event directly by ref and control in the controller would make some really big, fat, ugly controllers. If you could have the choice to push some of that out to the views (which are really kind of "view-controllers" not purely views anyway) it would be nice.

I'd like to know if there is a performance difference in your scenario. As in, does controlling the button by ref and control in the controller directly perform better/faster than firing a custom event and trying to manage that?

pmarko
8 May 2012, 2:30 AM
+1

zlog
5 Dec 2012, 11:31 AM
is this working now?

BostonMerlin
8 Dec 2012, 2:55 AM
Example:

in a button tap event add:

this.fireEvent('cmdDoSomethingForMe');

drag a controller action to a controller then set:

controlQuery: container
targetType: Ext.Button
fn: onCmdDoSomethingForMe
params: button
name: cmdLoadEntities

controlQuery and targtType would change as needed. Hope that helps a little. JB