Add “view post” page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 16 Oct 2010 00:57:14 +0000 (02:57 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 16 Oct 2010 00:57:14 +0000 (02:57 +0200)
src/main/java/net/pterodactylus/sone/web/ViewPostPage.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/templates/viewPost.html [new file with mode: 0644]

diff --git a/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java b/src/main/java/net/pterodactylus/sone/web/ViewPostPage.java
new file mode 100644 (file)
index 0000000..a013198
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Sone - ViewPostPage.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.Post;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * This page lets the user view a post and all its replies.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class ViewPostPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “view post” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public ViewPostPage(Template template, WebInterface webInterface) {
+               super("viewPost.html", template, "Page.ViewPost.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, Template template) throws RedirectException {
+               String postId = request.getHttpRequest().getParam("post");
+               Post post = webInterface.core().getPost(postId);
+               template.set("post", post);
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected boolean requiresLogin() {
+               return true;
+       }
+
+}
index 32bd783..a0a1c3d 100644 (file)
@@ -172,6 +172,9 @@ public class WebInterface extends AbstractService {
                Template viewSoneTemplate = templateFactory.createTemplate(createReader("/templates/viewSone.html"));
                viewSoneTemplate.set("formPassword", formPassword);
 
+               Template viewPostTemplate = templateFactory.createTemplate(createReader("/templates/viewPost.html"));
+               viewPostTemplate.set("formPassword", formPassword);
+
                Template followSoneTemplate = templateFactory.createTemplate(createReader("/templates/followSone.html"));
                followSoneTemplate.set("formPassword", formPassword);
 
@@ -187,6 +190,7 @@ public class WebInterface extends AbstractService {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreatePostPage(createPostTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new CreateReplyPage(createReplyTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewSonePage(viewSoneTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new ViewPostPage(viewPostTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSonePage(followSoneTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
index 1ca46dc..c2404f2 100644 (file)
@@ -82,6 +82,10 @@ Page.ViewSone.FollowSone.Text=Follow this Sone
 Page.ViewSone.Following.Title=This Sone follows
 Page.ViewSone.Following.FollowingNone.Text=Apparently, this Sone does not yet follow any other Sone.
 
+Page.ViewPost.Title=View Post - Sone
+Page.ViewPost.Page.Title=View Post by {sone}
+Page.ViewPost.Button.PostReply=Post Reply!
+
 Page.FollowSone.Title=Follow Sone - Sone
 
 Page.Logout.Title=Logout - Sone
diff --git a/src/main/resources/templates/viewPost.html b/src/main/resources/templates/viewPost.html
new file mode 100644 (file)
index 0000000..237bfce
--- /dev/null
@@ -0,0 +1,26 @@
+<div id="sone">
+
+       <h1><%= Page.ViewPost.Page.Title|l10n|insert needle="{sone}" key=post.sone.niceName|html></h1>
+
+       <div class="post">
+               <div class="author"><a href="viewSone.html?sone=<% post.sone.id>"><% post.sone.niceName|html></a></div>
+               <div class="text"><% post.text|html></div>
+               <div class="time"><% post.time|date format="MMM d, yyyy, HH:mm:ss"></div>
+       </div>
+       <%foreach post.replies reply>
+               <div class="reply">
+                       <div class="author"><a href="viewSone.html?sone=<% reply.sone.id>"><% reply.sone.niceName|html></a></div>
+                       <div class="text"><% reply.text|html></div>
+                       <div class="time"><% reply.time|date format="MMM d, yyyy, HH:mm:ss"></div>
+               </div>
+       <%/foreach>
+       <div class="create-reply">
+               <form method="post" action="createReply.html">
+                       <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+                       <input type="hidden" name="post" value="<% post.id>" />
+                       <input type="text" name="text" value="" />
+                       <button type="submit"><%= Page.ViewPost.Button.PostReply|l10n|html></button>
+               </form>
+       </div>
+
+</div>