PDA

View Full Version : Having trouble with MessageBox



JaimieWhiteside
25 Nov 2013, 4:42 AM
Hi,
I am working on a system that checks for the availability of a java service.
What I would like is on the failure of the Ajax request, is to present a message to the user asking if they want to launch the service.

In my controller I have:


Ext.define('MyController', {
extend: 'Ext.app.Controller',
requires: ['Ext.window.MessageBox'],
...
// this function triggered by an event
checkForService: function(){
var me= this;
var request = Ext.Ajax.request({
useDefaultXhrHeader: false,
url: 'http://localhost:8080/myservice',
method: 'GET',
cors: true,
limitParam: false,
noCache: false,
pageParam: false,
startParam: false,
failure: function(response, opts){
// no serviceavailable so tell user to launch
me.launchService();
}
});
},
...
launchService: function(){
var me = this;
Ext.MessageBox.show({
title: 'Service',
msg: 'The service is not running, would you like to start it?',
buttons: Ext.MessageBox.YESNO,
fn: me.openUrl,
icon: Ext.MessageBox.QUESTION
});
},
openUrl: function(){
// logic to launch service
}
}


When the service is not available, the launchService function is executed.
However, the message box is not displayed.
There are no errors in the console.

I'm at a bit of a loss as I was following the examples at:
http://docs.sencha.com/extjs/4.0.7/#!/example/message-box/msg-box.html
(http://docs.sencha.com/extjs/4.0.7/#!/example/message-box/msg-box.html)
I have also tried using Ext.MessageBox.alert, but that didn't work either.
The only thing currently working is the standard javascript alert.

Any ideas would be greatly appreciated.

dawesi
25 Nov 2013, 8:12 AM
to be consistant, you can also use:


failure : me.launchService

however without further context, it's hard to debug your code.

silcreval
26 Nov 2013, 4:39 AM
The first thing to check is scope. 'me' might not be what you think it is when 'failure' is called. For callbacks, I usually derive the scope from parameters passed into the failure() call or some other means rather than relying on external globals, etc.

console.log(me) in 'failure' to see what it is. launchservice may not be called.