From: David ‘Bombe’ Roden Date: Wed, 20 Oct 2010 05:21:56 +0000 (+0200) Subject: Implement reply deletion. X-Git-Tag: 0.1-RC1~169 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9a49215476e139cf20ed4b5b85bcdbb4d8d71704;p=Sone.git Implement reply deletion. --- 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 index 0000000..d0a45f1 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/DeleteReplyPage.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 456e103..3d67e2d 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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")); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 4012134..ed1cbd1 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -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 diff --git a/src/main/resources/static/css/sone.css b/src/main/resources/static/css/sone.css index ea2e782..9fb33a8 100644 --- a/src/main/resources/static/css/sone.css +++ b/src/main/resources/static/css/sone.css @@ -101,6 +101,23 @@ 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 index 0000000..ed72c7d --- /dev/null +++ b/src/main/resources/templates/deleteReply.html @@ -0,0 +1,15 @@ +<%include include/head.html> + +

<%= Page.DeleteReply.Page.Title|l10n|html>

+ +
<%= Page.DeleteReply.Text.PostWillBeGone|l10n|html>
+ +
+ + + + + +
+ +<%include include/tail.html>