X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FDeleteProfileFieldAjaxPage.java;h=b787e8c7b323dfb015ea1d62e29be7c220933c72;hb=2e03e9dddbea4b81aacaf1aa316f5c3ccffd4bf9;hp=205fb854c72c7af8385f0b6dc4f3f9df961d6618;hpb=38cb6c5ec82298ee351d0eb15ddd8331db273af2;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java index 205fb85..b787e8c 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.java @@ -1,5 +1,5 @@ /* - * Sone - DeleteProfileFieldAjaxPage.java - Copyright © 2011 David Roden + * Sone - DeleteProfileFieldAjaxPage.java - Copyright © 2011–2013 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 @@ -17,12 +17,17 @@ package net.pterodactylus.sone.web.ajax; +import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; + import net.pterodactylus.sone.data.Profile; import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; -import net.pterodactylus.util.json.JsonObject; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; +import com.google.common.base.Optional; /** * AJAX page that lets the user delete a profile field. @@ -41,22 +46,19 @@ public class DeleteProfileFieldAjaxPage extends JsonPage { super("deleteProfileField.ajax", webInterface); } - /** - * {@inheritDoc} - */ @Override - protected JsonObject createJsonObject(FreenetRequest request) { + protected JsonReturnObject createJsonObject(FreenetRequest request) { String fieldId = request.getHttpRequest().getParam("field"); Sone currentSone = getCurrentSone(request.getToadletContext()); Profile profile = currentSone.getProfile(); - Field field = profile.getFieldById(fieldId); - if (field == null) { + Optional field = profile.getFieldById(fieldId); + if (!field.isPresent()) { return createErrorJsonObject("invalid-field-id"); } - profile.removeField(field); + profile.removeField(field.get()); currentSone.setProfile(profile); webInterface.getCore().touchConfiguration(); - return createSuccessJsonObject().put("field", new JsonObject().put("id", field.getId())); + return createSuccessJsonObject().put("field", new ObjectNode(instance).put("id", new TextNode(field.get().getId()))); } }