1 package net.pterodactylus.sone.web.ajax
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.utils.parameters
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.*
7 import javax.inject.Inject
10 * AJAX page that lets the user delete a profile field.
12 @ToadletPath("deleteProfileField.ajax")
13 class DeleteProfileFieldAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) {
15 override fun createJsonObject(currentSone: Sone, request: FreenetRequest) =
16 currentSone.profile.let { profile ->
17 request.parameters["field"]
18 ?.let(profile::getFieldById)
20 createSuccessJsonObject().also {
21 profile.removeField(field)
22 currentSone.profile = profile
23 core.touchConfiguration()
25 } ?: createErrorJsonObject("invalid-field-id")