PDA

View Full Version : class refering back to object in main stream



DaveC426913
22 Oct 2010, 6:14 AM
This is a straight OOP thing. Not sure how it works within Ext.

My Session class, in a separate MERCON.session.js file:

In a nutshell, if the Ajax call fails to return in time, send a message to the txtMessage field in the UI.


Ext.ns('MERCON.session');
...
MERCON.session = {
login: function(){

// Ajax call
Ext.Ajax.request({
...
success: function(response, opts) {
...
},

failure: function(response, opts) {
setMessage("err","Having trouble logging in. Trying again. Try #" + this.retryCounter);
retryLogin();
},
});


My main stream index.js (that handles all UI). This is where the setMessage function is.


Ext.setup({
onReady: function() {
var main = new Ext.Panel({
... all my screen components
});

// functions

function setMessage(state,msg){
txtMessages.addClass(state)
txtMessages.update(msg)
}
}


});



Results in Uncaught ReferenceError: setMessage is not defined

DaveC426913
22 Oct 2010, 7:41 AM
I got it. I placed my globally-accessible setMessage() function outside the Ext.setup.




Ext.setup({
onReady: function() {
var main = new Ext.Panel({
... all my screen components
});

// functions

}


});

MERCON.UI.function setMessage(state,msg){
txtMessages.addClass(state)
txtMessages.update(msg)
}


Now I can do this:


Ext.ns('MERCON.session');
...
MERCON.session = {
login: function(){

// Ajax call
Ext.Ajax.request({
...
success: function(response, opts) {
...
},

failure: function(response, opts) {
MERCON.UI. setMessage("err","Having trouble logging in. Trying again. Try #" + this.retryCounter);
retryLogin();
},
});


You guys are sooo clever, holding off your avalanche of responses long enough for me to find the answer myself...