Disable 'Mark all as read' for notifications when everything is read

- This action needn't be performed when all notifications are read,
  hence disabling it is a good practice
- Added a link-disabled-color
- Used css pointer-events to disable clicking on the link

Preventing default on click for the mark_all_read_link

- avoiding the use of pointer-events
- setting up disabled only for mark_all_read_link

Moved disabling of the link to a global handler

- Added disabled class to the button in /notifications when all are read
- Styled the disabled button
- Adding disabled class after completion of ajaxRequest
This commit is contained in:
Srihari Sriraman 2013-08-29 11:48:01 +05:30 committed by Jonne Haß
parent da23efa433
commit 0bcc62f07f
7 changed files with 24 additions and 4 deletions

View file

@ -40,6 +40,7 @@ var app = {
this.setupHeader(); this.setupHeader();
this.setupBackboneLinks(); this.setupBackboneLinks();
this.setupGlobalViews(); this.setupGlobalViews();
this.setupDisabledLinks();
}, },
hasPreload : function(prop) { hasPreload : function(prop) {
@ -107,7 +108,13 @@ var app = {
instrument : function(type, name, object, callback) { instrument : function(type, name, object, callback) {
if(!window.mixpanel) { return } if(!window.mixpanel) { return }
window.mixpanel[type](name, object, callback) window.mixpanel[type](name, object, callback)
} },
setupDisabledLinks: function() {
$("a.disabled").click(function(event) {
event.preventDefault();
});
},
}; };
$(function() { $(function() {

View file

@ -22,7 +22,7 @@
.next(".hidden") .next(".hidden")
.removeClass("hidden"); .removeClass("hidden");
}); });
self.notificationMenu.find('a#mark_all_read_link').click(function() { self.notificationMenu.find('a#mark_all_read_link').click(function(event) {
$.ajax({ $.ajax({
url: "/notifications/read_all", url: "/notifications/read_all",
type: "GET", type: "GET",
@ -39,6 +39,7 @@
self.resetCount(); self.resetCount();
} }
}); });
$(event.target).addClass("disabled");
return false; return false;
}); });
}); });

View file

@ -52,6 +52,13 @@ a
:color $blue :color $blue
:text :text
:decoration underline :decoration underline
&.disabled
:color $link-disabled-grey
:cursor default
&.disabled.button:hover
:color $link-disabled-grey
:cursor default
:background #f7f7f7
p p
:word-wrap break-word :word-wrap break-word

View file

@ -7,6 +7,7 @@ $border-grey: #DDDDDD;
$background-grey: #EEEEEE; $background-grey: #EEEEEE;
$header-grey: #939393; $header-grey: #939393;
$link-grey: #777777; $link-grey: #777777;
$link-disabled-grey: #999999;
$text-grey: #999999; $text-grey: #999999;
$white: white; $white: white;

View file

@ -131,6 +131,10 @@ body > header {
} }
a { color: $blue; } a { color: $blue; }
a.disabled {
color: $link-disabled-grey;
cursor: default;
}
.header { .header {
padding: 10px; padding: 10px;

View file

@ -45,7 +45,7 @@
<div class="header"> <div class="header">
<div class="right"> <div class="right">
<a href="#" id="mark_all_read_link"> <a href="#" id="mark_all_read_link" class="{{#unless current_user.notifications_count}}disabled{{/unless}}">
{{t "header.mark_all_as_read"}} {{t "header.mark_all_as_read"}}
</a> </a>
| |

View file

@ -5,7 +5,7 @@
= @unread_notification_count = @unread_notification_count
= t('.notifications') = t('.notifications')
.span-8.last .span-8.last
= link_to t('.mark_all_as_read'), notifications_read_all_path, :class => 'button' = link_to t('.mark_all_as_read'), notifications_read_all_path, :class => "button #{'disabled' unless @unread_notification_count > 0}"
.span-24.last .span-24.last
.stream.notifications .stream.notifications
- @group_days.each do |day, notes| - @group_days.each do |day, notes|