mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-01 02:56:08 +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")
|
def ajaxGet(path : String)(action : => Any) : Route = {
|
||||||
protected def Unauthorized() = redirect("/")
|
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 = {
|
protected def baseUrl = {
|
||||||
val url = request.getRequestURL.toString
|
val url = request.getRequestURL.toString
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ trait LabelsControllerBase extends ControllerBase {
|
|||||||
redirect("/%s/%s/issues".format(owner, repository))
|
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 owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ trait LabelsControllerBase extends ControllerBase {
|
|||||||
.map(issues.html.labeleditlist(getLabels(owner, repository), _)) getOrElse NotFound()
|
.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 owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val labelId = params("labelId").toInt
|
val labelId = params("labelId").toInt
|
||||||
@@ -50,7 +50,7 @@ trait LabelsControllerBase extends ControllerBase {
|
|||||||
} getOrElse NotFound()
|
} 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 owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val labelId = params("labelId").toInt
|
val labelId = params("labelId").toInt
|
||||||
@@ -61,7 +61,7 @@ trait LabelsControllerBase extends ControllerBase {
|
|||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/issues/label/:labelId/delete")(writableRepository {
|
ajaxGet("/:owner/:repository/issues/label/:labelId/delete")(writableRepository {
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val labelId = params("labelId").toInt
|
val labelId = params("labelId").toInt
|
||||||
|
|||||||
@@ -3,9 +3,8 @@
|
|||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@defining((if(label.isEmpty) ("new", 190, 4) else ("edit", 180, 8))){ case (mode, width, margin) =>
|
@defining((if(label.isEmpty) ("new", 190, 4) else ("edit", 180, 8))){ case (mode, width, margin) =>
|
||||||
<div id="@(mode)LabelArea">
|
<div id="@(mode)LabelArea">
|
||||||
<form method="POST" id="edit-label-form"
|
<form method="POST" id="edit-label-form" validate="true" style="margin-bottom: 8px;"
|
||||||
action="@url(repository)/issues/label/@{if(mode == "new") "new" else label.get.labelId + "/edit"}"
|
action="@url(repository)/issues/label/@{if(mode == "new") "new" else label.get.labelId + "/edit"}">
|
||||||
validate="true" @if(mode == "edit"){ style="margin-bottom: 8px;"}>
|
|
||||||
<span id="error-@(mode)LabelName" class="error"></span>
|
<span id="error-@(mode)LabelName" class="error"></span>
|
||||||
<input type="text" name="@(mode)LabelName" id="@(mode)LabelName" style="width: @(width)px; margin-left: @(margin)px; margin-bottom: 0px;" value="@label.map(_.labelName)"@if(mode == "new"){ placeholder="New label name"}/>
|
<input type="text" name="@(mode)LabelName" id="@(mode)LabelName" style="width: @(width)px; margin-left: @(margin)px; margin-bottom: 0px;" value="@label.map(_.labelName)"@if(mode == "new"){ placeholder="New label name"}/>
|
||||||
<span id="error-@(mode)Color" class="error"></span>
|
<span id="error-@(mode)Color" class="error"></span>
|
||||||
@@ -26,21 +25,17 @@
|
|||||||
$('#editColor').colorpicker();
|
$('#editColor').colorpicker();
|
||||||
|
|
||||||
$('#edit-label-form').submit(function(e){
|
$('#edit-label-form').submit(function(e){
|
||||||
var form = $(e.target);
|
$.ajax($(this).attr('action'), {
|
||||||
$.post(form.attr('action') + '/validate', $(form).serialize(), function(data){
|
type: 'POST',
|
||||||
// clear all error messages
|
data: $(this).serialize()
|
||||||
$('.error').text('');
|
})
|
||||||
|
.done(function(data){
|
||||||
|
$('#label-edit').parent().empty().html(data);
|
||||||
|
})
|
||||||
|
.fail(function(data, status){
|
||||||
|
displayErrors($.parseJSON(data.responseText));
|
||||||
|
});
|
||||||
|
|
||||||
if($.isEmptyObject(data)){
|
|
||||||
$.post(form.attr('action'), $(form).serialize(), function(data){
|
|
||||||
$('#label-edit').parent().empty().html(data);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$.each(data, function(key, value){
|
|
||||||
$('#error-' + key).text(value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, 'json');
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user