$(document).
+ on('notifications:recount',
+ function() {
+ var menu = $('.notification-menu');
+ n = $('.notification', menu).not('.empty').length;
+ $('.notification-count', menu).html(n>0 ? n : '');
+ }).
on('ajax:success', 'form.new_authorized_key',
function(e, data, status, xhr) {
- $(e.target).parents('div.daxalert').fadeOut('slow', function() {
- $('<div class="alert alert-success daxalert"><button type="button" class="close" data-dismiss="alert">×</button><p>Key added.</p></div>').hide().replaceAll(this).fadeIn('slow');
+ $(e.target).parents('.notification').eq(0).fadeOut('slow', function() {
+ $('<li class="alert alert-success daxalert">SSH key added.</li>').hide().replaceAll(this).fadeIn('slow');
+ $(document).trigger('notifications:recount');
});
}).
on('ajax:complete', 'form.new_authorized_key',
</li>
-->
- <li class="dropdown">
+ <li class="dropdown notification-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-envelope"></span>
- <span class="badge badge-alert"><%= @notification_count %></span>
+ <span class="badge badge-alert notification-count"><%= @notification_count %></span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<% if @notifications.length > 0 %>
<% @notifications.each_with_index do |n, i| %>
<% if i > 0 %><li class="divider"></li><% end %>
- <li style="padding: 10px"><%= n.call(self) %></li>
+ <li class="notification"><%= n.call(self) %></li>
<% end %>
<% else %>
- <li style="padding: 10px">No notifications.</li>
+ <li class="notification empty">No notifications.</li>
<% end %>
</ul>
</li>