Remove obsolete loading animation
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / EditAlbumPage.kt
1 package net.pterodactylus.sone.web
2
3 import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
4 import net.pterodactylus.sone.utils.isPOST
5 import net.pterodactylus.sone.web.page.FreenetRequest
6 import net.pterodactylus.util.template.Template
7 import net.pterodactylus.util.template.TemplateContext
8
9 /**
10  * Page that lets the user edit the name and description of an album.
11  */
12 class EditAlbumPage(template: Template, webInterface: WebInterface):
13                 SoneTemplatePage("editAlbum.html", template, "Page.EditAlbum.Title", webInterface, true) {
14
15         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
16                 if (request.isPOST) {
17                         val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html")
18                         album.takeUnless { it.sone.isLocal }?.run { throw RedirectException("noPermission.html") }
19                         if (request.httpRequest.getPartAsStringFailsafe("moveLeft", 4) == "true") {
20                                 album.parent?.moveAlbumUp(album)
21                                 webInterface.core.touchConfiguration()
22                                 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
23                         } else if (request.httpRequest.getPartAsStringFailsafe("moveRight", 4) == "true") {
24                                 album.parent?.moveAlbumDown(album)
25                                 webInterface.core.touchConfiguration()
26                                 throw RedirectException("imageBrowser.html?album=${album.parent?.id}")
27                         } else {
28                                 try {
29                                         album.modify()
30                                                         .setTitle(request.httpRequest.getPartAsStringFailsafe("title", 100))
31                                                         .setDescription(request.httpRequest.getPartAsStringFailsafe("description", 1000))
32                                                         .update()
33                                 } catch (e: AlbumTitleMustNotBeEmpty) {
34                                         throw RedirectException("emptyAlbumTitle.html")
35                                 }
36                                 webInterface.core.touchConfiguration()
37                                 throw RedirectException("imageBrowser.html?album=${album.id}")
38                         }
39                 }
40         }
41
42 }