2009-01-06 11:49:19 +01:00
|
|
|
class MessagesController < ApplicationController
|
2009-01-15 18:26:37 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Renders the "inbox" action.
|
|
|
|
def index
|
2009-02-18 01:06:35 +01:00
|
|
|
@messages = Message.all :order => 'created_at DESC', :limit => 100
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
2009-01-15 18:26:37 +01:00
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# Creates a new message object.
|
|
|
|
def new
|
|
|
|
@message = Message.new
|
|
|
|
end
|
|
|
|
|
|
|
|
# Creates a new message.
|
|
|
|
def create
|
2009-01-15 18:26:37 +01:00
|
|
|
@message = @current_user.send_messages.new(params[:message])
|
|
|
|
if @message.save
|
|
|
|
flash[:notice] = "Nachricht ist gespeichert und wird versendet."
|
|
|
|
redirect_to messages_path
|
2009-01-06 11:49:19 +01:00
|
|
|
else
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Shows a single message.
|
|
|
|
def show
|
2009-01-15 18:26:37 +01:00
|
|
|
@message = Message.find(params[:id])
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Replys to the message specified through :id.
|
|
|
|
def reply
|
|
|
|
message = Message.find(params[:id])
|
2009-01-15 18:26:37 +01:00
|
|
|
@message = Message.new(:recipient => message.sender, :subject => "Re: #{message.subject}")
|
|
|
|
@message.body = "#{message.sender.nick} schrieb am #{I18n.l(message.created_at.to_date)} um #{I18n.l(message.created_at, :format => :time)}:\n"
|
|
|
|
message.body.each_line{|l| @message.body += "> #{l}"}
|
|
|
|
render :action => 'new'
|
2009-01-06 11:49:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
# Shows new-message form with the recipient user specified through :id.
|
|
|
|
def user
|
|
|
|
if (recipient = User.find(params[:id]))
|
2009-01-15 18:26:37 +01:00
|
|
|
@message = Message.new(:recipient => recipient)
|
2009-01-06 11:49:19 +01:00
|
|
|
render :action => 'new'
|
|
|
|
else
|
2009-01-15 18:26:37 +01:00
|
|
|
flash[:error] = 'Unbekannte_r EmpfängerIn.'
|
2009-01-06 11:49:19 +01:00
|
|
|
redirect_to :action=> 'index'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Shows new-message form with the recipient user specified through :id.
|
|
|
|
def group
|
2009-01-15 18:26:37 +01:00
|
|
|
group = Group.find(params[:id], :include => :memberships)
|
|
|
|
if (group && !group.memberships.empty?)
|
|
|
|
@message = Message.new(:group_id => group.id)
|
2009-01-06 11:49:19 +01:00
|
|
|
render :action => 'new'
|
|
|
|
else
|
2009-01-15 18:26:37 +01:00
|
|
|
flash[:error] = 'Empfängergruppe ist unbekannt oder hat keine Mitglieder.'
|
2009-01-06 11:49:19 +01:00
|
|
|
redirect_to :action=> 'index'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Auto-complete for recipient user list.
|
2009-01-15 18:26:37 +01:00
|
|
|
def auto_complete_for_message_recipients_nicks
|
|
|
|
@users = User.find(:all,
|
|
|
|
:conditions => ['LOWER(nick) LIKE ?', '%' + params[:message][:recipients_nicks].downcase + '%'],
|
|
|
|
:order => :nick, :limit => 8)
|
2009-01-06 11:49:19 +01:00
|
|
|
render :partial => '/shared/auto_complete_users'
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns list of all users as auto-completion hint.
|
|
|
|
def user_list
|
|
|
|
@users = User.find(:all, :order => :nick)
|
|
|
|
render :partial => '/shared/auto_complete_users'
|
|
|
|
end
|
|
|
|
end
|