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 class EditAlbumPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
16 LoggedInPage("editAlbum.html", "Page.EditAlbum.Title", webInterface, loaders, templateRenderer) {
18 override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
19 if (soneRequest.isPOST) {
20 val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
21 album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
22 if (soneRequest.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
23 album.parent?.moveAlbumUp(album)
24 soneRequest.core.touchConfiguration()
25 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
26 } else if (soneRequest.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
27 album.parent?.moveAlbumDown(album)
28 soneRequest.core.touchConfiguration()
29 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
33 .setTitle(soneRequest.httpRequest.getPartAsStringFailsafe("title", 100))
34 .setDescription(soneRequest.httpRequest.getPartAsStringFailsafe("description", 1000))
36 } catch (e: AlbumTitleMustNotBeEmpty) {
37 throw RedirectException("emptyAlbumTitle.html")
39 soneRequest.core.touchConfiguration()
40 throw RedirectException("imageBrowser.html?album=${album.id}")