Move all AJAX handlers to the same directory as the HTML handlers.
[Sone.git] / src / main / java / net / pterodactylus / sone / web / ajax / DeletePostAjaxPage.java
index 16c047d..479e71e 100644 (file)
@@ -36,7 +36,7 @@ public class DeletePostAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public DeletePostAjaxPage(WebInterface webInterface) {
-               super("ajax/deletePost.ajax", webInterface);
+               super("deletePost.ajax", webInterface);
        }
 
        //
@@ -49,9 +49,9 @@ public class DeletePostAjaxPage extends JsonPage {
        @Override
        protected JsonObject createJsonObject(Request request) {
                String postId = request.getHttpRequest().getParam("post");
-               Post post = webInterface.getCore().getPost(postId);
+               Post post = webInterface.getCore().getPost(postId, false);
                Sone currentSone = getCurrentSone(request.getToadletContext());
-               if (post == null) {
+               if ((post == null) || (post.getSone() == null)) {
                        return createErrorJsonObject("invalid-post-id");
                }
                if (currentSone == null) {
@@ -60,8 +60,8 @@ public class DeletePostAjaxPage extends JsonPage {
                if (!post.getSone().equals(currentSone)) {
                        return createErrorJsonObject("not-authorized");
                }
-               currentSone.removePost(post);
-               return new JsonObject().put("success", true);
+               webInterface.getCore().deletePost(post);
+               return createSuccessJsonObject();
        }
 
 }