summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-07-14 17:06:30 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2014-07-14 17:06:30 -0300
commitfceb51f82ec71d9b876ef77e51284bad1ef80c62 (patch)
tree4f32a558f889f8b2273f84c8937b0f68f7b47d1a
parent448b122b6e4522d66b6b71f4822ad1caf9f9c3f3 (diff)
downloadaskbot-fceb51f82ec71d9b876ef77e51284bad1ef80c62.tar.gz
askbot-fceb51f82ec71d9b876ef77e51284bad1ef80c62.tar.bz2
askbot-fceb51f82ec71d9b876ef77e51284bad1ef80c62.zip
added link to clear new notifications in the responses inbox
-rw-r--r--askbot/media/js/user.js44
-rw-r--r--askbot/templates/macros.html11
-rw-r--r--askbot/templates/user_inbox/base.html1
-rw-r--r--askbot/templates/user_inbox/responses.html3
-rw-r--r--askbot/urls.py5
-rw-r--r--askbot/views/users.py18
6 files changed, 74 insertions, 8 deletions
diff --git a/askbot/media/js/user.js b/askbot/media/js/user.js
index 11457803..a116876c 100644
--- a/askbot/media/js/user.js
+++ b/askbot/media/js/user.js
@@ -4,6 +4,14 @@ var setup_inbox = function(){
var modControls = new PostModerationControls();
modControls.decorate(page);
}
+ var page = $('.inbox-forum');
+ if (page.length) {
+ var clearNotifs = $('.clear-messages');
+ if (clearNotifs.length) {
+ var inbox = new ResponseNotifs();
+ inbox.decorate(clearNotifs);
+ }
+ }
};
var setup_badge_details_toggle = function(){
@@ -24,6 +32,42 @@ var setup_badge_details_toggle = function(){
});
};
+var ResponseNotifs = function() {
+ WrappedElement.call(this);
+};
+inherits(ResponseNotifs, WrappedElement);
+
+ResponseNotifs.prototype.clearNewNotifs = function() {
+ var news = $('.new');
+ $('#ab-responses').fadeOut();
+ this._element.fadeOut(function() {
+ news.removeClass('new highlight');
+ });
+};
+
+ResponseNotifs.prototype.makeHandler = function() {
+ var me = this;
+ return function() {
+ $.ajax({
+ type: 'POST',
+ cache: false,
+ dataType: 'json',
+ url: askbot['urls']['clearNewNotifications'],
+ success: function(response_data){
+ if (response_data['success']) {
+ me.clearNewNotifs();
+ }
+ }
+ });
+ };
+};
+
+ResponseNotifs.prototype.decorate = function(element) {
+ this._element = element;
+ var btn = element.find('a');
+ setupButtonEventHandlers(btn, this.makeHandler());
+};
+
/**
* the dropdown menu with selection of reasons
* to reject posts and a button that starts menu to
diff --git a/askbot/templates/macros.html b/askbot/templates/macros.html
index 8b657ec1..942d150f 100644
--- a/askbot/templates/macros.html
+++ b/askbot/templates/macros.html
@@ -796,17 +796,12 @@ for the purposes of the AJAX comment editor #}
{%- macro inbox_link(user) -%}
- {% if user.new_response_count > 0 or user.seen_response_count > 0 %}
+ {% if user.new_response_count %}
<a id='ab-responses' href="{{user.get_absolute_url()}}?sort=inbox&section=forum">
<img
alt="{% trans username=user.username|escape %}responses for {{username}}{% endtrans %}"
- {% if user.new_response_count > 0 %}
- src="{{ "/images/mail-envelope-full.png"|media }}"
- title="{% trans response_count=user.new_response_count %}you have {{response_count}} new response{% pluralize %}you have {{response_count}} new responses{% endtrans %}"
- {% elif user.seen_response_count > 0 %}
- src="{{ "/images/mail-envelope-empty.png"|media }}"
- title="{% trans %}no new responses yet{% endtrans %}"
- {% endif %}
+ src="{{ "/images/mail-envelope-full.png"|media }}"
+ title="{% trans response_count=user.new_response_count %}you have {{response_count}} new response{% pluralize %}you have {{response_count}} new responses{% endtrans %}"
/>
</a>
{% endif %}
diff --git a/askbot/templates/user_inbox/base.html b/askbot/templates/user_inbox/base.html
index 4687c62a..5a1dcb01 100644
--- a/askbot/templates/user_inbox/base.html
+++ b/askbot/templates/user_inbox/base.html
@@ -50,6 +50,7 @@
var askbot = askbot || {};
askbot['urls'] = askbot['urls'] || {};
askbot['urls']['manageInbox'] = '{% url manage_inbox %}';
+ askbot['urls']['clearNewNotifications'] = '{% url clear_new_notifications %}';
askbot['urls']['moderatePostEdits'] = '{% url moderate_post_edits %}';
askbot['urls']['save_post_reject_reason'] = '{% url save_post_reject_reason %}';
askbot['urls']['delete_post_reject_reason'] = '{% url delete_post_reject_reason %}';
diff --git a/askbot/templates/user_inbox/responses.html b/askbot/templates/user_inbox/responses.html
index dd27ef06..828e839d 100644
--- a/askbot/templates/user_inbox/responses.html
+++ b/askbot/templates/user_inbox/responses.html
@@ -4,6 +4,9 @@
{% trans %}inbox - moderation queue{% endtrans %}
{% endblock %}
{% block inbox_content %}
+ {% if request.user.new_response_count %}
+ <p class="clear-messages"><a>{% trans %}Clear new notifications{% endtrans %}</a></p>
+ {% endif %}
<div class="messages">
{% for message in messages %}{# messages are grouped by question, using the "nested_messages" #}
<div class="message{% if message.is_new %} highlight new{% else %} seen{% endif %}"
diff --git a/askbot/urls.py b/askbot/urls.py
index 85f9675f..93fb879c 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -494,6 +494,11 @@ urlpatterns = patterns('',
name='manage_inbox'
),
service_url(#ajax only
+ r'^clear-new-notifications/$',
+ views.users.clear_new_notifications,
+ name='clear_new_notifications'
+ ),
+ service_url(#ajax only
r'^save-post-reject-reason/$',
views.commands.save_post_reject_reason,
name='save_post_reject_reason'
diff --git a/askbot/views/users.py b/askbot/views/users.py
index d5a7f8ad..c80ff4ec 100644
--- a/askbot/views/users.py
+++ b/askbot/views/users.py
@@ -38,6 +38,7 @@ from askbot.utils.slug import slugify
from askbot.utils.html import sanitize_html
from askbot.mail import send_mail
from askbot.utils.http import get_request_info
+from askbot.utils import decorators
from askbot.utils import functions
from askbot import forms
from askbot import const
@@ -65,6 +66,23 @@ def owner_or_moderator_required(f):
return f(request, profile_owner, context)
return wrapped_func
+@decorators.ajax_only
+def clear_new_notifications(request):
+ """clears all new notifications for logged in user"""
+ user = request.user
+ if user.is_anonymous():
+ raise django_exceptions.PermissionDenied
+
+ activity_types = const.RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY
+ activity_types += (
+ const.TYPE_ACTIVITY_MENTION,
+ )
+ memo_set = models.ActivityAuditStatus.objects.filter(
+ activity__activity_type__in=activity_types,
+ user=user
+ )
+ memo_set.update(status = models.ActivityAuditStatus.STATUS_SEEN)
+ user.update_response_counts()
def show_users(request, by_group=False, group_id=None, group_slug=None):
"""Users view, including listing of users by group"""