PDA

View Full Version : Scope and applicaiton events



hciftci
19 Apr 2012, 3:46 AM
Hi

I try to build an application with Sencha Architect. The user must login before he can do anything. To achieve that, Iíve created an authentication view (a form in a modal Window) and an authentication controller. Additionally there is an application viewport:

34255

First the authentication view is displayed. When the user clicks the login button, an AJAX request is send to the backend and the when receiving a response from it, the onLoginResponse method is called:

Authentication.js

var responseArray = Ext.JSON.decode(response.responseText),
authStore = Ext.data.StoreManager.lookup('Authentication');

authentication = Ext.create('App.model.Authentication');
authentication.set('id', responseArray.data[0].id);
authentication.set('firstName', responseArray.data[0].firstName);
authentication.set('lastName', responseArray.data[0].lastName);
authentication.set('role', responseArray.data[0].role);
authentication.set('authorization', responseArray.data[0].authorization);

authStore.add(authentication);


In case the login is successful, I would like to fire an application global event:


this.application.fireEvent('login');

However, I have two problems until now. First, the actions created by Sencha Architect donít have a scope property. I would like to set the application controller scope where I can access the references:
34256
app.js

init: function() {

this.application.on({
Login: {
fn: this.onLogin
},
Logout: {
fn: this.onLogout
}
});
}

The second question is, how do I fire the application global event? this.application returns the authentication controller:

console.log(this.application);
this.application.fireEvent('login');

apsq
19 Apr 2012, 7:11 AM
You don't need to set a context ("scope") for controller actions as these will always be executed in the scope of the controller.

hciftci
19 Apr 2012, 7:13 AM
Thank you for your reply apsq. However, still I need a way to fire the events defined in the App.js within the Authentication controller. How can I do that?