X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FEditAlbumPage.kt;fp=src%2Fmain%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FEditAlbumPage.kt;h=1e457445d68906497ff7ceb3f4d1a50946f2368c;hb=de7568a82eb4150bf6d2b0553841b7b69f84c968;hp=0000000000000000000000000000000000000000;hpb=9acbc5bdec4ccb752e0856a501568b0bb6161579;p=Sone.git diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt new file mode 100644 index 0000000..1e45744 --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPage.kt @@ -0,0 +1,44 @@ +package net.pterodactylus.sone.web.pages + +import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty +import net.pterodactylus.sone.utils.isPOST +import net.pterodactylus.sone.web.pages.SoneTemplatePage +import net.pterodactylus.sone.web.WebInterface +import net.pterodactylus.sone.web.page.FreenetRequest +import net.pterodactylus.util.template.Template +import net.pterodactylus.util.template.TemplateContext + +/** + * Page that lets the user edit the name and description of an album. + */ +class EditAlbumPage(template: Template, webInterface: WebInterface): + SoneTemplatePage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, true) { + + override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { + if (request.isPOST) { + val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html") + album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") } + if (request.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") { + album.parent?.moveAlbumUp(album) + webInterface.core.touchConfiguration() + throw RedirectException("imageBrowser.html?album=${album.parent?.id}") + } else if (request.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") { + album.parent?.moveAlbumDown(album) + webInterface.core.touchConfiguration() + throw RedirectException("imageBrowser.html?album=${album.parent?.id}") + } else { + try { + album.modify() + .setTitle(request.httpRequest.getPartAsStringFailsafe("title", 100)) + .setDescription(request.httpRequest.getPartAsStringFailsafe("description", 1000)) + .update() + } catch (e: AlbumTitleMustNotBeEmpty) { + throw RedirectException("emptyAlbumTitle.html") + } + webInterface.core.touchConfiguration() + throw RedirectException("imageBrowser.html?album=${album.id}") + } + } + } + +}