Skip to content

Commit

Permalink
Cleaner notification deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Grillot committed Dec 17, 2012
1 parent 4e38721 commit d39e904
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
16 changes: 6 additions & 10 deletions app/assets/javascripts/application.js
Expand Up @@ -42,21 +42,17 @@ $(document).ready(function() {
}
});

// generic
// notifications

$(document).on('ajax:complete', 'a.ajax', function(){
$this = $(this);
$('a[href="'+$this.attr('href')+'"]').replaceWith('<span class="deleteMe '+$this.removeClass('ajax').attr('class')+'">✓</span>');
setTimeout(function(){
$('.deleteMe').fadeOut('slow');
}, 1000);
})
$('a.delete_notification').bind('ajax:beforeSend', function(){
$(this).parents('tr').hide('slow');
});

// small messages

$(document).on('ajax:beforeSend', 'a.ajax-delete', function(){
$(document).on('ajax:beforeSend', 'a.delete_small_message', function(){
$(this).css('visibility', 'hidden');
}).on('ajax:complete', 'a.ajax-delete', function(){
}).on('ajax:complete', 'a.delete_small_message', function(){
$(this).parent().hide('slow');
});

Expand Down
1 change: 1 addition & 0 deletions app/controllers/notifications_controller.rb
Expand Up @@ -34,6 +34,7 @@ def destroy
respond_to do |format|
format.html { redirect_to notifications_url }
format.json { head :no_content }
format.js { head :no_content }
end
end
end
1 change: 1 addition & 0 deletions app/controllers/small_messages_controller.rb
Expand Up @@ -89,6 +89,7 @@ def destroy
respond_to do |format|
format.html { redirect_to topic_url(topic, page: params[:page], anchor: "m#{message_id}") }
format.json { head :no_content }
format.js { head :no_content }
end
end
end
2 changes: 1 addition & 1 deletion app/models/notification.rb
Expand Up @@ -15,7 +15,7 @@ def increment_notifications_count
def publish
data = {
# avatar should use shared/avatar partial
avatar: self.message.user.avatar.exists? ? self.message.user.avatar.url(:icon) : self.message.user.gravatar_url(d: 'retro'),
avatar: self.message.user.avatar.exists? ? self.message.user.avatar.url(:x40) : self.message.user.gravatar_url(d: 'retro'),
title: truncate(self.message.topic.name, length: 20, separator: ' ', omission: '...'),
content: truncate(self.message.content, length: 24, separator: ' ', omission: '...'),
link: topic_path(self.message.topic) + '?newest'
Expand Down
2 changes: 1 addition & 1 deletion app/views/messages/_list.html.haml
Expand Up @@ -45,7 +45,7 @@
= f.input :message_id, as: :hidden
%td.ago.hidden-portrait-phone.meta
- if url_for == notifications_path
%p= link_to t('common.remove'), notification_path(message.notification_id), method: :delete, rel: :nofollow, remote: true, class: 'ajax'
%p= link_to t('common.remove'), notification_path(message.notification_id), method: :delete, rel: :nofollow, remote: true, class: 'delete_notification'
%p{title: l(message.created_at)}= time_ago_in_words message.created_at
- if current_user && !params[:q] && current_user.id != message.user_id
= render 'follows/show', id: message.follow_id, followable_id: message.id, followable_type: 'Message'
Expand Down
2 changes: 1 addition & 1 deletion app/views/small_messages/_show.html.haml
Expand Up @@ -3,4 +3,4 @@
%span.user= raw "#{username small_message.user}, "
%span.time{title: l(small_message.created_at)}= time_ago_in_words small_message.created_at
- if can? :destroy, small_message
= link_to '×', small_message_path(small_message, page: params[:page]), method: :delete, remote: true, class: 'ajax-delete'
= link_to '×', small_message_path(small_message, page: params[:page]), method: :delete, remote: true, class: 'delete_small_message'
2 changes: 1 addition & 1 deletion config/locales/en.yml
Expand Up @@ -38,7 +38,7 @@ en:
unpin: Unpin
are_you_sure: "Are you sure?"
follow: follow
remove: remove
remove: "×"
unfollow: unfollow
na: "not available"
topics_count:
Expand Down

0 comments on commit d39e904

Please sign in to comment.