hvtilborg
10 Jan 2012, 1:48 AM
Hey guys,
I have the following class:
Ext.define('DC.misc.Cockpit', {
singleton: true,
doXHRIfConfirmed: function(config)
{
config = Ext.apply({
route: 'pingpong',
title: '',
question: 'Sure?',
params: null,
successMsg: 'Successful.',
successFn: function() {},
failureMsg: 'Failure.',
failureFn: function() {}
}, config || {});
Ext.Msg.confirm(
config.title,
config.question,
function(button)
{
if (button == 'yes') {
Ext.Ajax.request({
method: 'POST',
url: Routing.generate(config.route),
params: config.params,
success: function(response)
{
var json = Ext.decode(response.responseText);
if (json.success) {
DC.misc.Cockpit.showInfoMsg(config.title, config.successMsg);
config.successFn();
} else {
DC.misc.Cockpit.showErrorMsg(config.failureMsg);
config.failureFn();
}
},
failure: function()
{
DC.misc.Cockpit.showErrorMsg(config.failureMsg);
config.failureFn();
},
scope: this
});
}
},
this
);
}
Now I'd like to call this static function like this:
DC.misc.Cockpit.doXHRIfConfirmed({
route: 'client_json_destroy',
params: {
client_id: this.clientId
},
title: 'Deactivate client',
successFn: function() { me.doReload(); },
scope: this
});
But of course, the scope is wrong then (i.e. 'scope: this' has no effect). Should I call DC.misc.Cockpit.doXHRIfConfirmed() using Ext.callback or Ext.Function.bind, or...?
I have the following class:
Ext.define('DC.misc.Cockpit', {
singleton: true,
doXHRIfConfirmed: function(config)
{
config = Ext.apply({
route: 'pingpong',
title: '',
question: 'Sure?',
params: null,
successMsg: 'Successful.',
successFn: function() {},
failureMsg: 'Failure.',
failureFn: function() {}
}, config || {});
Ext.Msg.confirm(
config.title,
config.question,
function(button)
{
if (button == 'yes') {
Ext.Ajax.request({
method: 'POST',
url: Routing.generate(config.route),
params: config.params,
success: function(response)
{
var json = Ext.decode(response.responseText);
if (json.success) {
DC.misc.Cockpit.showInfoMsg(config.title, config.successMsg);
config.successFn();
} else {
DC.misc.Cockpit.showErrorMsg(config.failureMsg);
config.failureFn();
}
},
failure: function()
{
DC.misc.Cockpit.showErrorMsg(config.failureMsg);
config.failureFn();
},
scope: this
});
}
},
this
);
}
Now I'd like to call this static function like this:
DC.misc.Cockpit.doXHRIfConfirmed({
route: 'client_json_destroy',
params: {
client_id: this.clientId
},
title: 'Deactivate client',
successFn: function() { me.doReload(); },
scope: this
});
But of course, the scope is wrong then (i.e. 'scope: this' has no effect). Should I call DC.misc.Cockpit.doXHRIfConfirmed() using Ext.callback or Ext.Function.bind, or...?