diff --git a/templates/file_view.html b/templates/file_view.html index 217f6c02cc..5d0b53128b 100644 --- a/templates/file_view.html +++ b/templates/file_view.html @@ -29,9 +29,9 @@ {% if is_starred %} - + {% else %} - + {% endif %} @@ -164,9 +164,9 @@ $('#edit').click(function() { $('#star').click(function() { var star_btn = $(this); disable(star_btn); - var state = star_btn.attr('data'); + var state = star_btn.data('status'); $.ajax({ - url: '{{ SITE_ROOT }}repo/star_file/{{ repo.id }}/', + url: '{% url 'repo_star_file' repo.id %}', type: 'POST', cache: false, contentType: 'application/json; charset=utf-8', @@ -181,18 +181,20 @@ $('#star').click(function() { if (data['success']) { if (state == 'starred') { feedback('{% trans "Unstarred successfully" %}', 'success'); - star_btn.attr('data', 'unstarred').text('{% trans "Star" %}'); + star_btn.data('status', 'unstarred').text('{% trans "Star" %}'); } else { feedback('{% trans "Starred successfully" %}', 'success'); - star_btn.attr('data', 'starred').text('{% trans "Unstar" %}'); + star_btn.data('status', 'starred').text('{% trans "Unstar" %}'); } - } else { - feedback('{% trans "Failed:" %}' + data['err_msg'], 'error'); + enable(star_btn); } - enable(star_btn); }, - error:function(jqXHR, textStatus, errorThrown) { - feedback(textStatus + '{% trans ", failed" %}', 'error'); + error:function(xhr, textStatus, errorThrown) { + if (xhr.responseText) { + feedback(jQuery.parseJSON(xhr.responseText).error, 'error'); + } else { + feedback('{% trans "Failed. Please check the network." %}', 'error'); + } enable(star_btn); } }); @@ -334,7 +336,7 @@ $('#comment-input').css('color', '#999').click(function() { }); $('#file-comment-form .submit').click(function() { if (!$.trim($('#comment-input').val())) { - $('#file-comment-form .error').html('{% trans "Please type a message" %}').removeClass('hide'); + $('#file-comment-form .error').html('{% trans "Please input a message." %}').removeClass('hide'); return false; } $.ajax({ @@ -353,11 +355,8 @@ $('#file-comment-form .submit').click(function() { $('#file-comment-form .submit, #file-comment-form .error').addClass('hide'); $('#comment-list').html(data.html); }, - error: function(data, textStatus, jqXHR) { - var errors = $.parseJSON(data.responseText); - $.each(errors, function(index, value) { - $('#file-comment-form .error').html(value[0]).removeClass('hide'); - }); + error: function() { + $('#file-comment-form .error').html('{% trans "Failed. Please check the network." %}').removeClass('hide'); } }); return false; diff --git a/templates/repo.html b/templates/repo.html index 0164e6d7ba..61ffa90a36 100644 --- a/templates/repo.html +++ b/templates/repo.html @@ -636,12 +636,14 @@ $('.file-star').click(function() { } else { it.attr('src', '{{ MEDIA_URL }}img/gray-star-icon.png').attr('alt','{% trans 'Starred' %}').attr('title','{% trans 'Starred' %}').data('status','starred'); } - } else { - feedback('{% trans "Failed:" %}' + data['err_msg'], 'error'); } }, - error:function(jqXHR, textStatus, errorThrown) { - feedback(textStatus + '{% trans ", failed" %}', 'error'); + error:function(xhr, textStatus, errorThrown) { + if (xhr.responseText) { + feedback(jQuery.parseJSON(xhr.responseText).error, 'error'); + } else { + feedback('{% trans "Failed. Please check the network." %}', 'error'); + } } }); }); diff --git a/views.py b/views.py index 891819daab..23d77bf1e9 100644 --- a/views.py +++ b/views.py @@ -2827,8 +2827,8 @@ def repo_star_file(request, repo_id): content_type = 'application/json; charset=utf-8' if not (path and state): - return HttpResponse(json.dumps({'success':False, 'err_msg':_(u'Invalid arguments')}), - content_type=content_type) + return HttpResponse(json.dumps({'error': _(u'Invalid arguments')}), + status=400, content_type=content_type) org_id = int(request.POST.get('org_id')) path = urllib2.unquote(path.encode('utf-8'))