Send messages directly instead of using controller filter. Litte improvements to the messages lists.
This commit is contained in:
parent
de4f1d573b
commit
dd940fb414
6 changed files with 20 additions and 10 deletions
|
@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
#before_filter :select_foodcoop
|
#before_filter :select_foodcoop
|
||||||
before_filter :authenticate, :store_controller
|
before_filter :authenticate, :store_controller
|
||||||
after_filter :send_email_messages, :remove_controller
|
after_filter :remove_controller
|
||||||
|
|
||||||
# sends a mail, when an error occurs
|
# sends a mail, when an error occurs
|
||||||
# see plugins/exception_notification
|
# see plugins/exception_notification
|
||||||
|
@ -145,11 +145,6 @@ class ApplicationController < ActionController::Base
|
||||||
def remove_controller
|
def remove_controller
|
||||||
Thread.current[:application_controller] = nil
|
Thread.current[:application_controller] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sends any pending emails that were created during this request.
|
|
||||||
def send_email_messages
|
|
||||||
call_rake :send_emails unless Message.pending.empty?
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get supplier in nested resources
|
# Get supplier in nested resources
|
||||||
def find_supplier
|
def find_supplier
|
||||||
|
|
|
@ -14,6 +14,8 @@ class MessagesController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@message = @current_user.send_messages.new(params[:message])
|
@message = @current_user.send_messages.new(params[:message])
|
||||||
if @message.save
|
if @message.save
|
||||||
|
#FIXME: Send Mails wit ID instead of using message.state ...
|
||||||
|
call_rake :send_emails
|
||||||
flash[:notice] = "Nachricht ist gespeichert und wird versendet."
|
flash[:notice] = "Nachricht ist gespeichert und wird versendet."
|
||||||
redirect_to messages_path
|
redirect_to messages_path
|
||||||
else
|
else
|
||||||
|
|
|
@ -12,6 +12,13 @@ module MessagesHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_subject(message, length)
|
def format_subject(message, length)
|
||||||
truncate "<b>#{link_to(h(message.subject), message)}</b> <span style='color:grey'>#{h(message.body)}</span>", :length => length
|
if message.subject.length > length
|
||||||
|
subject = truncate(message.subject, :length => length)
|
||||||
|
body = ""
|
||||||
|
else
|
||||||
|
subject = message.subject
|
||||||
|
body = truncate(message.body, :length => length - subject.length)
|
||||||
|
end
|
||||||
|
"<b>#{link_to(h(subject), message)}</b> <span style='color:grey'>#{h(body)}</span>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,7 +78,11 @@ class Message < ActiveRecord::Base
|
||||||
for message in messages
|
for message in messages
|
||||||
for recipient in message.recipients
|
for recipient in message.recipients
|
||||||
if recipient.settings['messages.sendAsEmail'] == "1" && !recipient.email.blank?
|
if recipient.settings['messages.sendAsEmail'] == "1" && !recipient.email.blank?
|
||||||
Mailer.deliver_message(message, recipient)
|
begin
|
||||||
|
Mailer.deliver_message(message, recipient)
|
||||||
|
rescue
|
||||||
|
logger.warn "Deliver failed for #{recipient.nick}: #{recipient.email}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
message.update_attribute(:email_state, 1)
|
message.update_attribute(:email_state, 1)
|
||||||
|
|
|
@ -35,7 +35,9 @@
|
||||||
.box_title
|
.box_title
|
||||||
%h2 Neuste Nachrichten
|
%h2 Neuste Nachrichten
|
||||||
.column_content
|
.column_content
|
||||||
= render :partial => 'messages/messages', :locals => { :subject_length => 110 }
|
= render :partial => 'messages/messages', :locals => { :subject_length => 70 }
|
||||||
|
%br/
|
||||||
|
= link_to "Alle Nachrichten einsehen", messages_path
|
||||||
|
|
||||||
- if @ordergroup
|
- if @ordergroup
|
||||||
// Ordergroup overview
|
// Ordergroup overview
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
%p= link_to('Neue Nachricht', :action => 'new')
|
%p= link_to('Neue Nachricht', :action => 'new')
|
||||||
|
|
||||||
#messages
|
#messages
|
||||||
= render :partial => 'messages', :locals => { :subject_length => 200 }
|
= render :partial => 'messages', :locals => { :subject_length => 130 }
|
Loading…
Reference in a new issue