msgBox
does not behave as alert
or confirm
: when called, it does not suspend the current execution thread.
Your function returns before the user has clicked on any button.
The simplest way to fix this would be to call your removeWorkspace
function from the "success" callback :
function showPrompt(ws){
$.msgBox({
title: "Are you sure",
content: "Do you want to save your work?",
type: "confirm",
buttons: [{ type:"submit", value: "Yes"},
{type: "submit", value: "No"},
{type: "cancel", value: "Cancel"}]
, success: function(result){
switch result {
case "Yes" :
removeWorkspace(ws);
break;
case "No" :
removeWorkspace(ws);
break;
}
}});
}
// change the calling site :
if($(this).parent().parent().hasClass("modified")){
showPrompt(this);
} else {
// default action :
removeWorkspace(this);
}