forked from atutor/ATutor
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ajax_demo: Added jquery dialog boxes for displaying messages
- Loading branch information
Showing
1 changed file
with
60 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,7 @@ ATutor.fileStorage = ATutor.fileStorage || {}; | |
|
||
//Function to be called on clicking Delete for a comment | ||
fileStorage.deleteComment = function (ot, oid, file_id, id) { | ||
//Asks for confirmation from user, returns if user cancels | ||
if (!confirm (deleteMessage)) { | ||
return; | ||
} | ||
|
||
|
||
//Sets POST variables to be sent | ||
var parameters = { | ||
"ot" : ot, | ||
|
@@ -31,26 +27,74 @@ ATutor.fileStorage = ATutor.fileStorage || {}; | |
"submit_yes": true | ||
}; | ||
|
||
//AJAX Request sent to required URL | ||
$.ajax({ | ||
type: "POST", | ||
url: deleteUrl, | ||
data: parameters, | ||
success: function(message) { | ||
commentOnDelete(message, parameters); | ||
} | ||
|
||
var buttonOptions = { | ||
"Yes": function (){ | ||
$.ajax({ | ||
type: "POST", | ||
url: deleteUrl, | ||
data: parameters, | ||
success: function(message) { | ||
commentOnDelete(message, parameters); | ||
} | ||
}); | ||
$(this).dialog("close"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}, | ||
"No" : function () { | ||
$(this).dialog("close"); | ||
} | ||
}; | ||
|
||
// Create dialog for the page if it doesn't exist | ||
if ($("#comment-delete-dialog").length === 0){ | ||
$("body").append("<div title='" + deleteTitle + "' id='comment-delete-dialog'>" + | ||
deleteMessage +"</div>"); | ||
} | ||
|
||
$("#comment-delete-dialog").dialog({ | ||
autoOpen: true, | ||
width: 400, | ||
modal: true, | ||
closeOnEscape: false, | ||
buttons: buttonOptions | ||
}); | ||
|
||
}; | ||
|
||
//Callback function for AJAX Request | ||
var commentOnDelete = function (responseMessage, parameters) { | ||
var ajaxResponse = "Ajax Response", | ||
accessDeniedMessage = "Access Denied", | ||
unknownErrorMessage = "Unknown Error Occurred"; | ||
|
||
// Create dialog for the page if it doesn't exist | ||
if ($("#ajax-response-dialog").length === 0){ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
$("body").append("<div title='" + ajaxResponse + "' id='ajax-response-dialog'></div>"); | ||
} | ||
|
||
if (responseMessage === "ACTION_COMPLETED_SUCCESSFULLY") { | ||
$("#comment" + parameters.id).fadeOut(); | ||
return; | ||
} else if (responseMessage === "ACCESS_DENIED") { | ||
alert ("Access denied"); | ||
$("#ajax-response-dialog").html(accessDeniedMessage); | ||
This comment has been minimized.
Sorry, something went wrong.
anvk
|
||
} else { | ||
alert ("Action not completed. Unknown Error Occurred."); | ||
$("#ajax-response-dialog").html(unknownErrorMessage); | ||
} | ||
|
||
//Set an Ok button for the dialog box to be shown in case the comment was not deleted | ||
var buttonOptions = { | ||
"Ok" : function () { | ||
$(this).dialog("close"); | ||
} | ||
}; | ||
|
||
$("#ajax-response-dialog").dialog({ | ||
autoOpen: true, | ||
width: 400, | ||
modal: true, | ||
closeOnEscape: false, | ||
buttons: buttonOptions | ||
}); | ||
}; | ||
|
||
})(ATutor.fileStorage); |
Ok here is a major issue with the code. Whenever I will see "this" in your code most likely I will be VERY grumpy.
Please Google online about common pitfalls with keyword "this". It is a huge pitfall in the world of webdev.
Here is a good link to look at for starters http://stackoverflow.com/questions/3127429/javascript-this-keyword
Your code here is the case #3. You will execute close() on the window object !!