Fix to submit form when creating issue comment.

This commit is contained in:
shimamoto
2013-06-25 14:11:01 +09:00
parent 1a4510201f
commit 317e2b6ea3
3 changed files with 29 additions and 55 deletions

View File

@@ -14,11 +14,16 @@ trait IssuesControllerBase extends ControllerBase {
with UsersOnlyAuthenticator =>
case class IssueForm(title: String, content: Option[String])
case class CommentForm(issueId: Int, content: String)
val form = mapping(
"title" -> trim(label("Title", text(required))),
"content" -> trim(optional(text()))
)(IssueForm.apply)
val commentForm = mapping(
"issueId" -> label("Issue Id", number()),
"content" -> trim(label("Comment", text(required)))
)(CommentForm.apply)
get("/:owner/:repository/issues"){
val owner = params("owner")
@@ -68,21 +73,12 @@ trait IssuesControllerBase extends ControllerBase {
})
// TODO requires users only and redable repository checking
post("/:owner/:repository/issue_comments")( usersOnly {
post("/:owner/:repository/issue_comments", commentForm)( usersOnly { form =>
val owner = params("owner")
val repository = params("repository")
val issueId = params("issueId").toInt
val content = params("content") // TODO input check
contentType = formats("json")
saveComment(owner, repository, context.loginAccount.get.userName, issueId, content) map {
model => org.json4s.jackson.Serialization.write(
Map("commentedUserName" -> model.commentedUserName,
"registeredDate" -> view.helpers.datetime(model.registeredDate),
"content" -> view.Markdown.toHtml(
model.content, getRepository(owner, repository, baseUrl).get, false, true, true)
))
} getOrElse ""
redirect("/%s/%s/issues/%d#comment-%d".format(owner, repository, form.issueId,
saveComment(owner, repository, context.loginAccount.get.userName, form.issueId, form.content)))
})
}

View File

@@ -60,15 +60,13 @@ trait IssuesService {
def saveComment(owner: String, repository: String, loginUser: String,
issueId: Int, content: String) =
Query(IssueComments) filter {
_.commentId is ( IssueComments.autoInc insert (
owner,
repository,
issueId,
loginUser,
content,
currentDate,
currentDate) ).bind
} firstOption
IssueComments.autoInc insert (
owner,
repository,
issueId,
loginUser,
content,
currentDate,
currentDate)
}

View File

@@ -19,25 +19,26 @@
@markdown(issue.content getOrElse "No description given.", repository, false, true, true)
</div>
</div>
<span id="comment-area">
@comments.map { comment =>
<div class="box">
<div class="box-header-small">
<a href="@path/@comment.commentedUserName">@comment.commentedUserName</a> commented
<span class="pull-right">@datetime(comment.registeredDate)</span>
</div>
<div class="box-content" style="background-color: #f5f5f5;">
@markdown(comment.content, repository, false, true, true)
</div>
<div class="box" id="comment-@comment.commentId">
<div class="box-header-small">
<a href="@path/@comment.commentedUserName">@comment.commentedUserName</a> commented
<span class="pull-right">@datetime(comment.registeredDate)</span>
</div>
<div class="box-content" style="background-color: #f5f5f5;">
@markdown(comment.content, repository, false, true, true)
</div>
</div>
}
</span>
<form action="@path/@repository.owner/@repository.name/issue_comments" method="POST" validate="true">
<div class="box">
<div class="box-content">
@html.preview(repository, "", false, true, true, "width: 730px; height: 100px;")
</div>
</div>
<input type="button" class="btn btn-success" value="Comment" id="comment"/>
<input type="hidden" name="issueId" value="@issue.issueId"/>
<input type="submit" class="btn btn-success" value="Comment"/>
</form>
</div>
<div class="span2">
@if(issue.closed) {
@@ -50,25 +51,4 @@
<strong>Labels</strong>
</div>
</div>
}
<script>
$(function(){
$('#comment').click(function(){
$.post('@path/@repository.owner/@repository.name/issue_comments',
{
issueId : @issue.issueId,
content : $('#content').val()
},
function(data){
var div = $('<div>').addClass('box')
.append($('<div>').addClass('box-header-small')
.append($('<a>').attr('href', '@path/@repository.owner').text(data.commentedUserName))
.append(' commented')
.append($('<span>').addClass('pull-right').text(data.registeredDate)))
.append($('<div>').addClass('box-content').attr('style', 'background-color: #f5f5f5;').html(data.content));
$('#comment-area').append(div);
$('#content').val('');
});
});
});
</script>
}