diff --git a/media/js/base.js b/media/js/base.js index 49730b9f8c..508b5bd119 100644 --- a/media/js/base.js +++ b/media/js/base.js @@ -53,6 +53,7 @@ $(function() { notice_list = $('#notice-list'); notice_list.addClass('hide'); loading_tip.show(); + $('.error', popup).addClass('hide'); $.ajax({ url: popup.data('url'), dataType: 'json', @@ -68,6 +69,17 @@ $(function() { dataType:'json' }); }); + }, + error: function (xhr, textStatus, errorThrown) { + if (xhr.responseText) { + var error = jQuery.parseJSON(xhr.responseText).error; + loading_tip.hide(); + if ($('.error', popup).length == 0) { + loading_tip.after('
' + error + '
'); + } else { + $('.error', popup).removeClass('hide'); + } + } } }); } @@ -95,29 +107,37 @@ $(function() { } }); - (function () { - var my_info = $('#my-info'); + $('#my-info').click(function() { var popup = $('#user-info-popup'); - my_info.click(function() { - var loading_tip = $('.loading-tip', popup); - if (popup.hasClass('hide')) { - popup.removeClass('hide'); - loading_tip.removeClass('hide'); - $.ajax({ - url: my_info.data('url'), - dataType: 'json', - cache: false, - success: function(data) { - loading_tip.addClass('hide'); - $('#space-traffic').html(data['html']); - } - }); - } else { - popup.addClass('hide'); - } - return false; - }); - })(); + popup.toggleClass('hide'); + if (!popup.hasClass('hide')) { + var loading_tip = $('.loading-tip', popup), + space_traffic = $('#space-traffic'); + loading_tip.show(); + space_traffic.addClass('hide'); + $('.error', popup).addClass('hide'); + $.ajax({ + url: space_traffic.data('url'), + dataType: 'json', + cache: false, + success: function(data) { + loading_tip.hide(); + space_traffic.html(data['html']).removeClass('hide'); + }, + error: function (xhr, textStatus, errorThrown) { + if (xhr.responseText) { + var error = jQuery.parseJSON(xhr.responseText).error; + loading_tip.hide(); + if ($('.error', popup).length == 0) { + loading_tip.after('' + error + '
'); + } else { + $('.error', popup).removeClass('hide'); + } + } + } + }); + } + }); }); diff --git a/seahub/templates/base.html b/seahub/templates/base.html index b4ad7e666a..39ef1d87ea 100644 --- a/seahub/templates/base.html +++ b/seahub/templates/base.html @@ -62,7 +62,7 @@ diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index fea63c4099..de37485fb3 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -1255,7 +1255,6 @@ def upload_file_done(request): return HttpResponse(json.dumps({'success': True}), content_type=ct) -@login_required def unseen_notices_count(request): """Count user's unseen notices. @@ -1266,6 +1265,12 @@ def unseen_notices_count(request): raise Http404 content_type = 'application/json; charset=utf-8' + + if not request.user.is_authenticated(): + return HttpResponse(json.dumps({ + 'error': _('Please log in.') + }), status=400, content_type=content_type) + username = request.user.username count = UserNotification.objects.count_unseen_user_notifications(username) @@ -1273,7 +1278,6 @@ def unseen_notices_count(request): result['count'] = count return HttpResponse(json.dumps(result), content_type=content_type) -@login_required def get_popup_notices(request): """Get user's notifications. @@ -1289,6 +1293,12 @@ def get_popup_notices(request): raise Http404 content_type = 'application/json; charset=utf-8' + + if not request.user.is_authenticated(): + return HttpResponse(json.dumps({ + 'error': _('Please log in.') + }), status=400, content_type=content_type) + username = request.user.username result_notices = [] @@ -1461,13 +1471,17 @@ def repo_remove(request, repo_id): result['error'] = _(u'Permission denied.') return HttpResponse(json.dumps(result), status=403, content_type=ct) -@login_required def space_and_traffic(request): if not request.is_ajax(): raise Http404 content_type = 'application/json; charset=utf-8' + if not request.user.is_authenticated(): + return HttpResponse(json.dumps({ + 'error': _('Please log in.') + }), status=400, content_type=content_type) + username = request.user.username quota = seafserv_threaded_rpc.get_user_quota(username)