From 68882b660ba80ab62387fbcc3ae3392adf3a3e82 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 25 Oct 2010 07:34:12 +0200 Subject: [PATCH] Add page to let the user edit the options. --- .../net/pterodactylus/sone/web/OptionsPage.java | 72 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 2 + src/main/resources/i18n/sone.en.properties | 9 +++ src/main/resources/templates/options.html | 23 +++++++ 4 files changed, 106 insertions(+) create mode 100644 src/main/java/net/pterodactylus/sone/web/OptionsPage.java create mode 100644 src/main/resources/templates/options.html 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 index 0000000..1a5fa6a --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/OptionsPage.java @@ -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 . + */ + +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 David ‘Bombe’ Roden + */ +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; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index f681ce7..96959da 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -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"))); diff --git a/src/main/resources/i18n/sone.en.properties b/src/main/resources/i18n/sone.en.properties index f093d44..5d74a57 100644 --- a/src/main/resources/i18n/sone.en.properties +++ b/src/main/resources/i18n/sone.en.properties @@ -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 index 0000000..0e8181c --- /dev/null +++ b/src/main/resources/templates/options.html @@ -0,0 +1,23 @@ +<%include include/head.html> + + + +

<%= Page.Options.Page.Title|l10n|html>

+ +

<%= Page.Options.Page.Description|l10n|html>

+ +
+ + +

<%= Page.Options.Option.InsertionDelay.Description|l10n|html>

+

+ +

+ +
+ +<%include include/tail.html> -- 2.7.4