1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.data.Album.Modifier.*
5 import net.pterodactylus.sone.main.*
6 import net.pterodactylus.sone.utils.*
7 import net.pterodactylus.sone.web.*
8 import net.pterodactylus.sone.web.page.*
9 import net.pterodactylus.util.template.*
13 * Page that lets the user edit the name and description of an album.
15 @ToadletPath("editAlbum.html")
16 class EditAlbumPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
17 LoggedInPage("Page.EditAlbum.Title", webInterface, loaders, templateRenderer) {
19 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
20 if (soneRequest.isPOST) {
21 val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: redirectTo("invalid.html")
22 album.takeUnless { it.sone.isLocal }?.run { redirectTo("noPermission.html") }
23 if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
24 album.parent?.moveAlbumUp(album)
25 soneRequest.core.touchConfiguration()
26 redirectTo("imageBrowser.html?album=${album.parent?.id}")
27 } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
28 album.parent?.moveAlbumDown(album)
29 soneRequest.core.touchConfiguration()
30 redirectTo("imageBrowser.html?album=${album.parent?.id}")
34 .setTitle(soneRequest.httpRequest.getPartAsStringFailsafe("title", 100))
35 .setDescription(soneRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
37 } catch (e: AlbumTitleMustNotBeEmpty) {
38 redirectTo("emptyAlbumTitle.html")
40 soneRequest.core.touchConfiguration()
41 redirectTo("imageBrowser.html?album=${album.id}")