From 2e85a9fe663fdef7502f1b1d9d092f661e53c74d Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 17 Dec 2010 16:51:12 -0800 Subject: [PATCH] notifications now can be read --- app/controllers/notifications_controller.rb | 6 +++--- app/views/notifications/index.html.haml | 20 +++++++++++++++----- config/routes.rb | 2 +- public/stylesheets/sass/application.sass | 3 +++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index c79293047..ff920e046 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -6,10 +6,11 @@ class NotificationsController < ApplicationController before_filter :authenticate_user! respond_to :html - def destroy + + def update note = Notification.find_by_user_id_and_id(current_user.id, params[:id]) if note - note.delete + note.update_attributes(:unread => false) render :nothing => true else render :nothing => true, :code => 404 @@ -20,6 +21,5 @@ class NotificationsController < ApplicationController @notifications = Notification.for(current_user) @group_days = @notifications.group_by{|note| note.created_at.strftime("%B %d") } respond_with @notifications - @notifications.find_all{|x| x.unread ==true}.each{|x| x.update_attributes(:unread => false)} end end diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 2af993192..28c5d7e6d 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -1,11 +1,21 @@ -%ul +:javascript + $('.note a').live('click', function(evt){ + var note_id = $(this).closest('.note').attr('id'); + $.ajax({ + url: 'notifications/' + note_id, + type: 'PUT' + }); + }); + +%ul.notes - @group_days.each do |day, notes| %h3 %ul %li = day - notes.each do |note| - %li - = link_to "#{note.person.name.titleize}", person_path(note.person) - = object_link(note) - %span.description=" #{t('ago', :time => time_ago_in_words(note.created_at))}" + %li.note{:id => note.id} + %h4{:class => "#{note.unread ? 'unread' : ''}"} + = link_to "#{note.person.name.titleize}", person_path(note.person) + = object_link(note) + %span.description=" #{t('ago', :time => time_ago_in_words(note.created_at))}" diff --git a/config/routes.rb b/config/routes.rb index e9ffd5af3..e8b45c3ac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,7 @@ Diaspora::Application.routes.draw do resources :requests, :only => [:destroy, :create] resources :services - resources :notifications, :only => [:destroy, :index] + resources :notifications resources :posts, :only => [:show], :path => '/p/' diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 1dc27f240..bd398323b 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -218,6 +218,9 @@ header :top 2px :display block +.unread + :background-color #eee + .diaspora_header_logo :position relative :top 4px