diff --git a/app/controllers/panel/er_email/back_end/approvals_controller.rb b/app/controllers/panel/er_email/back_end/approvals_controller.rb
index b000ee6..6a8ad60 100644
--- a/app/controllers/panel/er_email/back_end/approvals_controller.rb
+++ b/app/controllers/panel/er_email/back_end/approvals_controller.rb
@@ -7,7 +7,6 @@ class Panel::ErEmail::BackEnd::ApprovalsController < OrbitBackendController
def preview_and_approve
- email_group_data
@email_er = EmailEr.find params[:email_er_id]
end
@@ -73,39 +72,23 @@ class Panel::ErEmail::BackEnd::ApprovalsController < OrbitBackendController
@user = User.find(email_er.create_user_id)
- email_group_data
-
- @group_mail = Array.new
-
- email_er.email_group.each do |egroup|
-
- if @email_group_data.include?(egroup) and (egroup == 'e_0' or egroup == 'e_1' or egroup == 'e_2' or egroup == 'e_3')
-
- @group_mail << @email_group_data[egroup]["email"]
-
- elsif @email_group_data.include?(egroup) and egroup == 'e_4'
-
- @group_mail << email_er.other_mailaddress
-
- end
-
- end
+ @group_mail = MailCron.get_send_group_mail( email_er.email_user_ids , email_er.other_mailaddress )
if !@group_mail.join.blank?
@mail_content = {
+ "lang" => I18n.locale,
"text" => email_er.mail_content
}
@mail_cron = {
:mail_from_app => 'er_email',
- :mail_from => @user.email,
- :mail_reply_to => @user.email,
+ # :mail_from => @user.email,
+ # :mail_reply_to => @user.email,
:mail_subject => email_er.mail_subject,
:mail_to => @group_mail.join(','),
:mail_content => @mail_content ,
- # :mail_sentdate => email_er.mail_sentdate,
- :mail_sentdate => DateTime.now,
+ :mail_sentdate => email_er.mail_sentdate,
:create_user_id => email_er.create_user_id,
:update_user_id => email_er.create_user_id
}
@@ -131,16 +114,8 @@ class Panel::ErEmail::BackEnd::ApprovalsController < OrbitBackendController
@mail_cron.save
- MailCron.send_mail_now(@mail_cron.id)
-
end
end
- def email_group_data
-
- @email_group_data = EmailEr.email_group_data
-
- end
-
end
diff --git a/app/controllers/panel/er_email/back_end/email_ers_controller.rb b/app/controllers/panel/er_email/back_end/email_ers_controller.rb
index 056459d..d9456b5 100644
--- a/app/controllers/panel/er_email/back_end/email_ers_controller.rb
+++ b/app/controllers/panel/er_email/back_end/email_ers_controller.rb
@@ -17,7 +17,6 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
end
def index
- email_group_data
@categories = get_categories_for_index
@statuses = get_statuses
@@ -41,8 +40,6 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# GET /email_ers/1.xml
def show
-
- email_group_data
@item = Page.find(params[:page_id]) rescue nil
if params[:preview] == "true"
@@ -73,8 +70,6 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# GET /email_ers/new.xml
def new
- email_group_data
-
@email_er = EmailEr.new(:mail_sentdate => DateTime.now)
respond_to do |format|
@@ -86,10 +81,10 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# GET /email_ers/1/edit
def edit
- email_group_data
-
@email_er = EmailEr.find(params[:id])
+ @email_users = @email_er.get_email_users
+
is_authorized_sub_manager = @email_er.category.auth_sub_manager.authorized_user_ids rescue nil
if !(is_manager? || is_admin? || is_authorized_sub_manager.include?(current_user.id))
@@ -108,7 +103,8 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# POST /email_ers.xml
def create
- email_group_data
+ params[:email_er][:email_user_ids] = params[:email_er][:email_user_ids].uniq
+ params[:email_er][:email_user_ids].delete('')
@email_er = EmailEr.new(params[:email_er])
@email_er.create_user_id = current_user.id
@@ -151,9 +147,10 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# PUT /email_ers/1.xml
def update
- email_group_data
-
@email_er = EmailEr.find(params[:id])
+
+ params[:email_er][:email_user_ids] = params[:email_er][:email_user_ids].uniq
+ params[:email_er][:email_user_ids].delete('')
@email_er.update_user_id = current_user.id
@@ -235,45 +232,33 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
if !test_send
- email_group_data
+ @group_mail = MailCron.get_send_group_mail( email_er.email_user_ids , email_er.other_mailaddress )
- @group_mail = Array.new
-
- email_er.email_group.each do |egroup|
-
- if @email_group_data.include?(egroup) and (egroup == 'e_0' or egroup == 'e_1' or egroup == 'e_2' or egroup == 'e_3')
-
- @group_mail << @email_group_data[egroup]["email"]
-
- elsif @email_group_data.include?(egroup) and egroup == 'e_4'
-
- @group_mail << email_er.other_mailaddress
-
- end
-
- end
+ @mail_sentdate = email_er.mail_sentdate
else
@group_mail = [@user.email]
+ @mail_sentdate = DateTime.now
+
end
if !@group_mail.join.blank?
@mail_content = {
+ "lang" => I18n.locale,
"text" => email_er.mail_content
}
@mail_cron = {
:mail_from_app => 'er_email',
- :mail_from => @user.email,
- :mail_reply_to => @user.email,
+ # :mail_from => @user.email,
+ # :mail_reply_to => @user.email,
:mail_subject => email_er.mail_subject,
:mail_to => @group_mail.join(','),
:mail_content => @mail_content ,
- # :mail_sentdate => email_er.mail_sentdate,
- :mail_sentdate => DateTime.now,
+ :mail_sentdate => @mail_sentdate,
:create_user_id => email_er.create_user_id,
:update_user_id => email_er.create_user_id
}
@@ -299,7 +284,7 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
@mail_cron.save
- MailCron.send_mail_now(@mail_cron.id)
+ MailCron.send_mail_now(@mail_cron.id) if test_send
end
diff --git a/app/models/email_er.rb b/app/models/email_er.rb
index 99811b0..c3a01cc 100644
--- a/app/models/email_er.rb
+++ b/app/models/email_er.rb
@@ -17,6 +17,9 @@ class EmailEr
field :mail_subject
field :mail_sentdate , :type => DateTime
field :mail_content
+
+ field :email_user_ids
+ field :other_mailaddress
field :create_user_id
field :update_user_id
@@ -27,9 +30,6 @@ class EmailEr
field :not_checked_reason
- field :email_group, :type => Array, default: []
- field :other_mailaddress
-
scope :can_display,where(is_hidden: false)
has_many :email_er_files, :autosave => true, :dependent => :destroy
@@ -71,33 +71,6 @@ class EmailEr
!self.is_pending && self.is_rejected && (self.is_rejected == true)
end
- def get_email_group_data(email_group_data)
-
- group_mail = Array.new
-
- self.email_group.each do |egroup|
-
- if email_group_data.include?(egroup) and (egroup == 'e_0' or egroup == 'e_1' or egroup == 'e_2' or egroup == 'e_3')
-
- #group_mail << "#{email_group_data[egroup]["email"]}(#{email_group_data[egroup]["name"]})"
- group_mail << "#{email_group_data[egroup]["name"]}"
-
- elsif email_group_data.include?(egroup) and egroup == 'e_4'
-
- self.other_mailaddress.split(",").each do |otmail|
-
- group_mail << "#{otmail}(#{email_group_data[egroup]["name"]})"
-
- end
-
- end
-
- end
-
- group_mail.join("
").html_safe
-
- end
-
def to_preview
preview_object = Preview.new(:expired_at=>DateTime.now+30.minutes,:preview_at_link=>"panel_er_email_back_end_email_er_path",:object_class_type=>"EmailEr")
@@ -109,18 +82,8 @@ class EmailEr
preview_object
end
- protected
-
- def self.email_group_data
-
- @email_group_data = {
- 'e_0'=> {"name"=>I18n.t('er_email.email_group_data_0'), "email"=>"alluser@tea.ntue.edu.tw"},
- 'e_1'=> {"name"=>I18n.t('er_email.email_group_data_1'), "email"=>"allstu@tea.ntue.edu.tw"},
- 'e_2'=> {"name"=>I18n.t('er_email.email_group_data_2'), "email"=>"allgrad@tea.ntue.edu.tw"},
- 'e_3'=> {"name"=>I18n.t('er_email.email_group_data_3'), "email"=>"allad@tea.ntue.edu.tw"},
- 'e_4'=> {"name"=>I18n.t('er_email.email_group_data_4')}
- }
-
+ def get_email_users
+ User.find(self.email_user_ids) rescue []
end
end
\ No newline at end of file
diff --git a/app/views/panel/er_email/back_end/approvals/_modal_approve.html.erb b/app/views/panel/er_email/back_end/approvals/_modal_approve.html.erb
index 9729986..14dd306 100644
--- a/app/views/panel/er_email/back_end/approvals/_modal_approve.html.erb
+++ b/app/views/panel/er_email/back_end/approvals/_modal_approve.html.erb
@@ -15,9 +15,9 @@
<% end %>
- <% if !@email_er.email_group.blank? %>
- <%= label_tag 'group_mail' %>
- <%= @email_er.get_email_group_data(@email_group_data) %>
+ <% if !@email_er.email_user_ids.blank? || !@email_er.other_mailaddress.blank? %>
+ <%= label_tag t('er_email.mail_to') %>
+ <%= MailCron.get_send_group_mail(@email_er.email_user_ids , @email_er.other_mailaddress).join("
").html_safe %>
<% end %>