Add page to let the user edit the options.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 25 Oct 2010 05:34:12 +0000 (07:34 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 25 Oct 2010 05:34:12 +0000 (07:34 +0200)
src/main/java/net/pterodactylus/sone/web/OptionsPage.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/options.html [new file with mode: 0644]

diff --git a/src/main/java/net/pterodactylus/sone/web/OptionsPage.java b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java
new file mode 100644 (file)
index 0000000..1a5fa6a
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Sone - OptionsPage.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.core.Options;
+import net.pterodactylus.sone.web.page.Page.Request.Method;
+import net.pterodactylus.util.number.Numbers;
+import net.pterodactylus.util.template.Template;
+
+/**
+ * This page lets the user edit the options of the Sone plugin.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class OptionsPage extends SoneTemplatePage {
+
+       /**
+        * Creates a new options page.
+        *
+        * @param template
+        * @param webInterface
+        */
+       public OptionsPage(Template template, WebInterface webInterface) {
+               super("options.html", template, "Page.Options.Title", webInterface);
+       }
+
+       //
+       // TEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(Request request, Template template) throws RedirectException {
+               super.processTemplate(request, template);
+               Options options = webInterface.core().getOptions();
+               if (request.getMethod() == Method.POST) {
+                       Integer insertionDelay = Numbers.safeParseInteger(request.getHttpRequest().getPartAsStringFailsafe("insertion-delay", 16));
+                       options.getIntegerOption("InsertionDelay").set(insertionDelay);
+               }
+               template.set("insertion-delay", options.getIntegerOption("InsertionDelay").get());
+       }
+
+       //
+       // SONETEMPLATEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected boolean requiresLogin() {
+               return false;
+       }
+
+}
index f681ce7..96959da 100644 (file)
@@ -214,6 +214,7 @@ public class WebInterface extends AbstractService {
                Template deleteSoneTemplate = templateFactory.createTemplate(createReader("/templates/deleteSone.html"));
                Template noPermissionTemplate = templateFactory.createTemplate(createReader("/templates/noPermission.html"));
                Template logoutTemplate = templateFactory.createTemplate(createReader("/templates/logout.html"));
+               Template optionsTemplate = templateFactory.createTemplate(createReader("/templates/options.html"));
                Template aboutTemplate = templateFactory.createTemplate(createReader("/templates/about.html"));
 
                PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
@@ -239,6 +240,7 @@ public class WebInterface extends AbstractService {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(logoutTemplate, this), "Logout"));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new OptionsPage(optionsTemplate, this), "Options"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("about.html", aboutTemplate, "Page.About.Title", this), "About"));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new SoneTemplatePage("noPermission.html", noPermissionTemplate, "Page.NoPermission.Title", this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
index f093d44..5d74a57 100644 (file)
@@ -14,12 +14,20 @@ Navigation.Menu.Item.DeleteSone.Name=Delete Sone
 Navigation.Menu.Item.DeleteSone.Tooltip=Deletes the current Sone
 Navigation.Menu.Item.Logout.Name=Logout
 Navigation.Menu.Item.Logout.Tooltip=Logs you out of the current Sone
+Navigation.Menu.Item.Options.Name=Options
+Navigation.Menu.Item.Options.Tooltip=Options for the Sone plugin
 Navigation.Menu.Item.About.Name=About
 Navigation.Menu.Item.About.Tooltip=Information about Sone
 
 Page.About.Title=About - Sone
 Page.About.Page.Title=About
 
+Page.Options.Title=Options - Sone
+Page.Options.Page.Title=Options
+Page.Options.Page.Description=These options influence the runtime behaviour of the Sone plugin.
+Page.Options.Option.InsertionDelay.Description=The number of seconds the Sone inserter waits after a modification of a Sone before it is being inserted.
+Page.Options.Button.Save=Save
+
 Page.Login.Title=Login - Sone
 Page.Login.Page.Title=Login
 Page.Login.Label.SelectSone=Select Sone:
@@ -185,5 +193,6 @@ WebInterface.DefaultText.LastName=Last name
 WebInterface.DefaultText.BirthDay=Day
 WebInterface.DefaultText.BirthMonth=Month
 WebInterface.DefaultText.BirthYear=Year
+WebInterface.DefaultText.Option.InsertionDelay=Time to wait after a Sone is modified before insert (in seconds)
 WebInterface.Confirmation.DeletePostButton=Yes, delete!
 WebInterface.Confirmation.DeleteReplyButton=Yes, delete!
diff --git a/src/main/resources/templates/options.html b/src/main/resources/templates/options.html
new file mode 100644 (file)
index 0000000..0e8181c
--- /dev/null
@@ -0,0 +1,23 @@
+<%include include/head.html>
+
+       <script language="javascript">
+               $(document).ready(function() {
+                       registerInputTextareaSwap("#sone #options input[name=insertion-delay]", "WebInterface.DefaultText.Option.InsertionDelay", "insertion-delay", true, true);
+               });
+       </script>
+
+       <h1><%= Page.Options.Page.Title|l10n|html></h1>
+
+       <p><%= Page.Options.Page.Description|l10n|html></p>
+
+       <form id="options" method="post">
+               <input type="hidden" name="formPassword" value="<% formPassword|html>" />
+
+               <p><%= Page.Options.Option.InsertionDelay.Description|l10n|html></p>
+               <p><input type="text" name="insertion-delay" value="<% insertion-delay|html>" /></p>
+
+               <p><button type="submit"><%= Page.Options.Button.Save|l10n|html></button></p>
+
+       </form>
+
+<%include include/tail.html>