Add page that lets the user edit and delete targets.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 Sep 2011 15:47:48 +0000 (17:47 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 15 Sep 2011 15:47:48 +0000 (17:47 +0200)
src/main/java/net/pterodactylus/wotns/ui/web/EditTargetPage.java [new file with mode: 0644]
src/main/java/net/pterodactylus/wotns/ui/web/WebInterface.java
src/main/resources/templates/manage.html

diff --git a/src/main/java/net/pterodactylus/wotns/ui/web/EditTargetPage.java b/src/main/java/net/pterodactylus/wotns/ui/web/EditTargetPage.java
new file mode 100644 (file)
index 0000000..3ee6715
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * WoTNS - EditTargetPage.java - Copyright © 2011 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.wotns.ui.web;
+
+import java.net.MalformedURLException;
+
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.web.Method;
+import net.pterodactylus.wotns.freenet.wot.OwnIdentity;
+import net.pterodactylus.wotns.freenet.wot.WebOfTrustException;
+import net.pterodactylus.wotns.web.FreenetRequest;
+import freenet.keys.FreenetURI;
+
+/**
+ * TODO
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class EditTargetPage extends BasicPage {
+
+       /**
+        * @param webInterface
+        * @param path
+        * @param template
+        */
+       public EditTargetPage(Template template, WebInterface webInterface) {
+               super(webInterface, "editTarget.html", template);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
+               super.processTemplate(request, templateContext);
+               if (request.getMethod() == Method.POST) {
+                       OwnIdentity ownIdentity = getOwnIdentity(request);
+                       String name = request.getHttpRequest().getPartAsStringFailsafe("name", 64).trim();
+                       String target = request.getHttpRequest().getPartAsStringFailsafe("target", 256).trim();
+                       if ((name.length() == 0) || (target.length() == 0)) {
+                               /* TODO - show error. */
+                               return;
+                       }
+                       try {
+                               new FreenetURI(target);
+                       } catch (MalformedURLException mue1) {
+                               /* TODO - show error. */
+                               return;
+                       }
+                       try {
+                               if (request.getHttpRequest().getPartAsStringFailsafe("edit", 4).equals("true")) {
+                                       System.out.println("edit");
+                                       ownIdentity.setProperty("tns." + name, target);
+                               } else if (request.getHttpRequest().getPartAsStringFailsafe("delete", 4).equals("true")) {
+                                       System.out.println("delete");
+                                       ownIdentity.removeProperty("tns." + name);
+                               }
+                               throw new RedirectException("manage.html?ownIdentity=" + ownIdentity.getId());
+                       } catch (WebOfTrustException wote1) {
+                               /* TODO - show error. */
+                       }
+               }
+       }
+
+}
index c786d94..efcdced 100644 (file)
@@ -103,6 +103,7 @@ public class WebInterface {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new ManagePage(manageTemplate, this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new EnableIdentityPage(new Template(), this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new AddTargetPage(addTargetTemplate, this)));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new EditTargetPage(new Template(), this)));
 
                ToadletContainer toadletContainer = wotNSPlugin.getToadletContainer();
                toadletContainer.getPageMaker().addNavigationCategory("/tns/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", wotNSPlugin);
index b0b2be6..3f50a8c 100644 (file)
@@ -5,11 +5,12 @@
        <%/first>
        <form action="editTarget.html" method="post">
                <input type="hidden" name="formPassword" value="<%formPassword|html>"/>
+               <input type="hidden" name="ownIdentity" value="<%ownIdentity.id|html>"/>
                <input type="hidden" name="name" value="<%target.key|html>"/>
                <%target.key|html>:
                <input type="text" name="target" value="<%target.value|html>"/>
-               <button type="submit" name="edit">Save</button>
-               <button type="submit" name="delete">Delete</button>
+               <button type="submit" name="edit" value="true">Save</button>
+               <button type="submit" name="delete" value="true">Delete</button>
        </form>
 <%/foreach>
 <h2>Add Target</h2>