I have a site where there are lots of "jobs" that a user creates. The user has the option to Close any given job. I want a pop up warning dialog whenever the user clicks the Close button, and verify that they actually want to close the job.
There are many ways to do this, and I've implemented it this way (jsfiddle):
function openCloseDialog(item) {
var jobid = $(item).attr("jobid");
var closeLink = $(item).attr("value");
if ($("#closeWarningModal").size() > 0) {
$("#closeWarningModal").dialog({
autoOpen: true,
'modal': true,
title: "Close Job",
draggable: true,
resizable: true,
'buttons': {
'Cancel': function () {
$(this).dialog('close');
},
'Close': function () {
// close
$(this).dialog('close');
},
}
});
} else {
// close
}
}
This seems to be working perfectly fine. The question I have is, is there any reason to NOT do it this way? At first I was curious if this implementation would cause multiple instantiations of the dialog, or if the user clicked the Close button a second time it would fail to open. But neither of those things are happening and it seems to work perfectly.
Can you see or find anything wrong with this code?