Browse files

Message layout improvements and remove all feature

  • Loading branch information...
1 parent cd65b73 commit 3beec27d607af30ded80e688fbbeb436bff85c64 @mutle committed Dec 28, 2012
View
7 app/assets/stylesheets/common.css
@@ -91,8 +91,13 @@ ul#message_list {
padding: 0px;
}
+ul#message_list .header {
+ font-weight: bold;
+ line-height: 2em;
+}
+
.message_unread {
- font_weight: bold;
+ font-weight: bold;
}
.messages_who {
View
9 app/controllers/messages_controller.rb
@@ -43,4 +43,13 @@ def create
end
end
+ def destroy_all
+ @incoming_messages = Message.incoming_messages_from_user(current_user)
+ @incoming_messages.destroy_all
+ @outgoing_messages = Message.outgoing_messages_from_user(current_user)
+ @outgoing_messages.destroy_all
+ flash[:notice] = "All mesages removed..."
+ redirect_to messages_path
+ end
+
end
View
3 app/models/message.rb
@@ -6,6 +6,9 @@ class Message < ActiveRecord::Base
belongs_to :user
belongs_to :sender, :class_name => "User"
+
+ scope :incoming_messages_from_user, lambda { |u| where(:user_id => u.id).order("created_at DESC") }
+ scope :outgoing_messages_from_user, lambda { |u| where(:sender_id => u.id).order("created_at DESC") }
# validates_associated :sender, :user
View
3 app/views/layouts/application.html.haml
@@ -32,6 +32,7 @@
%ul#menu
%li= link_to "Settings", edit_user_path(current_user)
%li= link_to "Stylesheets", stylesheets_path
- %li= link_to "Inbox (#{current_user.number_unread_messages})", inbox_messages_path
+ -n = current_user.number_unread_messages
+ %li= link_to "#{'<strong>' if n > 0}Inbox (#{n})#{'</strong>' if n > 0}".html_safe, inbox_messages_path
%li= link_to "Logout", session_path, :method => :delete
=yield
View
8 app/views/messages/_navigation.html.haml
@@ -14,8 +14,10 @@
=link_to "Sent", sent_messages_path
-if @active_menu == :new
%li#messages_navigation_new.messages_active_menu
- =link_to "New message", :controller => 'messages', :action => 'new'
+ =link_to "New message", new_message_path
-else
%li#messages_navigation_new
- =link_to "New message", :controller => 'messages', :action => 'new'
- .clear
+ =link_to "New message", new_message_path
+ %li#messages_navigation_remove_all
+ =link_to "Remove all messages", destroy_all_messages_path, :method => :delete, :confirm => "Are you sure you want to remove all of your messages?"
+ .clear
View
9 app/views/messages/index.html.haml
@@ -1,6 +1,13 @@
%h2 Inbox
=render :partial => "navigation"
%ul#message_list
+ %li.header
+ .messages_who
+ From
+ .messages_date
+ Date
+ .messages_subject
+ Subject
-@incoming_messages.each do |message|
%li{:class => "#{'message_unread' if message.status == Message::STATUS_UNREAD}"}
- =render :partial => message, :locals => {:inbox => true}
+ =render :partial => message, :locals => {:inbox => true}
View
1 config/routes.rb
@@ -40,6 +40,7 @@
collection do
get :inbox
get :sent
+ delete :destroy_all
end
end

0 comments on commit 3beec27

Please sign in to comment.