From c93070476a62e3db94f175576e3cdabf49db1086 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 17 Nov 2010 15:35:13 +0100 Subject: [PATCH] Add functions to lock and unlock a Sone. --- .../net/pterodactylus/sone/web/LockSonePage.java | 62 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/UnlockSonePage.java | 61 +++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 8 +++ .../sone/web/ajax/LockSoneAjaxPage.java | 56 +++++++++++++++++++ .../sone/web/ajax/UnlockSoneAjaxPage.java | 56 +++++++++++++++++++ src/main/resources/i18n/sone.en.properties | 6 +++ src/main/resources/static/css/sone.css | 18 ++++--- src/main/resources/templates/include/head.html | 18 ++++++- src/main/resources/templates/include/viewSone.html | 14 +++++ 9 files changed, 291 insertions(+), 8 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/web/LockSonePage.java create mode 100644 src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java create mode 100644 src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java create mode 100644 src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java 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 index 0000000..767e89c --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/LockSonePage.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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 index 0000000..fe5c894 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/UnlockSonePage.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index f68fec2..e16ca9d 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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 index 0000000..d1a21d3 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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 index 0000000..5ea3aa9 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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(); + } + +} diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index 9cfe916..37ed1d4 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -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. diff --git a/src/main/resources/static/css/sone.css b/src/main/resources/static/css/sone.css index 4ed5801..3d7d50a 100644 --- a/src/main/resources/static/css/sone.css +++ b/src/main/resources/static/css/sone.css @@ -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; } diff --git a/src/main/resources/templates/include/head.html b/src/main/resources/templates/include/head.html index 7b6cc28..0f46054 100644 --- a/src/main/resources/templates/include/head.html +++ b/src/main/resources/templates/include/head.html @@ -128,7 +128,7 @@ diff --git a/src/main/resources/templates/include/viewSone.html b/src/main/resources/templates/include/viewSone.html index 453a093..82c0861 100644 --- a/src/main/resources/templates/include/viewSone.html +++ b/src/main/resources/templates/include/viewSone.html @@ -9,6 +9,20 @@
<% sone.requestUri|substring start=4 length=43|html>
+ <%if sone.local> +
+ + + + +
+
+ + + + +
+ <%/if> <%if ! sone.current> <%ifnull ! currentSone>
-- 2.7.4