PDA

View Full Version : Pass the observable to observer and respond to firedEvent



Wolfie
21 Sep 2010, 6:15 AM
Hi all

I have some code and it is observable child :



var www = VCC.NotifyMgr.getInstance({listeners: {dataChange: function (respObj) {new VCC.ButtonsNotifyModule(respObj);}}});
www.start();

VCC.ButtonsNotifyModule = Ext.extend(Ext.util.Observable, {
prevCrmRole: '',
prevVccRole: '',

constructor: function(config){

config = config || {};

this.addEvents('crmRoleChange');
this.addEvents('vccRoleChange');

this.roleChange(this, config);

VCC.ButtonsNotifyModule.superclass.constructor.call(this, config);
},
roleChange : function (module, config){
var self = this;
config = config || {};
if(self.prevCrmRole != config.session.crm_role){
var crm_role = config.session.crm_role
self.prevRole = crm_role;
//Ext.ux.plugins.CheckBtnPermissions({role : crm_role, module: module})
self.fireEvent('crmRoleChange', crm_role);
}
}
});


So here I am creating the observable which will fire event and pass the parameter to observer which looks like this :


Here the button which is observer :


{text: 'testChangePermissionsBtn', plugins : [Ext.ux.plugins.CheckBtnPermissions({role : ['SM']})]}


and the plugin which observe the observable


The most importatn part is marked with arrow


Ext.namespace('Ext.ux.plugins');


Ext.ux.plugins.CheckBtnPermissions = Ext.extend(Ext.util.Observable, {
constructor : function(config){

Ext.apply(this, config);

//var module = config.module;
module.on('crmRoleChange', function(role) { <<-------
Ext.Msg.alert('test',role);
});
},
init : function(button){

}
})


So the problem is that I want to pass somehow the VCC.ButtonsNotifyModule to make the event 'crmRoleChange' on it...