Fix send email language error.

This commit is contained in:
BoHung Chiu 2020-05-04 23:14:02 +08:00
parent 69682e9b79
commit 8ae48585ed
2 changed files with 16 additions and 16 deletions

View File

@ -170,14 +170,14 @@ class Admin::AnnouncementsController < OrbitAdminController
if user_can_approve?
bulletin.approved = true
else
send_notification_mail_to_managers(bulletin,"approval")
send_notification_mail_to_managers(bulletin,"approval",I18n.locale)
end
else
bulletin.approved = true
end
bulletin.save
build_email(bulletin)
build_email(bulletin,I18n.locale)
redirect_to params['referer_url']
end
@ -192,7 +192,7 @@ class Admin::AnnouncementsController < OrbitAdminController
bulletin.rejected = true
bulletin.reapproval = false
bulletin.rejection_reason = params["reason"]
send_rejection_email(bulletin)
send_rejection_email(bulletin,I18n.locale)
end
bulletin.save
redirect_to admin_announcements_path
@ -233,11 +233,11 @@ class Admin::AnnouncementsController < OrbitAdminController
if bulletin.rejected
bulletin.reapproval = true
bulletin.save
send_notification_mail_to_managers(bulletin,"reapproval")
send_notification_mail_to_managers(bulletin,"reapproval",I18n.locale)
else
bulletin.save
end
build_email(bulletin)
build_email(bulletin,I18n.locale)
now_bulletin_page = Bulletin.where(:title.ne => "",:is_preview.in=>[false,nil])
.order_by(sort).map(&:id).map.with_index.select{|v,i| v==bulletin.id}[0][1] rescue nil
now_bulletin_page = now_bulletin_page.nil? ? 0 : ((now_bulletin_page+1).to_f/10).ceil
@ -331,7 +331,7 @@ class Admin::AnnouncementsController < OrbitAdminController
render :json=>{'destroy'=>bulletin.id.to_s}
end
def build_email(bulletin)
def build_email(bulletin,locale)
if bulletin.email_sent and !bulletin.email_addresses.blank?
if bulletin.email.nil?
email = Email.new
@ -343,14 +343,14 @@ class Admin::AnnouncementsController < OrbitAdminController
is_sent = bulletin.email.is_sent
is_sent = !params[:resend_mail].eql?("true") if !params[:resend_mail].blank?
doc = Nokogiri::HTML(bulletin.title)
doc = Nokogiri::HTML(bulletin.title_translations[locale])
title = doc.text.empty? ? 'no content' : doc.text
bulletin.email.update_attributes(
:create_user=>current_user,
:mail_sentdate=>bulletin.email_sentdate,
:module_app=>@module_app,
:mail_lang => I18n.locale,
:mail_lang => locale,
:mail_to=>bulletin.email_addresses,
:mail_subject=>title,
:template=>'announcements/email',

View File

@ -119,21 +119,21 @@ module Admin::AnnouncementsHelper
anns.save
end
def send_rejection_email(announcement)
def send_rejection_email(announcement,locale)
user = User.find(announcement.create_user_id) rescue nil
if !user.nil?
email = user.member_profile.email
if !email.nil? && email != ""
url = "http://#{request.host_with_port}/admin/announcements/#{announcement.id}/edit"
datatosend = "<h3>Hello #{user.name},</h3><p>#{current_user.name} #{t("announcement.rejected_annoucement")} : #{announcement.rejection_reason} <a href='#{url}'> #{t("announcement.click_here_to_see")}</a></p>"
mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected公告未通過 : #{announcement.title}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend})
mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected公告未通過 : #{announcement.title_translations[locale]}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend})
mail.save
mail.deliver rescue nil
end
end
end
def send_notification_mail_to_managers(announcement, type)
def send_notification_mail_to_managers(announcement, type, locale)
users = []
if @announcement_setting.email_to.include?("managers")
authorizations = Authorization.where(:module_app_id => @module_app.id)
@ -155,22 +155,22 @@ module Admin::AnnouncementsHelper
users.each do |user|
email = user.member_profile.email
if !email.nil? && email != ""
send_email(user.name, email, announcement, type)
send_email(user.name, email, announcement, type, locale)
# sleep(1)
end
end
end
def send_email(name, useremail, announcement, type)
def send_email(name, useremail, announcement, type, locale)
url = "http://#{request.host_with_port}/admin/announcements?url=#{page_for_bulletin(announcement).sub("http://" + request.host_with_port, "")}&id=#{announcement.id}"
case type
when "approval"
datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.submitted_new_announcement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>"
datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.submitted_new_announcement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title_translations[locale]} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>"
when "reapproval"
datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.updated_annoucement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>"
datatosend = "<h3>#{t("announcement.approval_mail_hi", :name => name)},</h3><p>#{t("announcement.updated_annoucement", :poster => current_user.name)}<br /><br />#{t("announcement.approval_announcement_title")} : #{announcement.title_translations[locale]} <br /> #{t("announcement.click_here_to_see")} : <a href='#{url}'> #{url} </a></p>"
end
email = Email.new(:mail_to => useremail, :mail_subject => " #{t("announcement.announcement_subject")} : #{announcement.title}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend})
email = Email.new(:mail_to => useremail, :mail_subject => " #{t("announcement.announcement_subject")} : #{announcement.title_translations[locale]}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend})
email.save
email.deliver rescue nil
end