I have my 4.2.1 ExtJS application listen to every Ajax request (Ext.data.Connection) so I can do custom error handling and other stuff.
Im doing that inside my Main Controller
Ext.define('App.controller.Main', {
extend: 'Ext.app.Controller',
init: function (application) {
var me = this;
this.control({
'[xtype=login] button#btnLogin': {
click: me.onLogin
},
});
Ext.util.Observable.observe(Ext.data.Connection, {
requestcomplete: function (conn, response, options) {
// Do stuff on success
},
requestexception: me.handleRequestException // Do stuff on failure
});
},
handleRequestException: function (conn, response, options) {
var me = this;
if (response.status == 401) {
// here i need to fire the logoutApplication method
// have tried: me.fireEvent('logoutApplication'); but fireEvent is undefined because "me" scope is data.Connection
// it doesnt know about the controller.
}
},
logoutApplication: function () {
var me = this;
// do somestuff here!!
}
Inside the handleRequestException function Im trying to do me.fireEvent(...) but fireEvent is undefined because the scope of the function is data.Connection.
I don't want to use:
var mainController = App.app.getController('App.controller.Main');
Because when calling that the init is fired and I get issues with event firing twice.
Im new in ExtJS so Im sure there is a better way to do this. Appreciate any advice.