From: David ‘Bombe’ Roden Date: Thu, 21 Oct 2010 11:58:18 +0000 (+0200) Subject: Add JSON page that returns the status of a Sone. X-Git-Tag: 0.1-RC1~121 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a1b2f42d03e3420bfc4a4aa896f5809b79400cd0;p=Sone.git Add JSON page that returns the status of a Sone. --- diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 40da956..9ea4a7a 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -36,6 +36,7 @@ import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.sone.template.PostAccessor; import net.pterodactylus.sone.template.SoneAccessor; import net.pterodactylus.sone.template.SubstringFilter; +import net.pterodactylus.sone.web.ajax.GetSoneStatusPage; import net.pterodactylus.sone.web.ajax.GetTranslationPage; import net.pterodactylus.sone.web.page.PageToadlet; import net.pterodactylus.sone.web.page.PageToadletFactory; @@ -203,6 +204,7 @@ public class WebInterface extends AbstractService { pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript"))); pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png"))); pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this))); + pageToadlets.add(pageToadletFactory.createPageToadlet(new GetSoneStatusPage(core()))); 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/GetSoneStatusPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/GetSoneStatusPage.java new file mode 100644 index 0000000..7a4bfda --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/web/ajax/GetSoneStatusPage.java @@ -0,0 +1,58 @@ +/* + * Sone - GetSoneStatusPage.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.core.Core.SoneStatus; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.util.json.JsonObject; + +/** + * AJAX page that reeturns the status of a sone, as a) a {@link SoneStatus} name + * and b) a “modified” boolean (as per {@link Sone#getModificationCounter()}). + * + * @author David ‘Bombe’ Roden + */ +public class GetSoneStatusPage extends JsonPage { + + /** The Sone core. */ + private final Core core; + + /** + * Creates a new AJAX sone status handler. + * + * @param core + * The Sone core + */ + public GetSoneStatusPage(Core core) { + super("ajax/getSoneStatus.ajax"); + this.core = core; + } + + /** + * {@inheritDoc} + */ + @Override + protected JsonObject createJsonObject(Request request) { + String soneId = request.getHttpRequest().getParam("sone"); + Sone sone = core.getSone(soneId); + SoneStatus soneStatus = core.getSoneStatus(sone); + return new JsonObject().put("status", soneStatus.name()).put("modified", sone.getModificationCounter() > 0); + } + +}