Skip to content

Commit

Permalink
Add JS notifications unread polling
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywink committed Oct 11, 2015
1 parent cfdc99f commit db884c3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/assets/javascripts/app/views/notifications_view.js
Expand Up @@ -10,6 +10,8 @@ app.views.Notifications = Backbone.View.extend({
initialize: function() {
$(".unread-toggle .entypo-eye").tooltip();
app.helpers.timeago($(document));
this.updateHeaderCounts();
setInterval(this.updateHeaderCounts, 30000);
},

toggleUnread: function(evt) {
Expand Down Expand Up @@ -50,6 +52,22 @@ app.views.Notifications = Backbone.View.extend({
});
},

updateHeaderCounts: function() {
$.getJSON("/notifications/counts", function(data) {
var headerBadge = $(".notifications-link .badge"),
markAllReadLink = $("a#mark_all_read_link");
if (data.notifications > 0) {
headerBadge.html(parseInt(data.notifications));
headerBadge.removeClass("hidden");
markAllReadLink.removeClass("enabled");
} else {
headerBadge.addClass("hidden");
headerBadge.html(0);
markAllReadLink.removeClass("disabled");
}
});
},

updateView: function(guid, type, unread) {
var change = unread ? 1 : -1,
allNotes = $(".list-group > a:eq(0) .badge"),
Expand Down

0 comments on commit db884c3

Please sign in to comment.