diff --git a/media/js/base.js b/media/js/base.js index 18d91738f4..dfc524967c 100644 --- a/media/js/base.js +++ b/media/js/base.js @@ -16,85 +16,62 @@ if ($('.messages')[0]) { setTimeout(function() { $('.messages').addClass('hide'); }, 10000); } -$(function(){ +$(function() { var msg_ct = $("#msg-count"); - $.ajax({ - url: msg_ct.data('cturl'), - dataType: 'json', - cache: false, - success: function(data) { - if (data['count'] > 0) { - $('.num', msg_ct).html(data['count']).removeClass('hide'); - $('.num').data('count', data['count']); + // original title + var orig_doc_title = document.title; + var reqUnreadNum = function() { + $.ajax({ + url: msg_ct.data('url'), + dataType: 'json', + cache: false, + success: function(data) { + var count = data['count'], + num = $('.num', msg_ct); + num.html(count); + if (count > 0) { + num.removeClass('hide'); + document.title = '(' + count + ')' + orig_doc_title; + } else { + num.addClass('hide'); + document.title = orig_doc_title; + } } - } - }); + }); + }; + reqUnreadNum(); + // request every 30s + setInterval(reqUnreadNum, 30*1000); $('#notice-icon').click(function() { var popup = $('#notice-popup'); popup.toggleClass('hide'); - - //to prevent duplicately send ajax - if ($('#notice-icon').data('ajax') != 1){ + if (!popup.hasClass('hide')) { + $('.con', popup).css({'max-height':$(window).height() - $('#header').outerHeight() - $('#notice-popup .hd').outerHeight() - 3}); + var loading_tip = $('.loading-tip', popup); + loading_tip.show(); $.ajax({ - url: popup.data('pop_url'), - dataType: 'json', - cache: false, + url: popup.data('url'), + dataType: 'json', success: function(data) { - popup.find('.loading-tip').remove(); - popup.html(data['notifications_popup_html']); - $('.con', popup).css({'max-height':$(window).height() - $('#header').outerHeight() - $('#notice-popup .hd').outerHeight() - 3}); - $('#notice-icon').data('ajax', 1); + loading_tip.hide(); + var notice_list = $('#notice-list'); + notice_list.html(data['notice_html']).removeClass('hide'); - $('#notice-popup .close').click(function() { - if ($('.num').data('count') > 0){ - $.ajax({ - url: popup.data('seen_url'), - dataType: 'json', - cache: false, - success: function() { - popup.addClass('hide'); - $('.num').data('count', 0); - $('.num').addClass('hide'); - $('li').each(function() { - if ($(this).hasClass('unread')){ - $(this).removeClass('unread'); - $(this).addClass('read'); - } - }); - } - }); - }else{ - popup.addClass('hide'); - } - }); - - $("a[id$='-notice']").click(function() { - var notice_id = $(this).data('notice_id'); - var url = popup.data('seen_by_id_url'); - var href = $(this).data('href'); - - if ($(this).parent().parent().hasClass('unread')){ - $.ajax({ - url: url + '?notice_id=' + notice_id, - type: 'GET', - dataType: 'json', - cache: false, - success: function() { - location.href = href; - } - }); - }else{ - location.href = href; - } + // set a notice to be read when in it is clicked + $('.unread a', notice_list).click(function() { + var notice_id = $(this).parents('.unread').data('id'); + $.ajax({ + url: notice_list.data('url') + '?notice_id=' + e(notice_id), + dataType:'json' + }); }); } }); } }); - $(window).resize(function() { var popup = $('#notice-popup'); if (!popup.hasClass('hide')) { @@ -102,6 +79,22 @@ $(function(){ } }); + $('#notice-popup .close').click(function() { + $('#notice-popup').addClass('hide'); + if ($('#notice-list .unread').length > 0) { + // set all unread notice to be read + var url = $(this).data('url'); + $.ajax({ + url: url, + dataType: 'json', + success: function() { + $('.num', msg_ct).html(0).addClass('hide'); + document.title = orig_doc_title; + } + }); + } + }); + (function () { var my_info = $('#my-info'); var popup = $('#user-info-popup'); @@ -125,6 +118,7 @@ $(function(){ return false; }); })(); + }); $(document).click(function(e) { @@ -137,15 +131,6 @@ $(document).click(function(e) { closePopup($('#user-info-popup'), $('#my-info')); closePopup($('#top-nav-grp-info'), $('#top-nav-grp')); closePopup($('#notice-popup'), $('#notice-icon')); - - var closeNum = function(num, num_switch) { - if (num.hasClass('hide') && !num.is(target) && !num_switch.is(target) && !num_switch.find('*').is(target) ) { - if ($('.num').data('count') > 0){ - num.removeClass('hide'); - } - } - }; - closeNum($('.num'), $('#msg-count')); }); // search: disable submit when input nothing diff --git a/seahub/notifications/models.py b/seahub/notifications/models.py index a1e67688f9..eba0b401c8 100644 --- a/seahub/notifications/models.py +++ b/seahub/notifications/models.py @@ -486,12 +486,11 @@ class UserNotification(models.Model): folder_link = reverse('repo', args=[repo_id]) + '?p=' + urlquote(uploaded_to) folder_name = os.path.basename(uploaded_to) - msg = _(u"A file named %(file_name)s is uploaded to your folder %(folder)s") % { + msg = _(u"A file named %(file_name)s is uploaded to your folder %(folder)s") % { 'file_link': file_link, 'file_name': filename, 'folder_link': folder_link, 'folder': folder_name, - 'notice_id': self.id, } return msg @@ -510,11 +509,10 @@ class UserNotification(models.Model): self.delete() return None - msg = _(u"%(user)s has shared a library named %(repo_name)s to you.") % { + msg = _(u"%(user)s has shared a library named %(repo_name)s to you.") % { 'user': escape(share_from), 'href': reverse('repo', args=[repo.id]), 'repo_name': repo.name, - 'notice_id': self.id, } return msg @@ -529,11 +527,10 @@ class UserNotification(models.Model): file_name = d['file_name'] priv_share_token = d['priv_share_token'] - msg = _(u"%(user)s has shared a file named %(file_name)s to you.") % { + msg = _(u"%(user)s has shared a file named %(file_name)s to you.") % { 'user': escape(share_from), 'href': reverse('view_priv_shared_file', args=[priv_share_token]), 'file_name': file_name, - 'notice_id': self.id, } return msg def format_user_message_title(self): @@ -550,7 +547,7 @@ class UserNotification(models.Model): msg_from = d.get('msg_from') nickname = email2nickname(msg_from) - msg = _(u"You have received a new message from %(user)s.") % { + msg = _(u"You have received a new message from %(user)s.") % { 'user': escape(nickname), 'href': reverse('user_msg_list', args=[msg_from]), } @@ -593,11 +590,11 @@ class UserNotification(models.Model): msg_from = d.get('msg_from') if msg_from is None: - msg = _(u"%(group_name)s has new discussion.") % { + msg = _(u"%(group_name)s has a new discussion.") % { 'href': reverse('group_discuss', args=[group.id]), 'group_name': group.group_name} else: - msg = _(u"%(user)s posted a new discussion in %(group_name)s.") % { + msg = _(u"%(user)s posted a new discussion in %(group_name)s.") % { 'href': reverse('group_discuss', args=[group.id]), 'user': escape(email2nickname(msg_from)), 'group_name': group.group_name} @@ -634,11 +631,11 @@ class UserNotification(models.Model): reply_from = d.get('reply_from') if reply_from is None: - msg = _(u"One group discussion has new reply.") % { + msg = _(u"One group discussion has a new reply.") % { 'href': reverse('msg_reply_new'), } else: - msg = _(u"%(user)s replied your group discussion.") % { + msg = _(u"%(user)s replied your group discussion.") % { 'user': escape(email2nickname(reply_from)), 'href': reverse('msg_reply_new'), } @@ -677,13 +674,12 @@ class UserNotification(models.Model): self.delete() return None - msg = _(u"User %(username)s has asked to join group %(group_name)s, verification message: %(join_request_msg)s") % { + msg = _(u"User %(username)s has asked to join group %(group_name)s, verification message: %(join_request_msg)s") % { 'user_profile': reverse('user_profile', args=[username]), 'username': username, 'href': reverse('group_members', args=[group_id]), 'group_name': group.group_name, 'join_request_msg': escape(join_request_msg), - 'notice_id': self.id, } return msg diff --git a/seahub/notifications/templates/notifications/notice_email.html b/seahub/notifications/templates/notifications/notice_email.html index b9052ed022..282e42722e 100644 --- a/seahub/notifications/templates/notifications/notice_email.html +++ b/seahub/notifications/templates/notifications/notice_email.html @@ -5,7 +5,7 @@ {% block email_con %} {% autoescape off %} -
Hi, {{ name|email2nickname }}
+{% blocktrans with name=to_user|email2nickname %}Hi {{ name }},{% endblocktrans %}
{% blocktrans count num=notice_count %} @@ -15,8 +15,8 @@ You've got {{num}} new notices on {{ site_name }}: {% endblocktrans %}
-{% trans "Message"%} | {% trans "Time"%} | @@ -24,38 +24,38 @@ You've got {{num}} new notices on {{ site_name }}: {% for notice in notices %} {% if notice.is_group_msg %} -
---|---|
{{notice.group_msg_from}} posted a new discussion in {{notice.group_name}} | +|
{% blocktrans with user=notice.group_msg_from grp_url=notice.group_url grp_name=notice.group_name%}{{user}} posted a new discussion in {{grp_name}}{% endblocktrans %} | {{ notice.timestamp }} |
{{notice.group_msg_reply_from}} replied yourgroup discussion | +|
{% blocktrans with user=notice.group_msg_reply_from reply_url=notice.group_msg_reply_url%}{{user}} replied yourgroup discussion{% endblocktrans %} | {{ notice.timestamp }} |
{{notice.repo_share_from}} has shared a library named {{notice.repo_name}} to you. | +|
{% blocktrans with user=notice.repo_share_from lib_url=notice.repo_url lib_name=notice.repo_name%}{{user}} has shared a library named {{lib_name}} to you.{% endblocktrans %} | {{ notice.timestamp }} |
{{notice.priv_shared_file_from}} has shared a file named {{notice.priv_shared_file_name}} to you. | +|
{% blocktrans with user=notice.priv_shared_file_from file_url=notice.priv_shared_file_url file_name=notice.priv_shared_file_name %}{{user}} has shared a file named {{file_name}} to you.{% endblocktrans %} | {{ notice.timestamp }} |
You have received a new message from {{notice.user_msg_from}} | +|
{% blocktrans with msg_url=notice.user_msg_url user=notice.user_msg_from %}You have received a new message from {{user}}.{% endblocktrans %} | {{ notice.timestamp }} |
A file named {{notice.uploaded_file_name}} is uploaded to your folder {{notice.uploaded_folder_name}}. | +|
{% blocktrans with file_url=notice.uploaded_file_link file_name=notice.uploaded_file_name folder_url=notice.uploaded_folder_link folder_name=notice.uploaded_folder_name %}A file named {{file_name}} is uploaded to your folder {{folder_name}}.{% endblocktrans %} | {{ notice.timestamp }} |
User {{notice.grpjoin_username}} has asked to join group {{notice.grpjoin_group_name}}, verification message: {{notice.grpjoin_request_msg}}. | +|
{% blocktrans with user_url=notice.grpjoin_user_profile_url user_name=notice.grpjoin_username grp_url=notice.grpjoin_group_url grp_name=notice.grpjoin_group_name msg=notice.grpjoin_request_msg%}User {{user_name}} has asked to join group {{grp_name}}, verification message: {{msg}}.{% endblocktrans %} | {{ notice.timestamp }} |