From: Rodney Ewing Date: Wed, 7 Aug 2013 19:44:43 +0000 (-0700) Subject: add the ability to mark all notifications read. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d0708da727b72cfc95defe14dd6780d2cba0a0b7;p=mediagoblin.git add the ability to mark all notifications read. --- diff --git a/mediagoblin/notifications/routing.py b/mediagoblin/notifications/routing.py index e57956d3..cd7bbc21 100644 --- a/mediagoblin/notifications/routing.py +++ b/mediagoblin/notifications/routing.py @@ -23,3 +23,7 @@ add_route('mediagoblin.notifications.subscribe_comments', add_route('mediagoblin.notifications.silence_comments', '/u//m//notifications/silence/', 'mediagoblin.notifications.views:silence_comments') + +add_route('mediagoblin.notifications.mark_all_comment_notifications_seen', + '/notifications/comments/mark_all_seen/', + 'mediagoblin.notifications.views:mark_all_comment_notifications_seen') diff --git a/mediagoblin/notifications/views.py b/mediagoblin/notifications/views.py index d275bc92..cda7f0af 100644 --- a/mediagoblin/notifications/views.py +++ b/mediagoblin/notifications/views.py @@ -24,7 +24,7 @@ from mediagoblin.decorators import (uses_pagination, get_user_media_entry, from mediagoblin import messages from mediagoblin.notifications import add_comment_subscription, \ - silence_comment_subscription + silence_comment_subscription, mark_comment_notification_seen from werkzeug.exceptions import BadRequest @@ -52,3 +52,17 @@ def silence_comments(request, media): ' %s.') % media.title) return redirect(request, location=media.url_for_self(request.urlgen)) + + +@require_active_login +def mark_all_comment_notifications_seen(request): + """ + Marks all comment notifications seen. + """ + for comment in request.notifications.get_notifications(request.user.id): + mark_comment_notification_seen(comment.subject_id, request.user) + + if request.GET.get('next'): + return redirect(request, location=request.GET.get('next')) + else: + return redirect(request, 'index') diff --git a/mediagoblin/static/js/notifications.js b/mediagoblin/static/js/notifications.js index 0153463a..c1c06a43 100644 --- a/mediagoblin/static/js/notifications.js +++ b/mediagoblin/static/js/notifications.js @@ -33,4 +33,17 @@ var notifications = {}; $(document).ready(function () { notifications.init(); + + var mark_all_comments_seen = document.getElementById('mark_all_comments_seen'); + + if (mark_all_comments_seen) { + mark_all_comments_seen.href = '#'; + mark_all_comments_seen.onclick = function() { + $.ajax({ + type: 'GET', + url: '/notifications/comments/mark_all_seen/', + success: function(res, status, xhr) { window.location.reload(); }, + }); + } + } }); diff --git a/mediagoblin/templates/mediagoblin/fragments/header_notifications.html b/mediagoblin/templates/mediagoblin/fragments/header_notifications.html index 70d7935a..55759a39 100644 --- a/mediagoblin/templates/mediagoblin/fragments/header_notifications.html +++ b/mediagoblin/templates/mediagoblin/fragments/header_notifications.html @@ -36,5 +36,9 @@ {% endfor %} + + {% trans %}Mark all read{% endtrans %} + {% endif %}