From 30dd11b9fa915cbb5a4a060fb501ed8432cabf80 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Sat, 25 Dec 2010 16:27:09 -0500 Subject: [PATCH] mark notifications as read and update badge --- app/views/notifications/index.html.haml | 12 ++++++++++-- public/javascripts/web-socket-receiver.js | 1 - 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 0013e3be3..45d504841 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -1,7 +1,8 @@ :javascript $('.message').live('click', function(evt){ var note = $(this).closest('.message'), - note_id = note.attr('data-guid'); + note_id = note.attr('data-guid'), + nBadge = $("#notification_badge_number"); if(note.hasClass('unread') ){ note.removeClass('unread'); @@ -10,8 +11,15 @@ type: 'PUT' }); } - }); + nBadge.html().replace(/\d+/, function(num){ + num = parseInt(num); + nBadge.html(parseInt(num)-1); + if(num == 1) { + nBadge.addClass("hidden"); + } + }); + }); .span-1 = image_tag 'icons/mail_big.png', :height => 30, :width => 30, :style=>"margin-top:3px;" diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index 4a1bdefe4..a6bd2554e 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -54,7 +54,6 @@ var WebSocketReceiver = { processNotification: function(notification){ - var nBadge = $("#notification_badge_number"); nBadge.html().replace(/\d+/, function(num){