🎨 Replace post count comparator with Kotlin version
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / DeleteAlbumPage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.*
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.utils.*
6 import net.pterodactylus.sone.web.*
7 import net.pterodactylus.sone.web.page.*
8 import net.pterodactylus.util.template.*
9 import javax.inject.*
10
11 /**
12  * Page that lets the user delete an {@link Album}.
13  */
14 @TemplatePath("/templates/deleteAlbum.html")
15 @ToadletPath("deleteAlbum.html")
16 class DeleteAlbumPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
17                 LoggedInPage("Page.DeleteAlbum.Title", webInterface, loaders, templateRenderer) {
18
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                         if (!album.sone.isLocal) {
23                                 redirectTo("noPermission.html")
24                         }
25                         if (soneRequest.httpRequest.getPartAsStringFailsafe("abortDelete", 4) == "true") {
26                                 redirectTo("imageBrowser.html?album=${album.id}")
27                         }
28                         soneRequest.core.deleteAlbum(album)
29                         redirectTo(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}")
30                 }
31                 val album = soneRequest.core.getAlbum(soneRequest.httpRequest.getParam("album"))
32                 templateContext["album"] = album ?: redirectTo("invalid.html")
33         }
34
35 }