From 47df88512f5288d6a1f5f268cdf787bb4bf169c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 22 Oct 2010 23:39:42 +0200 Subject: [PATCH] =?utf8?q?Make=20=E2=80=9Cfollow=E2=80=9D,=20=E2=80=9Cunfo?= =?utf8?q?llow=E2=80=9D,=20=E2=80=9Cblock=E2=80=9D=20and=20=E2=80=9Cunbloc?= =?utf8?q?k=E2=80=9D=20buttons=20dynamic.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/web/WebInterface.java | 8 +++ .../sone/web/ajax/BlockSoneAjaxPage.java | 58 +++++++++++++++++++++ .../sone/web/ajax/FollowSoneAjaxPage.java | 59 ++++++++++++++++++++++ .../sone/web/ajax/UnblockSoneAjaxPage.java | 58 +++++++++++++++++++++ .../sone/web/ajax/UnfollowSoneAjaxPage.java | 59 ++++++++++++++++++++++ src/main/resources/static/css/sone.css | 4 ++ src/main/resources/static/javascript/sone.js | 19 +++++++ src/main/resources/templates/include/head.html | 38 ++++++++++++++ src/main/resources/templates/include/viewSone.html | 54 +++++++++----------- 9 files changed, 327 insertions(+), 30 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/web/ajax/BlockSoneAjaxPage.java create mode 100644 src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java create mode 100644 src/main/java/net/pterodactylus/sone/web/ajax/UnblockSoneAjaxPage.java create mode 100644 src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 2bdeff5..4294e64 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -38,10 +38,14 @@ import net.pterodactylus.sone.template.PostAccessor; import net.pterodactylus.sone.template.RequestChangeFilter; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.template.SubstringFilter; +import net.pterodactylus.sone.web.ajax.BlockSoneAjaxPage; import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage; import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage; +import net.pterodactylus.sone.web.ajax.FollowSoneAjaxPage; import net.pterodactylus.sone.web.ajax.GetSoneStatusPage; import net.pterodactylus.sone.web.ajax.GetTranslationPage; +import net.pterodactylus.sone.web.ajax.UnblockSoneAjaxPage; +import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage; import net.pterodactylus.sone.web.page.PageToadlet; import net.pterodactylus.sone.web.page.PageToadletFactory; import net.pterodactylus.sone.web.page.StaticPage; @@ -230,6 +234,10 @@ public class WebInterface extends AbstractService { pageToadlets.add(pageToadletFactory.createPageToadlet(new GetSoneStatusPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DeletePostAjaxPage(this))); pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteReplyAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new FollowSoneAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new UnfollowSoneAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new BlockSoneAjaxPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new UnblockSoneAjaxPage(this))); ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer(); toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", sonePlugin); diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/BlockSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/BlockSoneAjaxPage.java new file mode 100644 index 0000000..e4ffe2b --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/BlockSoneAjaxPage.java @@ -0,0 +1,58 @@ +/* + * Sone - BlockSoneAjaxPage.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.data.Sone; +import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.util.json.JsonObject; + +/** + * AJAX page that lets the user block another Sone. + * + * @author David ‘Bombe’ Roden + */ +public class BlockSoneAjaxPage extends JsonPage { + + /** + * Creates a new “block Sone” AJAX page. + * + * @param webInterface + * The Sone web interface + */ + public BlockSoneAjaxPage(WebInterface webInterface) { + super("ajax/blockSone.ajax", webInterface); + } + + /** + * {@inheritDoc} + */ + @Override + protected JsonObject createJsonObject(Request request) { + String soneId = request.getHttpRequest().getParam("sone"); + if (soneId == null) { + return new JsonObject().put("success", false).put("error", "invalid-sone-id"); + } + Sone currentSone = getCurrentSone(request.getToadletContext()); + if (currentSone == null) { + return new JsonObject().put("success", false).put("error", "auth-required"); + } + currentSone.addBlockedSoneId(soneId); + return new JsonObject().put("success", true); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java new file mode 100644 index 0000000..5b4fdc2 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java @@ -0,0 +1,59 @@ +/* + * Sone - FollowSoneAjaxPage.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.data.Sone; +import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.util.json.JsonObject; + +/** + * AJAX page that lets a Sone follow another Sone. + * + * @author David ‘Bombe’ Roden + */ +public class FollowSoneAjaxPage extends JsonPage { + + /** + * Creates a new “follow Sone” AJAX page. + * + * @param webInterface + * The Sone web interface + */ + public FollowSoneAjaxPage(WebInterface webInterface) { + super("ajax/followSone.ajax", webInterface); + } + + /** + * {@inheritDoc} + */ + @Override + protected JsonObject createJsonObject(Request request) { + String soneId = request.getHttpRequest().getParam("sone"); + Sone sone = webInterface.core().getSone(soneId); + if (sone == null) { + return new JsonObject().put("success", false).put("error", "invalid-sone-id"); + } + Sone currentSone = getCurrentSone(request.getToadletContext()); + if (currentSone == null) { + return new JsonObject().put("success", false).put("error", "auth-required"); + } + currentSone.addFriend(sone); + return new JsonObject().put("success", true); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnblockSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnblockSoneAjaxPage.java new file mode 100644 index 0000000..9012aee --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnblockSoneAjaxPage.java @@ -0,0 +1,58 @@ +/* + * Sone - UnblockSoneAjaxPage.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.data.Sone; +import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.util.json.JsonObject; + +/** + * AJAX page that lets the user unblock another Sone. + * + * @author David ‘Bombe’ Roden + */ +public class UnblockSoneAjaxPage extends JsonPage { + + /** + * Creates a new “unblock Sone” AJAX page. + * + * @param webInterface + * The Sone web interface + */ + public UnblockSoneAjaxPage(WebInterface webInterface) { + super("ajax/unblockSone.ajax", webInterface); + } + + /** + * {@inheritDoc} + */ + @Override + protected JsonObject createJsonObject(Request request) { + String soneId = request.getHttpRequest().getParam("sone"); + if (soneId == null) { + return new JsonObject().put("success", false).put("error", "invalid-sone-id"); + } + Sone currentSone = getCurrentSone(request.getToadletContext()); + if (currentSone == null) { + return new JsonObject().put("success", false).put("error", "auth-required"); + } + currentSone.removeBlockedSoneId(soneId); + return new JsonObject().put("success", true); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java new file mode 100644 index 0000000..012b9cf --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java @@ -0,0 +1,59 @@ +/* + * Sone - UnfollowSoneAjaxPage.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.data.Sone; +import net.pterodactylus.sone.web.WebInterface; +import net.pterodactylus.util.json.JsonObject; + +/** + * AJAX page that lets a Sone unfollow another Sone. + * + * @author David ‘Bombe’ Roden + */ +public class UnfollowSoneAjaxPage extends JsonPage { + + /** + * Creates a new “unfollow Sone” AJAX page. + * + * @param webInterface + * The Sone web interface + */ + public UnfollowSoneAjaxPage(WebInterface webInterface) { + super("ajax/unfollowSone.ajax", webInterface); + } + + /** + * {@inheritDoc} + */ + @Override + protected JsonObject createJsonObject(Request request) { + String soneId = request.getHttpRequest().getParam("sone"); + Sone sone = webInterface.core().getSone(soneId); + if (sone == null) { + return new JsonObject().put("success", false).put("error", "invalid-sone-id"); + } + Sone currentSone = getCurrentSone(request.getToadletContext()); + if (currentSone == null) { + return new JsonObject().put("success", false).put("error", "auth-required"); + } + currentSone.removeFriend(sone); + return new JsonObject().put("success", true); + } + +} diff --git a/src/main/resources/static/css/sone.css b/src/main/resources/static/css/sone.css index 503555e..79c91b8 100644 --- a/src/main/resources/static/css/sone.css +++ b/src/main/resources/static/css/sone.css @@ -294,6 +294,10 @@ textarea { bottom: -0.5ex } +#sone .sone form.hidden { + display: none; +} + #sone .sone form.block button, #sone .sone form.unblock button, #sone .sone form.follow button, #sone .sone form.unfollow button { display: inline; color: rgb(28, 131, 191); diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 45a678f..63b8361 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -232,3 +232,22 @@ function enhanceDeleteReplyButton(buttonId, replyId) { }); }); } + +function getFormPassword() { + return $("#sone #formPassword").text(); +} + +function getSoneElement(element) { + return $(element).parent(".sone"); +} + +/** + * Returns the ID of the Sone that this element belongs to. + * + * @param element + * The element to locate the matching Sone ID for + * @returns The ID of the Sone, or undefined + */ +function getSoneId(element) { + return getSoneElement(element).find(".id").text(); +} diff --git a/src/main/resources/templates/include/head.html b/src/main/resources/templates/include/head.html index 9528ecd..ee4278c 100644 --- a/src/main/resources/templates/include/head.html +++ b/src/main/resources/templates/include/head.html @@ -49,6 +49,44 @@ }); + +
diff --git a/src/main/resources/templates/include/viewSone.html b/src/main/resources/templates/include/viewSone.html index b12de4a..f2c51f7 100644 --- a/src/main/resources/templates/include/viewSone.html +++ b/src/main/resources/templates/include/viewSone.html @@ -10,36 +10,30 @@
<% sone.requestUri|substring start=4 length=43|html>
<%ifnull ! currentSone> <%if ! sone.current> - <%if sone.friend> -
- - - - -
- <%else> - - <%/if> - <%if sone.blocked> -
- - - - -
- <%else> -
- - - - -
- <%/if> +
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
<%/if> <%/if>
 
-- 2.7.4