PDA

View Full Version : Re: Communication between controllers



lorezyra
15 Dec 2011, 6:14 PM
In reference to the Q&A for http://www.sencha.com/forum/showthread.php?146752-Communication-between-controllers&highlight=application+event+fire ...

I would like to know the proper way to pass parameters/args to the function of the application controller.

According to the API (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.util.Observable-method-fireEvent), I only need to specify as follows:

fireEvent (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.util.Observable-method-fireEvent)( String (http://docs.sencha.com/ext-js/4-0/#!/api/String) eventName, Object (http://docs.sencha.com/ext-js/4-0/#!/api/Object)... args )

I've tried the following, but neither appear to work...


this.application.fireEvent("adminlogevent", "testing...");
this.application.fireEvent("adminlogevent", {msg: "testing..."});



The function works fine for the controller that houses it.


//...
init:function(){
if(Ext.isGecko && debug) console.log(" adminUIviewport.controllerInit()");
var me=this;
me.application.on({//handle system-application wide events and calls here!!
'systemlogoff': me.adminUIappLogoff,
scope: me
},{
'adminlogevent': me.adminUIappLogBoard,
scope: me
});


//...
adminUIappLogBoard: function(msg){
if (msg) {
var timeStamp= new Date();

if(Ext.isGecko && debug){console.info(Ext.util.Format.date(timeStamp,"Y/m/d G:i:s") + ": " + msg);}
Ext.StoreMgr.lookup('adminUILog').add({dateTime: Ext.util.Format.date(timeStamp,"Y/m/d G:i:s"),desc: msg});
//TODO: scroll to bottom of grid?
/*
var logHeight=Ext.getCmp("adminUILogger").getHeight();
Ext.getCmp("adminUILogger").setScrollTop(logHeight); // object.scrollTop = object.scrollHeight
*/
}
}



Can anyone enlighten me? Also, the docs say that fireEvent is supposed to return a Boolean. In firebug, it shows the return as undefined. Is this a bug?

lorezyra
15 Dec 2011, 9:29 PM
Looking at the (4.0.7) source, it appears that you can simply add on the parameters after the eventName.



fireEvent: function(eventName) {
var name = eventName.toLowerCase(),
events = this.events,
event = events && events[name],
bubbles = event && event.bubble;

return this.continueFireEvent(name, Ext.Array.slice(arguments, 1), bubbles);



So, this should be valid:

this.application.fireEvent("adminlogevent", "testing...");

I'm going to double check my scoping...

lorezyra
15 Dec 2011, 9:53 PM
Found the problem! My syntax for this.application.on() was incorrect. Just like the this.control() config, I needed to correctly define my syntax!




//...
init:function(){
if(Ext.isGecko && debug) console.log(" adminUIviewport.controllerInit()");
var me=this;
me.application.on({//handle system-application wide events and calls here!!
'systemlogoff': me.adminUIappLogoff,
'adminlogevent': me.adminUIappLogBoard,
scope: me
});


//...

}

lorezyra
15 Dec 2011, 10:01 PM
Both of these do, in fact, work...



this.application.fireEvent("adminlogevent", "testing...");
this.application.fireEvent("adminlogevent", {msg: "testing..."});



However, the second statement (obviously) passes an object instead of the text. My function expects a string...