I have this code:
$('.b-icon.b-icon_del').click(function(e) {
showConfirmDialog('Are you sure you want to delete this document?',deleteDocument(window.lastSelectedRowId), 'Delete document');
});
function showConfirmDialog(content, callback, pTitle, obj){
return showDialogEx(content, callback, pTitle, obj, "Yes", "No");
}
function showDialogEx(content, callback, pTitle, obj, okButtonLabel, cancelButtonLabel){
var str = "#_showMessageDialog";
var showMessageDialog = $(str);
if(showMessageDialog.length == 0){
$('body').append('<div id="_showMessageDialog"></div>');
showMessageDialog = $(str);
}
showMessageDialog.val("");
showMessageDialog.append('<p id="_showMessageDialogContent">'.concat(content, '</p>'));
var my_buttons = {};
my_buttons[cancelButtonLabel] = function(){
$(this).dialog("close");
$(this).html("");
$(this).dialog("destroy");
};
my_buttons[okButtonLabel] = function(){
callback();
$(this).html("");
$(this).dialog("close");
if(obj){
obj.focus();
}
$(this).dialog("destroy");
};
showMessageDialog.dialog({
modal : true,
resizable : true,
title : pTitle,
minWidth : 250,
width : 450,
buttons : my_buttons
});
}
And then I click on button with classes .b-icon.b-icon_del it seems like executing both deleteDocument(window.lastSelectedRowId) and showConfirmDialog('Are you sure you want to delete this document?',deleteDocument(window.lastSelectedRowId), 'Delete document'); at the moment. I just want that callback function (which is
deleteDocument(window.lastSelectedRowId)) invoke after user clicks “OK” button. Thanks!
Alternatively, wrap
deleteDocument(window.lastSelectedRowId)in a function to prevent it from being evaluated prematurely at the call to$('.b-icon.b-icon_del').click().i.e.