Newer
Older
gitbucket_jkp / src / main / twirl / issues / editcomment.scala.html
@(content: String, commentId: Int, owner: String, repository: String)(implicit context: app.Context)
@import context._
<span id="error-edit-content-@commentId" class="error"></span>
@helper.html.attached(owner, repository){
  <textarea style="width: 635px; height: 100px;" id="edit-content-@commentId">@content</textarea>
}
<div>
  <input type="button" id="update-comment-@commentId" class="btn btn-small" value="Update Comment"/>
  <input type="button" id="cancel-comment-@commentId" class="btn btn-small btn-danger pull-right" value="Cancel"/>
</div>
<script>
$(function(){
  var callback = function(data){
    $('#update-comment-@commentId, #cancel-comment-@commentId').removeAttr('disabled');
    $('#commentContent-@commentId').empty().html(data.content);
    prettyPrint();
  };

  $('#update-comment-@commentId').click(function(){
    $('#update-comment-@commentId, #cancel-comment-@commentId').attr('disabled', 'disabled');
    $.ajax({
      url: '@path/@owner/@repository/issue_comments/edit/@commentId',
      type: 'POST',
      data: {
        issueId : 0,	// TODO
        content : $('#edit-content-@commentId').val()
      }
    }).done(
      callback
    ).fail(function(req) {
      $('#update-comment-@commentId, #cancel-comment-@commentId').removeAttr('disabled');
      $('#error-edit-content-@commentId').text($.parseJSON(req.responseText).content);
    });
  });

  $('#cancel-comment-@commentId').click(function(){
    $('#update-comment-@commentId, #cancel-comment-@commentId').attr('disabled', 'disabled');
    $.get('@path/@owner/@repository/issue_comments/_data/@commentId', callback);
    return false;
  });
});
</script>