diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index 8222198..6f1b36e 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -172,7 +172,7 @@ class Admin::AnnouncementsController < OrbitAdminController bulletin.rejected = true bulletin.reapproval = false bulletin.rejection_reason = params["reason"] - send_rejection_email(bulletin) rescue "" + send_rejection_email(bulletin) end bulletin.save redirect_to admin_announcements_path diff --git a/app/helpers/admin/announcements_helper.rb b/app/helpers/admin/announcements_helper.rb index 128fb3a..c55ad18 100644 --- a/app/helpers/admin/announcements_helper.rb +++ b/app/helpers/admin/announcements_helper.rb @@ -124,8 +124,9 @@ module Admin::AnnouncementsHelper if !user.nil? email = user.member_profile.email if !email.nil? && email != "" - url = page_for_bulletin(announcement) - mail = Email.new(:mail_to => email, :mail_subject => "Announcement rejected : #{announcement.title}.", :template => "email/rejection_email.html.erb", :template_data => {"url" => url, "rejector" => current_user.name, "name" => user.name, "reason" => announcement.rejection_reason}) + 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.deliver rescue nil end end @@ -136,20 +137,29 @@ module Admin::AnnouncementsHelper users = authorizations.collect do |auth| auth.user end + wg = Workgroup.where(:key => "admin").first + admins = User.where(:workgroup_id => wg.id) users.delete(nil) + users = users.concat(admins.to_a) users.each do |user| email = user.member_profile.email if !email.nil? && email != "" send_email(user.name, email, announcement, type) - sleep(1) + # sleep(1) end end end def send_email(name, useremail, announcement, type) - url = page_for_bulletin(announcement) - template = (type == "approval" ? "email/new_announcement_email.html.erb" : "email/reapproval_announcement_email.html.erb") - email = Email.new(:mail_to => useremail, :mail_subject => "New announcement : #{announcement.title}.", :template => template, :template_data => {"url" => url, "submitter" => current_user.name, "name" => name}) + 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 = "

Hello #{name}

,

#{current_user.name} #{t("announcement.submitted_new_announcement")} #{t("announcement.click_here_to_see")}

" + when "reapproval" + datatosend = "

Hello #{name}

,

#{current_user.name} #{t("announcement.updated_annoucement")} #{t("announcement.click_here_to_see")}

" + end + email = Email.new(:mail_to => useremail, :mail_subject => "New announcement waiting for approval 待審核公告 : #{announcement.title}.", :template => "email/announcement_email.html.erb", :template_data => {"html" => datatosend}) email.deliver rescue nil end diff --git a/app/views/admin/announcements/_index.html.erb b/app/views/admin/announcements/_index.html.erb index 48e7d37..d352938 100644 --- a/app/views/admin/announcements/_index.html.erb +++ b/app/views/admin/announcements/_index.html.erb @@ -49,7 +49,7 @@
  • <%= t(:edit) %>
  • <%= t(:delete_) %>
  • <% if (!b.approved || b.reapproval) && user_can_approve? %> -
  • <%= t("announcement.approve") %>
  • +
  • <%= t("announcement.approval_waiting") %>
  • <% end %> <% end %> diff --git a/app/views/admin/announcements/index.html.erb b/app/views/admin/announcements/index.html.erb index 6ae0abc..f6074c5 100644 --- a/app/views/admin/announcements/index.html.erb +++ b/app/views/admin/announcements/index.html.erb @@ -9,13 +9,21 @@ <%= render :partial=> "approval_modal" %> <% end %> \ No newline at end of file diff --git a/app/views/email/announcement_email.html.erb b/app/views/email/announcement_email.html.erb new file mode 100644 index 0000000..902acf0 --- /dev/null +++ b/app/views/email/announcement_email.html.erb @@ -0,0 +1 @@ +<%= @data["html"].html_safe %> \ No newline at end of file diff --git a/app/views/email/new_announcement_email.html.erb b/app/views/email/new_announcement_email.html.erb deleted file mode 100644 index e8e32c8..0000000 --- a/app/views/email/new_announcement_email.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

    Hello <%= @data["name"] %>,

    -

    <%= @data["submitter"] %> submitted a new announcement. - Please click here to view the announcement. \ No newline at end of file diff --git a/app/views/email/reapproval_announcement_email.html.erb b/app/views/email/reapproval_announcement_email.html.erb index dd1d1c7..2e1f89b 100644 --- a/app/views/email/reapproval_announcement_email.html.erb +++ b/app/views/email/reapproval_announcement_email.html.erb @@ -1,3 +1,3 @@

    Hello <%= @data["name"] %>,

    -

    <%= @data["submitter"] %> updated the announcement. - Please click here to view the annoucement. \ No newline at end of file +

    <%= @data["submitter"] %> <%= t("announcement.updated_annoucement") %> +<%= t("announcement.click_here_to_see") %> \ No newline at end of file diff --git a/app/views/email/rejection_email.html.erb b/app/views/email/rejection_email.html.erb index 8bc9867..187530d 100644 --- a/app/views/email/rejection_email.html.erb +++ b/app/views/email/rejection_email.html.erb @@ -1,3 +1,3 @@

    Hello <%= @data["name"] %>,

    -

    <%= @data["rejector"] %> has rejected your announcement<%= @data["reason"].nil? || @data["reason"] == "" ? "." : ", because #{@data["reason"]}" %>

    - Please click here to view the annoucement. \ No newline at end of file +

    <%= @data["rejector"] %> <%= t("annoucement.rejected_annoucement") %> : <%= @data["reason"].nil? || @data["reason"] == "" ? "" : "#{@data["reason"]}" %>

    +<%= t("announcement.click_here_to_see") %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 8a9879e..603f691 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -23,6 +23,11 @@ en: approval_setting: Approval Setting approve_bulletin_fail: Approval Fail approve_bulletin_success: Approve Successfully + approval_waiting: Approval + submitted_new_announcement: submitted a new announcement waiting for your approval. + click_here_to_see: Please click here to view the announcement. + rejected_annoucement: has rejected your announcement, because + updated_annoucement: updated the rejected announcement. bulletins: Bulletins categories: Categories create_bulletin_success: Create Bulletin Successfully diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 967ac30..c4c8d8f 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -23,6 +23,11 @@ zh_tw: approval_setting: 審核設定 approve_bulletin_fail: 審核失敗 approve_bulletin_success: 審核成功 + approval_waiting: 審核 + submitted_new_announcement: 送出了一個新的公告等待您的審核。 + click_here_to_see: 點選此處瀏覽該公告。 + rejected_annoucement: 未通過您的公告審核,原因為 + updated_annoucement: 重新編輯了被拒絕的公告 bulletins: 公告 categories: 類別 create_bulletin_success: 建立公告成功