mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 15:05:50 +01:00
Fix Ajax processing.
This commit is contained in:
@@ -27,8 +27,50 @@ abstract class ControllerBase extends ScalatraFilter
|
||||
}
|
||||
}
|
||||
|
||||
protected def NotFound() = html.error("Not Found")
|
||||
protected def Unauthorized() = redirect("/")
|
||||
def ajaxGet(path : String)(action : => Any) : Route = {
|
||||
super.get(path){
|
||||
request.setAttribute("AJAX", "true")
|
||||
action
|
||||
}
|
||||
}
|
||||
|
||||
override def ajaxGet[T](path : String, form : MappingValueType[T])(action : T => Any) : Route = {
|
||||
super.ajaxGet(path, form){ form =>
|
||||
request.setAttribute("AJAX", "true")
|
||||
action(form)
|
||||
}
|
||||
}
|
||||
|
||||
def ajaxPost(path : String)(action : => Any) : Route = {
|
||||
super.post(path){
|
||||
request.setAttribute("AJAX", "true")
|
||||
action
|
||||
}
|
||||
}
|
||||
|
||||
override def ajaxPost[T](path : String, form : MappingValueType[T])(action : T => Any) : Route = {
|
||||
super.ajaxPost(path, form){ form =>
|
||||
request.setAttribute("AJAX", "true")
|
||||
action(form)
|
||||
}
|
||||
}
|
||||
|
||||
protected def NotFound() = {
|
||||
if(request.getAttribute("AJAX") == null){
|
||||
org.scalatra.NotFound(html.error("Not Found"))
|
||||
} else {
|
||||
org.scalatra.NotFound()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO redirect to the sign-in page if not logged in?
|
||||
protected def Unauthorized() = {
|
||||
if(request.getAttribute("AJAX") == null){
|
||||
org.scalatra.Unauthorized(redirect("/"))
|
||||
} else {
|
||||
org.scalatra.Unauthorized()
|
||||
}
|
||||
}
|
||||
|
||||
protected def baseUrl = {
|
||||
val url = request.getRequestURL.toString
|
||||
|
||||
@@ -32,7 +32,7 @@ trait LabelsControllerBase extends ControllerBase {
|
||||
redirect("/%s/%s/issues".format(owner, repository))
|
||||
})
|
||||
|
||||
get("/:owner/:repository/issues/label/edit")(writableRepository {
|
||||
ajaxGet("/:owner/:repository/issues/label/edit")(writableRepository {
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
|
||||
@@ -40,7 +40,7 @@ trait LabelsControllerBase extends ControllerBase {
|
||||
.map(issues.html.labeleditlist(getLabels(owner, repository), _)) getOrElse NotFound()
|
||||
})
|
||||
|
||||
get("/:owner/:repository/issues/label/:labelId/edit")(writableRepository {
|
||||
ajaxGet("/:owner/:repository/issues/label/:labelId/edit")(writableRepository {
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
val labelId = params("labelId").toInt
|
||||
@@ -50,7 +50,7 @@ trait LabelsControllerBase extends ControllerBase {
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issues/label/:labelId/edit", editForm)(writableRepository { form =>
|
||||
ajaxPost("/:owner/:repository/issues/label/:labelId/edit", editForm)(writableRepository { form =>
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
val labelId = params("labelId").toInt
|
||||
@@ -61,7 +61,7 @@ trait LabelsControllerBase extends ControllerBase {
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
get("/:owner/:repository/issues/label/:labelId/delete")(writableRepository {
|
||||
ajaxGet("/:owner/:repository/issues/label/:labelId/delete")(writableRepository {
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
val labelId = params("labelId").toInt
|
||||
|
||||
Reference in New Issue
Block a user