mirror of
https://github.com/correl/codereview.git
synced 2024-12-27 11:07:33 +00:00
Updated commenting to use ajax
This commit is contained in:
parent
33a27c17be
commit
f89a815b47
2 changed files with 32 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.core.urlresolvers import reverse
|
||||
|
@ -55,4 +55,7 @@ def add_comment(request):
|
|||
comment.author = request.user
|
||||
comment.path = diff.b.path if diff.b else diff.a.path
|
||||
comment.save()
|
||||
return HttpResponseRedirect(reverse(edit, args=[review.pk]))
|
||||
data = RequestContext(request, {
|
||||
'comment': comment,
|
||||
})
|
||||
return render_to_response('components/comment.html', data)
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
var line_b = info[3];
|
||||
if ($('#' + form_id).length == 0) {
|
||||
// Show the comment form
|
||||
$(this).after(
|
||||
'<tr class="comment-form" id="' + form_id + '" ><td colspan="3">' +
|
||||
var form = $(
|
||||
'<form method="post" action="{% url codereview.review.views.add_comment %}">' +
|
||||
"{% csrf_token %}" +
|
||||
'<input type="hidden" name="review" value="{{ review.pk }}" />' +
|
||||
|
@ -26,8 +25,27 @@
|
|||
'<textarea name="text" />' +
|
||||
'<input type="submit" value="Add Comment" />' +
|
||||
'<input type="button" value="Cancel" onclick="$(this.form).parent().parent().remove();"/>' +
|
||||
'</form>' +
|
||||
'</td></tr>');
|
||||
'</form>');
|
||||
form.submit(function() {
|
||||
var data = $(this).serialize();
|
||||
//$.post('{% url codereview.review.views.add_comment %}', data, function(comment) {
|
||||
$.ajax({
|
||||
'url': '{% url codereview.review.views.add_comment %}',
|
||||
'type': 'POST',
|
||||
'data': data,
|
||||
'context': $(this),
|
||||
'success': function(html) {
|
||||
html = $('<tr class="annotation"></tr>').append($('<td colspan="3"></td>').append(html));
|
||||
$(this).parent().parent().after(html);
|
||||
$(this).parent().parent().remove();
|
||||
},
|
||||
});
|
||||
return false;
|
||||
});
|
||||
$(this).after(
|
||||
$('<tr class="comment-form" id="' + form_id + '" ></tr>')
|
||||
.append($('<td colspan="3"></td>').append(form))
|
||||
);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
@ -37,5 +55,9 @@
|
|||
{% for diff in diffs %}
|
||||
{% include "components/diff.html" %}
|
||||
{% endfor %}
|
||||
|
||||
<div id="comment-template" class="ui-helper-hidden-accessible">
|
||||
{% include "components/comment.html" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue