Add functions to lock and unlock a Sone.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Nov 2010 14:35:13 +0000 (15:35 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 17 Nov 2010 14:35:13 +0000 (15:35 +0100)
src/main/java/net/pterodactylus/sone/web/LockSonePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java [new file with mode: 0644]
src/main/resources/i18n/sone.en.properties
src/main/resources/static/css/sone.css
src/main/resources/templates/include/head.html
src/main/resources/templates/include/viewSone.html

diff --git a/src/main/java/net/pterodactylus/sone/web/LockSonePage.java b/src/main/java/net/pterodactylus/sone/web/LockSonePage.java
new file mode 100644 (file)
index 0000000..767e89c
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Sone - LockSonePage.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.Sone;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * This page lets the user lock a {@link Sone} to prevent it from being
+ * inserted.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class LockSonePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “lock Sone” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public LockSonePage(Template template, WebInterface webInterface) {
+               super("lockSone.html", template, "Page.LockSone.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, Template template) throws RedirectException {
+               super.processTemplate(request, template);
+               String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
+               Sone sone = webInterface.getCore().getLocalSone(soneId, false);
+               if (sone != null) {
+                       webInterface.getCore().lockSone(sone);
+               }
+               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
+               throw new RedirectException(returnPage);
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java b/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java
new file mode 100644 (file)
index 0000000..fe5c894
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Sone - LockSonePage.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.Sone;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * This page lets the user unlock a {@link Sone} to allow its insertion.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class UnlockSonePage extends SoneTemplatePage {
+
+       /**
+        * Creates a new “unlock Sone” page.
+        *
+        * @param template
+        *            The template to render
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public UnlockSonePage(Template template, WebInterface webInterface) {
+               super("unlockSone.html", template, "Page.UnlockSone.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, Template template) throws RedirectException {
+               super.processTemplate(request, template);
+               String soneId = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
+               Sone sone = webInterface.getCore().getLocalSone(soneId, false);
+               if (sone != null) {
+                       webInterface.getCore().unlockSone(sone);
+               }
+               String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 64);
+               throw new RedirectException(returnPage);
+       }
+
+}
index f68fec2..e16ca9d 100644 (file)
@@ -61,8 +61,10 @@ import net.pterodactylus.sone.web.ajax.GetReplyAjaxPage;
 import net.pterodactylus.sone.web.ajax.GetSoneStatusPage;
 import net.pterodactylus.sone.web.ajax.GetTranslationPage;
 import net.pterodactylus.sone.web.ajax.LikeAjaxPage;
+import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage;
 import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage;
+import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage;
 import net.pterodactylus.sone.web.page.PageToadlet;
 import net.pterodactylus.sone.web.page.PageToadletFactory;
 import net.pterodactylus.sone.web.page.StaticPage;
@@ -285,6 +287,8 @@ public class WebInterface implements CoreListener {
                Template unlikePostTemplate = templateFactory.createTemplate(createReader("/templates/unlike.html"));
                Template deletePostTemplate = templateFactory.createTemplate(createReader("/templates/deletePost.html"));
                Template deleteReplyTemplate = templateFactory.createTemplate(createReader("/templates/deleteReply.html"));
+               Template lockSoneTemplate = templateFactory.createTemplate(createReader("/templates/lockSone.html"));
+               Template unlockSoneTemplate = templateFactory.createTemplate(createReader("/templates/unlockSone.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"));
@@ -308,6 +312,8 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlikePage(unlikePostTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostPage(deletePostTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyPage(deleteReplyTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSonePage(lockSoneTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSonePage(unlockSoneTemplate, 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"));
@@ -328,6 +334,8 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetReplyAjaxPage(this, replyTemplate)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new LockSoneAjaxPage(this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new UnlockSoneAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new LikeAjaxPage(this)));
diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java
new file mode 100644 (file)
index 0000000..d1a21d3
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Sone - LockSoneAjaxPage.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.ajax;
+
+import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.util.json.JsonObject;
+
+/**
+ * Lets the user {@link Core#lockSone(Sone) lock} a {@link Sone}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class LockSoneAjaxPage extends JsonPage {
+
+       /**
+        * Creates a new “lock Sone” AJAX handler.
+        *
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public LockSoneAjaxPage(WebInterface webInterface) {
+               super("ajax/lockSone.ajax", webInterface);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected JsonObject createJsonObject(Request request) {
+               String soneId = request.getHttpRequest().getParam("sone");
+               Sone sone = webInterface.getCore().getLocalSone(soneId, false);
+               if (sone == null) {
+                       return createErrorJsonObject("invalid-sone-id");
+               }
+               webInterface.getCore().lockSone(sone);
+               return createSuccessJsonObject();
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java
new file mode 100644 (file)
index 0000000..5ea3aa9
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Sone - LockSoneAjaxPage.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.ajax;
+
+import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.web.WebInterface;
+import net.pterodactylus.util.json.JsonObject;
+
+/**
+ * Lets the user {@link Core#unlockSone(Sone) unlock} a {@link Sone}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class UnlockSoneAjaxPage extends JsonPage {
+
+       /**
+        * Creates a new “unlock Sone” AJAX handler.
+        *
+        * @param webInterface
+        *            The Sone web interface
+        */
+       public UnlockSoneAjaxPage(WebInterface webInterface) {
+               super("ajax/unlockSone.ajax", webInterface);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected JsonObject createJsonObject(Request request) {
+               String soneId = request.getHttpRequest().getParam("sone");
+               Sone sone = webInterface.getCore().getLocalSone(soneId, false);
+               if (sone == null) {
+                       return createErrorJsonObject("invalid-sone-id");
+               }
+               webInterface.getCore().unlockSone(sone);
+               return createSuccessJsonObject();
+       }
+
+}
index 9cfe916..37ed1d4 100644 (file)
@@ -136,6 +136,10 @@ Page.DeleteReply.Text.PostWillBeGone=Deleting a reply will remove it from your S
 Page.DeleteReply.Button.Yes=Yes, delete.
 Page.DeleteReply.Button.No=No, do not delete.
 
+Page.LockSone.Title=Lock Sone - Sone
+
+Page.UnlockSone.Title=Unlock Sone - Sone
+
 Page.FollowSone.Title=Follow Sone - Sone
 
 Page.UnfollowSone.Title=Unfollow Sone - Sone
@@ -163,6 +167,8 @@ View.CreateSone.Button.Create=Create Sone
 View.CreateSone.Text.Error.NoIdentity=You have not selected an identity.
 
 View.Sone.Label.LastUpdate=Last update:
+View.Sone.Button.UnlockSone=unlock
+View.Sone.Button.LockSone=lock
 View.Sone.Button.UnfollowSone=unfollow
 View.Sone.Button.FollowSone=follow
 View.Sone.Status.Modified=This Sone was modified and waits to be inserted.
index 4ed5801..3d7d50a 100644 (file)
@@ -372,7 +372,7 @@ textarea {
        font-weight: bold;
 }
 
-#sone .sone form {
+#sone .sone form.follow, #sone .sone form.unfollow, #sone .sone form.lock, #sone .sone form.unlock {
        display: inline;
        border: solid 1px #ccc;
        border-left: none;
@@ -383,11 +383,7 @@ textarea {
        bottom: -0.5ex
 }
 
-#sone .sone form.hidden {
-       display: none;
-}
-
-#sone .sone form.follow button, #sone .sone form.unfollow button {
+#sone .sone form.follow button, #sone .sone form.unfollow button, #sone .sone form.lock button, #sone .sone form.unlock button {
        display: inline;
        color: rgb(28, 131, 191);
        background: none;
@@ -396,11 +392,19 @@ textarea {
        padding: 0px;
 }
 
-#sone .sone form.follow button:hover, #sone .sone form.unfollow button:hover {
+#sone .sone form.follow button:hover, #sone .sone form.unfollow button:hover, #sone .sone form.lock button:hover, #sone .sone form.unlock button:hover {
        display: inline;
        color: rgb(255, 172, 0);
 }
 
+#sone .sone.locked form.lock, #sone .sone.unlocked form.unlock {
+       display: none;
+}
+
+#sone .sone form.hidden {
+       display: none;
+}
+
 #sone .sone .spacer {
        display: inline;
 }
index 7b6cc28..0f46054 100644 (file)
        </script>
 
        <script language="javascript">
-               /* convert all “follow”, “unfollow”, “block”, and “unblock” links to something nicer. */
+               /* convert all “follow”, “unfollow”, “lock”, and “unlock” links to something nicer. */
                $(document).ready(function() {
                        $("#sone .follow").submit(function() {
                                var followElement = this;
                                });
                                return false;
                        });
+                       $("#sone .lock").submit(function() {
+                               var lockElement = this;
+                               $.getJSON("ajax/lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
+                                       $(lockElement).addClass("hidden");
+                                       $(lockElement).parent().find(".unlock").removeClass("hidden");
+                               });
+                               return false;
+                       });
+                       $("#sone .unlock").submit(function() {
+                               var unlockElement = this;
+                               $.getJSON("ajax/unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
+                                       $(unlockElement).addClass("hidden");
+                                       $(unlockElement).parent().find(".lock").removeClass("hidden");
+                               });
+                               return false;
+                       });
                });
        </script>
 
index 453a093..82c0861 100644 (file)
@@ -9,6 +9,20 @@
        <div class="profile-link"><a href="viewSone.html?sone=<% sone.id|html>" title="<% sone.requestUri|html>"><% sone.niceName|html></a></div>
        <div class="short-request-uri"><% sone.requestUri|substring start=4 length=43|html></div>
        <div class="hidden"><% sone.blacklisted></div>
+       <%if sone.local>
+               <form class="lock<%if sone.locked> hidden<%/if>" action="lockSone.html" method="post">
+                       <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+                       <input type="hidden" name="sone" value="<% sone.id|html>" />
+                       <input type="hidden" name="returnPage" value="<% request.uri|html>" />
+                       <button type="submit"><%= View.Sone.Button.LockSone|l10n|html></button>
+               </form>
+               <form class="unlock<%if !sone.locked> hidden<%/if>" action="unlockSone.html" method="post">
+                       <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+                       <input type="hidden" name="sone" value="<% sone.id|html>" />
+                       <input type="hidden" name="returnPage" value="<% request.uri|html>" />
+                       <button type="submit"><%= View.Sone.Button.UnlockSone|l10n|html></button>
+               </form>
+       <%/if>
        <%if ! sone.current>
                <%ifnull ! currentSone>
                        <form class="unfollow<%if ! sone.friend> hidden<%/if>" action="unfollowSone.html" method="post">