diff --git a/assets/js/components/comments/interface.js b/assets/js/components/comments/interface.js index 84b3cc59..9ebe23bd 100644 --- a/assets/js/components/comments/interface.js +++ b/assets/js/components/comments/interface.js @@ -6,4 +6,23 @@ ComunicWeb.components.comments.interface = { + /** + * Delete a comment + * + * @param {number} commentID The ID of the comment to delete + * @param {function} callback What to do once the comment has been delete + */ + delete: function(commentID, callback){ + + //Perform a request on the API + var apiURI = "comments/delete"; + var params = { + commentID: commentID + }; + + //Make the request + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + + } + }; \ No newline at end of file diff --git a/assets/js/components/comments/ui.js b/assets/js/components/comments/ui.js index 9e635979..dfd15cbc 100644 --- a/assets/js/components/comments/ui.js +++ b/assets/js/components/comments/ui.js @@ -126,6 +126,35 @@ ComunicWeb.components.comments.ui = { class: "fa fa-trash" }); + //Make button lives + deleteCommentLink.onclick = function(){ + + ComunicWeb.common.messages.confirm("Are you sure do you want to delete this comment ? This operation is unrecoverable!", function(response){ + + //Check if user cancelled the operation + if(!response) + return; + + //Hide the comment + commentContener.style.visibility = "hidden"; + + //Delete the comment + ComunicWeb.components.comments.interface.delete(infos.ID, function(response){ + + commentContener.style.visibility = "visible"; + + //Check for errors + if(response.error){ + ComunicWeb.common.notificationSystem.showNotification("Could not delete comment!", "danger"); + return; + } + + + }); + + }); + + } } //Add comment content