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 %> - - - -
+ +
+ +
+ <%= f.datetime_picker :mail_sentdate, :no_label => true %> +
+
- +
- - <% @email_group_data.collect do |k,v| %> - - - - <% end if !@email_group_data.blank? %> - + <%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'email_er[email_user_ids][]', users: @email_users} %>
diff --git a/app/views/panel/er_email/back_end/email_ers/index.html.erb b/app/views/panel/er_email/back_end/email_ers/index.html.erb index 4de51f7..3eb401f 100644 --- a/app/views/panel/er_email/back_end/email_ers/index.html.erb +++ b/app/views/panel/er_email/back_end/email_ers/index.html.erb @@ -7,6 +7,7 @@ objects @email_ers quick_edit_link type: 'edit', link: 'edit_panel_er_email_back_end_email_er_path' + quick_edit_link type: 'detail' quick_edit_link type: 'test_send_email', define_link: 'test_send_email_panel_er_email_back_end_email_ers_path(:id=>object.id)', condition_option: 'object.is_pending', @@ -17,7 +18,7 @@ quick_edit_link type: 'email_resend', define_link: 'email_resend_panel_er_email_back_end_email_ers_path(:id=>object.id)', condition_option: 'object.is_checked and !object.is_rejected', - translation: 'er_email.email_resend' + translation: 'er_email.mail_resend' quick_edit_link type: 'approval', link: 'panel_er_email_back_end_email_er_approval_preview_path' quick_edit_link type: 'reject_reason' @@ -25,23 +26,32 @@ db_field: @statuses, translation: 'status', hide: 'phone', - sort: 'status' + sort: 'status', + header_class: 'span2' field type: 'associated', db_field: 'category', model_field: 'title', translation: 'category', hide: 'phone', - sort: 'category' + sort: 'category', + header_class: 'span2' field db_field: 'mail_subject', translation: 'er_email.mail_subject', sort: 'mail_subject', quick_edit: true, - header_class: 'span5' - field db_field: 'email_group', - translation: 'er_email.email_group', - display_option: 'object.get_email_group_data(@email_group_data)', + header_class: 'span8' + field db_field: 'email_user_ids', + hide: 'all', + translation: 'er_email.mail_to', + display_option: '"
#{MailCron.get_send_group_mail(object.email_user_ids , object.other_mailaddress).join(", ").html_safe}"', + sort: 'email_user_ids' + field type: 'id', + db_field: 'create_user_id', + model: User, + model_field: 'name', + translation: 'er_email.created_user', hide: 'phone', - sort: 'email_group' + sort: 'create_user_id' footer link: 'new_panel_er_email_back_end_email_er_path' end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a44d4f0..90a428c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -10,18 +10,14 @@ en: approve_email_er_fail: Approval Fail approve_email_er_success: Approve Successfully create_email_er_success: Create Successfully - email_resend: Resend + mail_resend: Resend test_send_email: Test Send Email mail_subject: Mail Subject mail_content: Mail Content mail_sentdate: Email Time - email_group: Email Group - email_group_data_0: All Faculty - email_group_data_1: Undergraduates - email_group_data_2: Postgraduates - email_group_data_3: Continuing Ed. Postgraduates - email_group_data_4: Other + mail_to: Email To other_mailaddress: Other Email other_mailaddress_note: Divide different email accounts with "," other_mailaddress_note_limit: maximum 1000 characters - email_file_limit: File upload size is limited to 1MB \ No newline at end of file + email_file_limit: File upload size is limited to 1MB + created_user: Creator \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 1553eeb..cc608f9 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -10,18 +10,14 @@ zh_tw: approve_email_er_fail: 審核失敗 approve_email_er_success: 審核成功 create_email_er_success: 建立資料成功 - email_resend: 重新寄送 + mail_resend: 重新寄送 test_send_email: 測試寄信 mail_subject: 主旨 mail_content: 信件內容 mail_sentdate: 寄送時間 - email_group: 寄送群組 + mail_to: 寄送對象 other_mailaddress: 其他Mail other_mailaddress_note: 輸入多組mail時,請用","逗號隔開 other_mailaddress_note_limit: 限制1000字元以內 - email_group_data_0: 全校教職員 - email_group_data_1: 大學部學生 - email_group_data_2: 日間部研究生 - email_group_data_3: 進修部研究生 - email_group_data_4: 其他 - email_file_limit: 檔案上傳容量限制為10MB \ No newline at end of file + email_file_limit: 檔案上傳容量限制為10MB + created_user: 建立者 \ No newline at end of file