From fceb51f82ec71d9b876ef77e51284bad1ef80c62 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 14 Jul 2014 17:06:30 -0300 Subject: added link to clear new notifications in the responses inbox --- askbot/media/js/user.js | 44 ++++++++++++++++++++++++++++++ askbot/templates/macros.html | 11 ++------ askbot/templates/user_inbox/base.html | 1 + askbot/templates/user_inbox/responses.html | 3 ++ askbot/urls.py | 5 ++++ askbot/views/users.py | 18 ++++++++++++ 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 %} {% trans username=user.username|escape %}responses for {{username}}{% endtrans %} 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 %}" /> {% 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 %} +

{% trans %}Clear new notifications{% endtrans %}

+ {% endif %}
{% for message in messages %}{# messages are grouped by question, using the "nested_messages" #}