add the ability to mark all notifications read.
authorRodney Ewing <ewing.rj@gmail.com>
Wed, 7 Aug 2013 19:44:43 +0000 (12:44 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Tue, 20 Aug 2013 15:09:29 +0000 (08:09 -0700)
mediagoblin/notifications/routing.py
mediagoblin/notifications/views.py
mediagoblin/static/js/notifications.js
mediagoblin/templates/mediagoblin/fragments/header_notifications.html

index e57956d3e9ee93f33903c65cef3dc516e2d693be..cd7bbc21bb04257cde6e54bebc475193fc72979f 100644 (file)
@@ -23,3 +23,7 @@ add_route('mediagoblin.notifications.subscribe_comments',
 add_route('mediagoblin.notifications.silence_comments',
           '/u/<string:user>/m/<string:media>/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')
index d275bc9273f19b22f3b5c95e61ddffacb641cce3..cda7f0afc5829358cde06bcc9701fffce211dcde 100644 (file)
@@ -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')
index 0153463aac2c74ee0d8a49746a51a5e2d7d10c4a..c1c06a431173ada1f56fa0351d64b83fa20eebe6 100644 (file)
@@ -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(); },
+            });
+        }
+    }
 });
index 70d7935a94d407991bc1b3d360b85ee5cc0d0946..55759a39465f481674a243d70d1f633042db7d79 100644 (file)
@@ -36,5 +36,9 @@
         </li>
         {% endfor %}
     </ul>
+    <a href="{{ request.urlgen('mediagoblin.notifications.mark_all_comment_notifications_seen') }}?next={{ 
+      request.base_url|urlencode }}" id="mark_all_comments_seen">
+      {% trans %}Mark all read{% endtrans %}
+    </a>
     </div>
 {% endif %}