changed emails to multilingual, url changed to open backend

This commit is contained in:
Harry Bomrah 2016-07-22 00:23:19 +08:00
parent 026fef47af
commit 5e762fa542
10 changed files with 43 additions and 17 deletions

View File

@ -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

View File

@ -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 = "<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.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 = "<h3>Hello #{name}</h3>,<p>#{current_user.name} #{t("announcement.submitted_new_announcement")} <a href='#{url}'> #{t("announcement.click_here_to_see")}</a></p>"
when "reapproval"
datatosend = "<h3>Hello #{name}</h3>,<p>#{current_user.name} #{t("announcement.updated_annoucement")} <a href='#{url}'> #{t("announcement.click_here_to_see")}</a></p>"
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

View File

@ -49,7 +49,7 @@
<li><a href="/admin/announcements/<%=b.id.to_s%>/edit"><%= t(:edit) %></a></li>
<li><a href="#" class="delete text-error" rel="/admin/announcements/<%=b.id.to_s%>"><%= t(:delete_) %></a></li>
<% if (!b.approved || b.reapproval) && user_can_approve? %>
<li><a href="<%= page_for_bulletin(b) %>" class="approval_button" data-id="<%= b.id.to_s %>" ><%= t("announcement.approve") %></a></li>
<li><a href="<%= page_for_bulletin(b) %>" class="approval_button" data-id="<%= b.id.to_s %>" ><%= t("announcement.approval_waiting") %></a></li>
<% end %>
<% end %>
</ul>

View File

@ -9,13 +9,21 @@
<%= render :partial=> "approval_modal" %>
<script type="text/javascript">
var modal = $("#approvalModal");
$(document).on("click", ".approval_button",function(){
var url = $(this).attr("href"),
modal = $("#approvalModal");
var url = $(this).attr("href");
modal.find("iframe").attr("src", url);
modal.find("#object_id").val($(this).data("id"));
modal.modal("show");
return false;
})
var params = getUrlVars();
console.log(params["url"])
if(typeof params["url"] != "undefined"){
modal.find("iframe").attr("src", params["url"]);
modal.find("#object_id").val(params["id"]);
modal.modal("show");
}
</script>
<% end %>

View File

@ -0,0 +1 @@
<%= @data["html"].html_safe %>

View File

@ -1,3 +0,0 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p><%= @data["submitter"] %> submitted a new announcement.
<a href="<%= @data['url'] %>" > Please click here to view the announcement.</a>

View File

@ -1,3 +1,3 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p><%= @data["submitter"] %> updated the announcement.
<a href="<%= @data['url'] %>" > Please click here to view the annoucement.</a>
<p><%= @data["submitter"] %> <%= t("announcement.updated_annoucement") %>
<a href="<%= @data['url'] %>" ><%= t("announcement.click_here_to_see") %></a>

View File

@ -1,3 +1,3 @@
<h3>Hello <%= @data["name"] %>,</h3>
<p><%= @data["rejector"] %> has rejected your announcement<%= @data["reason"].nil? || @data["reason"] == "" ? "." : ", because #{@data["reason"]}" %></p>
<a href="<%= @data['url'] %>" > Please click here to view the annoucement.</a>
<p><%= @data["rejector"] %> <%= t("annoucement.rejected_annoucement") %> : <%= @data["reason"].nil? || @data["reason"] == "" ? "" : "#{@data["reason"]}" %></p>
<a href="<%= @data['url'] %>" ><%= t("announcement.click_here_to_see") %></a>

View File

@ -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

View File

@ -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: 建立公告成功