org.hyperscala.ui.PageChangeWarning.scala Maven / Gradle / Ivy
package org.hyperscala.ui
import org.hyperscala.module._
import org.hyperscala.web.{Website, Webpage}
import org.powerscala.Version
import org.hyperscala.html._
import org.hyperscala.javascript.JavaScriptString
import org.hyperscala.realtime.Realtime
import com.outr.net.http.session.Session
/**
* @author Matt Hicks
*/
object PageChangeWarning extends Module {
def name = "pagechangewarning"
def version = Version(1)
override def dependencies = List(Realtime)
override def init[S <: Session](website: Website[S]) = {
website.register("/js/page_change_warning.js", "page_change_warning.js")
}
override def load[S <: Session](webpage: Webpage[S]) = {
webpage.head.contents += new tag.Script(src = "/js/page_change_warning.js")
}
def warn[S <: Session](webpage: Webpage[S], message: String) = {
val m = message match {
case null => "null"
case _ => "'%s'".format(message)
}
webpage.body.contents += new tag.Script {
contents += new JavaScriptString("setPageChangeWarning(%s);".format(m))
}
}
}