diff --git a/app/controllers/dmails_controller.rb b/app/controllers/dmails_controller.rb index 9b9e5cfc3..30759c3c5 100644 --- a/app/controllers/dmails_controller.rb +++ b/app/controllers/dmails_controller.rb @@ -14,6 +14,7 @@ class DmailsController < ApplicationController end def index + cookies[:dmail_folder] = params[:folder] @search = Dmail.visible.search(params[:search]) @dmails = @search.order("dmails.created_at desc").paginate(params[:page]) respond_with(@dmails) do |format| diff --git a/app/helpers/dmails_helper.rb b/app/helpers/dmails_helper.rb index 3583e9cf4..869a21820 100644 --- a/app/helpers/dmails_helper.rb +++ b/app/helpers/dmails_helper.rb @@ -1,2 +1,12 @@ module DmailsHelper + def dmails_current_folder_path + case cookies[:dmail_folder] + when "sent" + dmails_path(:search => {:owner_id => CurrentUser.id, :from_id => CurrentUser.id}, :folder => "sent") + when "all" + dmails_path(:search => {:owner_id => CurrentUser.id}, :folder => "all") + else + dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received") + end + end end diff --git a/app/views/dmails/_secondary_links.html.erb b/app/views/dmails/_secondary_links.html.erb index 4eac22d6b..2a46bc711 100644 --- a/app/views/dmails/_secondary_links.html.erb +++ b/app/views/dmails/_secondary_links.html.erb @@ -1,6 +1,6 @@ <% content_for(:secondary_links) do %> -
  • <%= link_to "All", dmails_path %>
  • +
  • <%= link_to "All", dmails_path(:search => {:owner_id => CurrentUser.id}, :folder => "all") %>
  • <%= link_to "Received", dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received") %>
  • <%= link_to "Sent", dmails_path(:search => {:owner_id => CurrentUser.id, :from_id => CurrentUser.id}, :folder => "sent") %>
  • <%= link_to "New", new_dmail_path %>
  • diff --git a/app/views/users/_secondary_links.html.erb b/app/views/users/_secondary_links.html.erb index 18bd6b648..3cd6bdb62 100644 --- a/app/views/users/_secondary_links.html.erb +++ b/app/views/users/_secondary_links.html.erb @@ -16,7 +16,7 @@
  • <%= link_to "Edit subscriptions", tag_subscriptions_path %>
  • <% end %>
  • <%= link_to "Profile", user_path(CurrentUser.user) %>
  • -
  • <%= link_to "Messages #{CurrentUser.dmail_count}", dmails_path(:search => {:owner_id => CurrentUser.id, :to_id => CurrentUser.id}, :folder => "received") %>
  • +
  • <%= link_to "Messages #{CurrentUser.dmail_count}", dmails_current_folder_path %>
  • <% else %>
  • <%= link_to "Send message", new_dmail_path(:dmail => {:to_id => @user.id}) %>
  • <% end %>