From 65b45e46c28e03d683991b093e3cefd705d2a128 Mon Sep 17 00:00:00 2001 From: albert Date: Wed, 20 Feb 2013 22:52:42 -0500 Subject: [PATCH] add mark all dmail as read option --- app/controllers/dmails_controller.rb | 6 ++++++ app/views/dmails/_secondary_links.html.erb | 1 + app/views/dmails/mark_all_as_read.js.erb | 1 + config/routes.rb | 1 + 4 files changed, 9 insertions(+) create mode 100644 app/views/dmails/mark_all_as_read.js.erb diff --git a/app/controllers/dmails_controller.rb b/app/controllers/dmails_controller.rb index c06f5b651..be3141019 100644 --- a/app/controllers/dmails_controller.rb +++ b/app/controllers/dmails_controller.rb @@ -41,6 +41,12 @@ class DmailsController < ApplicationController redirect_to dmails_path, :notice => "Message destroyed" end + def mark_all_as_read + Dmail.visible.unread.each do |x| + x.update_column(:is_read, true) + end + end + private def check_privilege(dmail) if !dmail.visible_to?(CurrentUser.user) diff --git a/app/views/dmails/_secondary_links.html.erb b/app/views/dmails/_secondary_links.html.erb index 3534b0552..559277969 100644 --- a/app/views/dmails/_secondary_links.html.erb +++ b/app/views/dmails/_secondary_links.html.erb @@ -4,5 +4,6 @@
  • <%= link_to "Sent", dmails_path(:search => {:owner_id => CurrentUser.id, :from_id => CurrentUser.id}, :folder => "sent") %>
  • <%= link_to "New", new_dmail_path %>
  • <%= link_to "Search", search_dmails_path %>
  • +
  • <%= link_to "Mark all as read", {:controller => "dmails", :action => "mark_all_as_read"}, :method => :post, :remote => true %>
  • <% end %> diff --git a/app/views/dmails/mark_all_as_read.js.erb b/app/views/dmails/mark_all_as_read.js.erb new file mode 100644 index 000000000..345366b9b --- /dev/null +++ b/app/views/dmails/mark_all_as_read.js.erb @@ -0,0 +1 @@ +location.reload(); diff --git a/config/routes.rb b/config/routes.rb index 8e83931bd..88f44f2b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,6 +72,7 @@ Danbooru::Application.routes.draw do resources :dmails do collection do get :search + post :mark_all_as_read end end resource :dtext_preview, :only => [:create]