02ccdce5edb8307237845c5f62dca59ba78bf645
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / web / pages / RescuePage.kt
1 package net.pterodactylus.sone.web.pages
2
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.main.*
5 import net.pterodactylus.sone.utils.isPOST
6 import net.pterodactylus.sone.utils.parameters
7 import net.pterodactylus.sone.web.WebInterface
8 import net.pterodactylus.sone.web.page.*
9 import net.pterodactylus.util.template.TemplateContext
10 import javax.inject.Inject
11
12 /**
13  * Page that lets the user control the rescue mode for a Sone.
14  */
15 @MenuName("Rescue")
16 @TemplatePath("/templates/rescue.html")
17 class RescuePage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer):
18                 LoggedInPage("rescue.html", "Page.Rescue.Title", webInterface, loaders, templateRenderer) {
19
20         override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) {
21                 val soneRescuer = soneRequest.core.getSoneRescuer(currentSone)
22                 templateContext["soneRescuer"] = soneRescuer
23                 if (soneRequest.isPOST) {
24                         soneRequest.parameters["edition", 9]?.toIntOrNull()?.also {
25                                 if (it > -1) {
26                                         soneRescuer.setEdition(it.toLong())
27                                 }
28                         }
29                         if (soneRequest.parameters["fetch", 8] == "true") {
30                                 soneRescuer.startNextFetch()
31                         }
32                         throw RedirectException("rescue.html")
33                 }
34         }
35
36 }