X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fajax%2FEditProfileFieldAjaxPage.kt;h=7e7581d07bbf0c73e3f6d89da197b200675fe222;hp=72ee0059f1b2527f820efc1d6307f0a29fd43881;hb=393926e1a012b28b05e946d6ac68310b3548f6f3;hpb=bad2f1fc43a86069c26c0b448a5d760d0a2ae737 diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.kt index 72ee005..7e7581d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/ajax/EditProfileFieldAjaxPage.kt @@ -1,17 +1,20 @@ package net.pterodactylus.sone.web.ajax +import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.utils.ifFalse import net.pterodactylus.sone.utils.parameters import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest +import javax.inject.Inject /** * AJAX page that lets the user rename a profile field. */ -class EditProfileFieldAjaxPage(webInterface: WebInterface) : JsonPage("editProfileField.ajax", webInterface) { +class EditProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : + LoggedInJsonPage("editProfileField.ajax", webInterface) { - override fun createJsonObject(request: FreenetRequest) = - getCurrentSone(request.toadletContext).profile.let { profile -> + override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = + currentSone.profile.let { profile -> request.parameters["field"]!! .let(profile::getFieldById) ?.let { field -> @@ -20,7 +23,7 @@ class EditProfileFieldAjaxPage(webInterface: WebInterface) : JsonPage("editProfi try { field.name = newName createSuccessJsonObject().also { - getCurrentSone(request.toadletContext).profile = profile + currentSone.profile = profile } } catch (_: IllegalArgumentException) { createErrorJsonObject("duplicate-field-name")