X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FDeleteProfileFieldAjaxPage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FDeleteProfileFieldAjaxPage.kt;h=5e7c901353ca530ccc3be6316304e3e1a3a27f35;hb=551c2cc1787db9fbffca982c2c38e706defdc961;hp=0000000000000000000000000000000000000000;hpb=4588d890e2d7eae8f9ca727a4435ad388c172615;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt new file mode 100644 index 0000000..5e7c901 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt @@ -0,0 +1,27 @@ +package net.pterodactylus.sone.web.ajax + +import net.pterodactylus.sone.utils.parameters +import net.pterodactylus.sone.web.WebInterface +import net.pterodactylus.sone.web.page.FreenetRequest + +/** + * AJAX page that lets the user delete a profile field. + */ +class DeleteProfileFieldAjaxPage(webInterface: WebInterface) : JsonPage("deleteProfileField.ajax", webInterface) { + + override fun createJsonObject(request: FreenetRequest) = + getCurrentSone(request.toadletContext)!!.let { currentSone -> + currentSone.profile.let { profile -> + request.parameters["field"] + ?.let(profile::getFieldById) + ?.let { field -> + createSuccessJsonObject().also { + profile.removeField(field) + currentSone.profile = profile + webInterface.core.touchConfiguration() + } + } ?: createErrorJsonObject("invalid-field-id") + } + } + +}