X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FDeleteProfileFieldAjaxPage.kt;h=6daa4daabc0ab453adae973d0f0d47d88d51c7ac;hp=5e7c901353ca530ccc3be6316304e3e1a3a27f35;hb=ca45de0dcbd2e361ab630bbee1d47ff6cf34d97c;hpb=551c2cc1787db9fbffca982c2c38e706defdc961 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt index 5e7c901..6daa4da 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DeleteProfileFieldAjaxPage.kt @@ -1,27 +1,28 @@ package net.pterodactylus.sone.web.ajax +import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.sone.web.page.* +import javax.inject.Inject /** * AJAX page that lets the user delete a profile field. */ -class DeleteProfileFieldAjaxPage(webInterface: WebInterface) : JsonPage("deleteProfileField.ajax", webInterface) { +@ToadletPath("deleteProfileField.ajax") +class DeleteProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(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") - } + override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = + currentSone.profile.let { profile -> + request.parameters["field"] + ?.let(profile::getFieldById) + ?.let { field -> + createSuccessJsonObject().also { + profile.removeField(field) + currentSone.profile = profile + core.touchConfiguration() + } + } ?: createErrorJsonObject("invalid-field-id") } }