Implement reply deletion.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 20 Oct 2010 05:21:56 +0000 (07:21 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 20 Oct 2010 05:21:56 +0000 (07:21 +0200)
src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/i18n/sone.en.properties
src/main/resources/static/css/sone.css
src/main/resources/templates/deleteReply.html [new file with mode: 0644]

diff --git a/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java
new file mode 100644 (file)
index 0000000..d0a45f1
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Sone - DeleteReplyPage.java - Copyright © 2010 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web;
+
+import net.pterodactylus.sone.data.Reply;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * This page lets the user delete a reply.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class DeleteReplyPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “delete reply” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public DeleteReplyPage(Template template, WebInterface webInterface) {
+               super("deleteReply.html", template, "Page.DeleteReply.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, Template template) throws RedirectException {
+               super.processTemplate(request, template);
+               String replyId = request.getHttpRequest().getPartAsStringFailsafe("reply", 36);
+               Reply reply = webInterface.core().getReply(replyId);
+               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
+               if (request.getMethod() == Method.POST) {
+                       Sone currentSone = getCurrentSone(request.getToadletContext());
+                       if (!reply.getSone().equals(currentSone)) {
+                               throw new RedirectException("noPermission.html");
+                       }
+                       if (request.getHttpRequest().isPartSet("confirmDelete")) {
+                               webInterface.core().deleteReply(reply);
+                               throw new RedirectException(returnPage);
+                       } else if (request.getHttpRequest().isPartSet("abortDelete")) {
+                               throw new RedirectException(returnPage);
+                       }
+               }
+               template.set("reply", reply);
+               template.set("returnPage", returnPage);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected boolean requiresLogin() {
+               return true;
+       }
+
+}
index 456e103..3d67e2d 100644 (file)
@@ -170,6 +170,7 @@ public class WebInterface extends AbstractService {
                Template unblockSoneTemplate = templateFactory.createTemplate(createReader("/templates/unblockSone.html"));
                Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
                Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
+               Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
                Template followSoneTemplate = templateFactory.createTemplate(createReader("/templates/followSone.html"));
                Template unfollowSoneTemplate = templateFactory.createTemplate(createReader("/templates/unfollowSone.html"));
                Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html"));
@@ -190,6 +191,7 @@ public class WebInterface extends AbstractService {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UnblockSonePage(unblockSoneTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(followSoneTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSonePage(unfollowSoneTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
index 4012134..ed1cbd1 100644 (file)
@@ -126,6 +126,12 @@ Page.DeletePost.Text.PostWillBeGone=Deleting a post will remove it from your Son
 Page.DeletePost.Button.Yes=Yes, delete.
 Page.DeletePost.Button.No=No, do not delete.
 
+Page.DeleteReply.Title=Delete Reply - Sone
+Page.DeleteReply.Page.Title=Delete Reply
+Page.DeleteReply.Text.PostWillBeGone=Deleting a reply will remove it from your Sone. It will not remove it from Freenet because that is not possible. Older versions of your Sone will always include the deleted reply.
+Page.DeleteReply.Button.Yes=Yes, delete.
+Page.DeleteReply.Button.No=No, do not delete.
+
 Page.FollowSone.Title=Follow Sone - Sone
 
 Page.UnfollowSone.Title=Unfollow Sone - Sone
index ea2e782..9fb33a8 100644 (file)
        display: inline;
 }
 
+#sone .post .delete button {
+       font: inherit;
+       border: 0px;
+       background: none;
+       padding: 0px;
+       color: rgb(28, 131, 191);
+}
+
+#sone .post .delete button:hover {
+       font: inherit;
+       border: 0px;
+       background: none;
+       padding: 0px;
+       color: rgb(255, 172, 0);
+       cursor: pointer;
+}
+
 #sone .post .delete:before {
        content: ' ‧ ';
 }
diff --git a/src/main/resources/templates/deleteReply.html b/src/main/resources/templates/deleteReply.html
new file mode 100644 (file)
index 0000000..ed72c7d
--- /dev/null
@@ -0,0 +1,15 @@
+<%include include/head.html>
+
+       <h1><%= Page.DeleteReply.Page.Title|l10n|html></h1>
+
+       <div><%= Page.DeleteReply.Text.PostWillBeGone|l10n|html></div>
+
+       <form method="post">
+               <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+               <input type="hidden" name="returnPage" value="<% returnPage|html>" />
+               <input type="hidden" name="reply" value="<% reply.id|html>" />
+               <button type="submit" name="confirmDelete" value="1"><%= Page.DeleteReply.Button.Yes|l10n|html></button>
+               <button type="submit" name="abortDelete" value="1"><%= Page.DeleteReply.Button.No|l10n|html></button>
+       </form>
+
+<%include include/tail.html>