Replace unlike ajax page with Kotlin version
[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.utils.isPOST
4 import net.pterodactylus.sone.utils.parameters
5 import net.pterodactylus.sone.web.WebInterface
6 import net.pterodactylus.sone.web.page.FreenetRequest
7 import net.pterodactylus.util.template.Template
8 import net.pterodactylus.util.template.TemplateContext
9
10 /**
11  * Page that lets the user control the rescue mode for a Sone.
12  */
13 class RescuePage(template: Template, webInterface: WebInterface):
14                 SoneTemplatePage("rescue.html", template, "Page.Rescue.Title", webInterface, true) {
15
16         override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) {
17                 val soneRescuer = webInterface.core.getSoneRescuer(getCurrentSone(request.toadletContext)!!)
18                 templateContext["soneRescuer"] = soneRescuer
19                 if (request.isPOST) {
20                         request.parameters["edition", 9]?.toIntOrNull()?.also {
21                                 if (it > -1) {
22                                         soneRescuer.setEdition(it.toLong())
23                                 }
24                         }
25                         if (request.parameters["fetch", 8] == "true") {
26                                 soneRescuer.startNextFetch()
27                         }
28                         throw RedirectException("rescue.html")
29                 }
30         }
31
32 }