mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 23:15:49 +01:00
Separate scalatra-forms from gitbucket.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package app
|
||||
|
||||
import util.Directory._
|
||||
import util.Validations._
|
||||
import org.scalatra._
|
||||
import java.io.File
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib._
|
||||
import org.apache.commons.io._
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
/**
|
||||
* Creates new repository.
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package app
|
||||
|
||||
import util.Validations._
|
||||
|
||||
import org.scalatra._
|
||||
import org.scalatra.json._
|
||||
import org.json4s._
|
||||
import org.json4s.jackson._
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
/**
|
||||
* Provides generic features for ScalatraServlet implementations.
|
||||
*/
|
||||
abstract class ServletBase extends ScalatraServlet with JacksonJsonSupport {
|
||||
abstract class ServletBase extends ScalatraServlet with ClientSideValidationFormSupport with JacksonJsonSupport {
|
||||
|
||||
implicit val jsonFormats = DefaultFormats
|
||||
|
||||
@@ -19,31 +18,6 @@ abstract class ServletBase extends ScalatraServlet with JacksonJsonSupport {
|
||||
// TODO get from session
|
||||
val LoginUser = System.getProperty("user.name")
|
||||
|
||||
def get[T](path: String, form: MappingValueType[T])(action: T => Any) = {
|
||||
super.get(path){
|
||||
withValidation(form, params){ obj: T =>
|
||||
action(obj)
|
||||
}
|
||||
}
|
||||
registerValidate(path, form)
|
||||
}
|
||||
|
||||
def post[T](path: String, form: MappingValueType[T])(action: T => Any) = {
|
||||
super.post(path){
|
||||
withValidation(form, params){ obj: T =>
|
||||
action(obj)
|
||||
}
|
||||
}
|
||||
registerValidate(path, form)
|
||||
}
|
||||
|
||||
private def registerValidate[T](path: String, form: MappingValueType[T]) = {
|
||||
super.post(path.replaceFirst("/$", "") + "/validate"){
|
||||
contentType = "application/json"
|
||||
form.validateAsJSON(params)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case class Context(path: String)
|
||||
Reference in New Issue
Block a user