diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index 2ed68df..76dc253 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -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', diff --git a/app/helpers/admin/announcements_helper.rb b/app/helpers/admin/announcements_helper.rb index 847dd10..fc3f28e 100644 --- a/app/helpers/admin/announcements_helper.rb +++ b/app/helpers/admin/announcements_helper.rb @@ -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 = "

Hello #{user.name},

#{current_user.name} #{t("announcement.rejected_annoucement")} : #{announcement.rejection_reason} #{t("announcement.click_here_to_see")}

" - 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 = "

#{t("announcement.approval_mail_hi", :name => name)},

#{t("announcement.submitted_new_announcement", :poster => current_user.name)}

#{t("announcement.approval_announcement_title")} : #{announcement.title}
#{t("announcement.click_here_to_see")} : #{url}

" + datatosend = "

#{t("announcement.approval_mail_hi", :name => name)},

#{t("announcement.submitted_new_announcement", :poster => current_user.name)}

#{t("announcement.approval_announcement_title")} : #{announcement.title_translations[locale]}
#{t("announcement.click_here_to_see")} : #{url}

" when "reapproval" - datatosend = "

#{t("announcement.approval_mail_hi", :name => name)},

#{t("announcement.updated_annoucement", :poster => current_user.name)}

#{t("announcement.approval_announcement_title")} : #{announcement.title}
#{t("announcement.click_here_to_see")} : #{url}

" + datatosend = "

#{t("announcement.approval_mail_hi", :name => name)},

#{t("announcement.updated_annoucement", :poster => current_user.name)}

#{t("announcement.approval_announcement_title")} : #{announcement.title_translations[locale]}
#{t("announcement.click_here_to_see")} : #{url}

" 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