diff --git a/assets/js/components/posts/interface.js b/assets/js/components/posts/interface.js index 1b3f4152..57dbb08b 100644 --- a/assets/js/components/posts/interface.js +++ b/assets/js/components/posts/interface.js @@ -68,4 +68,23 @@ ComunicWeb.components.posts.interface = { }, + /** + * Delete a post + * + * @param {int} postID The ID of the post to delete + * @param {function} callback What to do once we got a reponse + */ + delete: function(postID, callback){ + + //Prepare an API request + apiURI = "posts/delete"; + params = { + postID: postID + }; + + //Perform the request + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + + } + } \ No newline at end of file diff --git a/assets/js/components/posts/ui.js b/assets/js/components/posts/ui.js index c9daaf76..de480790 100644 --- a/assets/js/components/posts/ui.js +++ b/assets/js/components/posts/ui.js @@ -183,6 +183,27 @@ ComunicWeb.components.posts.ui = { innerHTML: "" }); + //Make delete button lives + deleteButtonLink.onclick = function(){ + + //Create a confirmation dialog + ComunicWeb.common.messages.confirm("Are you sure do you want to delete this post? The operation can not be reverted !", function(accept){ + + //Check if the user cancelled the operation + if(!accept) + return; + + postRoot.style.visibility = "hidden"; + + //Delete the post + ComunicWeb.components.posts.interface.delete(infos.ID, function(response){ + + postRoot.style.visibility = "visible"; + + }); + }); + + } } //Add post attachement (if any)