orbit er_email module

This commit is contained in:
spen 2014-03-07 10:44:24 +08:00
parent 34a13479d4
commit 83d680b547
8 changed files with 68 additions and 149 deletions

View File

@ -7,7 +7,6 @@ class Panel::ErEmail::BackEnd::ApprovalsController < OrbitBackendController
def preview_and_approve def preview_and_approve
email_group_data
@email_er = EmailEr.find params[:email_er_id] @email_er = EmailEr.find params[:email_er_id]
end end
@ -73,39 +72,23 @@ class Panel::ErEmail::BackEnd::ApprovalsController < OrbitBackendController
@user = User.find(email_er.create_user_id) @user = User.find(email_er.create_user_id)
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
if !@group_mail.join.blank? if !@group_mail.join.blank?
@mail_content = { @mail_content = {
"lang" => I18n.locale,
"text" => email_er.mail_content "text" => email_er.mail_content
} }
@mail_cron = { @mail_cron = {
:mail_from_app => 'er_email', :mail_from_app => 'er_email',
:mail_from => @user.email, # :mail_from => @user.email,
:mail_reply_to => @user.email, # :mail_reply_to => @user.email,
:mail_subject => email_er.mail_subject, :mail_subject => email_er.mail_subject,
:mail_to => @group_mail.join(','), :mail_to => @group_mail.join(','),
:mail_content => @mail_content , :mail_content => @mail_content ,
# :mail_sentdate => email_er.mail_sentdate, :mail_sentdate => email_er.mail_sentdate,
:mail_sentdate => DateTime.now,
:create_user_id => email_er.create_user_id, :create_user_id => email_er.create_user_id,
:update_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 @mail_cron.save
MailCron.send_mail_now(@mail_cron.id)
end end
end end
def email_group_data
@email_group_data = EmailEr.email_group_data
end
end end

View File

@ -17,7 +17,6 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
end end
def index def index
email_group_data
@categories = get_categories_for_index @categories = get_categories_for_index
@statuses = get_statuses @statuses = get_statuses
@ -41,8 +40,6 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# GET /email_ers/1.xml # GET /email_ers/1.xml
def show def show
email_group_data
@item = Page.find(params[:page_id]) rescue nil @item = Page.find(params[:page_id]) rescue nil
if params[:preview] == "true" if params[:preview] == "true"
@ -73,8 +70,6 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# GET /email_ers/new.xml # GET /email_ers/new.xml
def new def new
email_group_data
@email_er = EmailEr.new(:mail_sentdate => DateTime.now) @email_er = EmailEr.new(:mail_sentdate => DateTime.now)
respond_to do |format| respond_to do |format|
@ -86,10 +81,10 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# GET /email_ers/1/edit # GET /email_ers/1/edit
def edit def edit
email_group_data
@email_er = EmailEr.find(params[:id]) @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 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)) 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 # POST /email_ers.xml
def create 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 = EmailEr.new(params[:email_er])
@email_er.create_user_id = current_user.id @email_er.create_user_id = current_user.id
@ -151,9 +147,10 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
# PUT /email_ers/1.xml # PUT /email_ers/1.xml
def update def update
email_group_data
@email_er = EmailEr.find(params[:id]) @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 @email_er.update_user_id = current_user.id
@ -235,45 +232,33 @@ class Panel::ErEmail::BackEnd::EmailErsController < OrbitBackendController
if !test_send 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 @mail_sentdate = email_er.mail_sentdate
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
else else
@group_mail = [@user.email] @group_mail = [@user.email]
@mail_sentdate = DateTime.now
end end
if !@group_mail.join.blank? if !@group_mail.join.blank?
@mail_content = { @mail_content = {
"lang" => I18n.locale,
"text" => email_er.mail_content "text" => email_er.mail_content
} }
@mail_cron = { @mail_cron = {
:mail_from_app => 'er_email', :mail_from_app => 'er_email',
:mail_from => @user.email, # :mail_from => @user.email,
:mail_reply_to => @user.email, # :mail_reply_to => @user.email,
:mail_subject => email_er.mail_subject, :mail_subject => email_er.mail_subject,
:mail_to => @group_mail.join(','), :mail_to => @group_mail.join(','),
:mail_content => @mail_content , :mail_content => @mail_content ,
# :mail_sentdate => email_er.mail_sentdate, :mail_sentdate => @mail_sentdate,
:mail_sentdate => DateTime.now,
:create_user_id => email_er.create_user_id, :create_user_id => email_er.create_user_id,
:update_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 @mail_cron.save
MailCron.send_mail_now(@mail_cron.id) MailCron.send_mail_now(@mail_cron.id) if test_send
end end

View File

@ -17,6 +17,9 @@ class EmailEr
field :mail_subject field :mail_subject
field :mail_sentdate , :type => DateTime field :mail_sentdate , :type => DateTime
field :mail_content field :mail_content
field :email_user_ids
field :other_mailaddress
field :create_user_id field :create_user_id
field :update_user_id field :update_user_id
@ -27,9 +30,6 @@ class EmailEr
field :not_checked_reason field :not_checked_reason
field :email_group, :type => Array, default: []
field :other_mailaddress
scope :can_display,where(is_hidden: false) scope :can_display,where(is_hidden: false)
has_many :email_er_files, :autosave => true, :dependent => :destroy 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) !self.is_pending && self.is_rejected && (self.is_rejected == true)
end 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("<br />").html_safe
end
def to_preview 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") 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 preview_object
end end
protected def get_email_users
User.find(self.email_user_ids) rescue []
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')}
}
end end
end end

View File

@ -15,9 +15,9 @@
<br /> <br />
<% end %> <% end %>
<% if !@email_er.email_group.blank? %> <% if !@email_er.email_user_ids.blank? || !@email_er.other_mailaddress.blank? %>
<%= label_tag 'group_mail' %> <%= label_tag t('er_email.mail_to') %>
<%= @email_er.get_email_group_data(@email_group_data) %> <%= MailCron.get_send_group_mail(@email_er.email_user_ids , @email_er.other_mailaddress).join("<br />").html_safe %>
<% end %> <% end %>
</div> </div>
<div class="modal-right"> <div class="modal-right">

View File

@ -5,10 +5,13 @@
<%= stylesheet_link_tag "lib/main-list" %> <%= stylesheet_link_tag "lib/main-list" %>
<% end %> <% end %>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %> <%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/modal-preview" %> <%= javascript_include_tag "lib/modal-preview" %>
<%= javascript_include_tag "lib/file-type" %> <%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %> <%= javascript_include_tag "lib/module-area" %>
<%= javascript_include_tag "member-selection" %>
<% end %> <% end %>
<%= f.error_messages %> <%= f.error_messages %>
@ -23,9 +26,6 @@
<li class="active"> <li class="active">
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a> <a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
</li> </li>
<li>
<a href="#mail-group" data-toggle="tab"><%= t('er_email.email_group')%></a>
</li>
</ul> </ul>
<!-- Module --> <!-- Module -->
@ -42,25 +42,19 @@
</div> </div>
</div> </div>
</div> <!-- Mail Sentdate -->
<div class="control-group">
<!-- Mail Group Module --> <label class="control-label muted"><%= t("er_email.mail_sentdate") %></label>
<div class="tab-pane fade" id="mail-group"> <div class="controls">
<%= f.datetime_picker :mail_sentdate, :no_label => true %>
</div>
</div>
<!-- Mail Group --> <!-- Mail Group -->
<div class="control-group"> <div class="control-group">
<label class="control-label muted"><%= t("er_email.email_group") %></label> <label class="control-label muted"><%= t("er_email.mail_to") %></label>
<div class="controls"> <div class="controls">
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'email_er[email_user_ids][]', users: @email_users} %>
<% @email_group_data.collect do |k,v| %>
<label class="checkbox inline">
<%= check_box_tag 'email_er[email_group][]', k, (@email_er.email_group.nil? ? false : @email_er.email_group.include?(k)), :id => "field-#{k}" %> <%= v["name"] %>
<%= hidden_field_tag 'email_er[email_group][]', '' %>
</label>
<% end if !@email_group_data.blank? %>
</div> </div>
</div> </div>
<div class="control-group"> <div class="control-group">

View File

@ -7,6 +7,7 @@
objects @email_ers objects @email_ers
quick_edit_link type: 'edit', quick_edit_link type: 'edit',
link: 'edit_panel_er_email_back_end_email_er_path' link: 'edit_panel_er_email_back_end_email_er_path'
quick_edit_link type: 'detail'
quick_edit_link type: 'test_send_email', quick_edit_link type: 'test_send_email',
define_link: 'test_send_email_panel_er_email_back_end_email_ers_path(:id=>object.id)', define_link: 'test_send_email_panel_er_email_back_end_email_ers_path(:id=>object.id)',
condition_option: 'object.is_pending', condition_option: 'object.is_pending',
@ -17,7 +18,7 @@
quick_edit_link type: 'email_resend', quick_edit_link type: 'email_resend',
define_link: 'email_resend_panel_er_email_back_end_email_ers_path(:id=>object.id)', define_link: 'email_resend_panel_er_email_back_end_email_ers_path(:id=>object.id)',
condition_option: 'object.is_checked and !object.is_rejected', condition_option: 'object.is_checked and !object.is_rejected',
translation: 'er_email.email_resend' translation: 'er_email.mail_resend'
quick_edit_link type: 'approval', quick_edit_link type: 'approval',
link: 'panel_er_email_back_end_email_er_approval_preview_path' link: 'panel_er_email_back_end_email_er_approval_preview_path'
quick_edit_link type: 'reject_reason' quick_edit_link type: 'reject_reason'
@ -25,23 +26,32 @@
db_field: @statuses, db_field: @statuses,
translation: 'status', translation: 'status',
hide: 'phone', hide: 'phone',
sort: 'status' sort: 'status',
header_class: 'span2'
field type: 'associated', field type: 'associated',
db_field: 'category', db_field: 'category',
model_field: 'title', model_field: 'title',
translation: 'category', translation: 'category',
hide: 'phone', hide: 'phone',
sort: 'category' sort: 'category',
header_class: 'span2'
field db_field: 'mail_subject', field db_field: 'mail_subject',
translation: 'er_email.mail_subject', translation: 'er_email.mail_subject',
sort: 'mail_subject', sort: 'mail_subject',
quick_edit: true, quick_edit: true,
header_class: 'span5' header_class: 'span8'
field db_field: 'email_group', field db_field: 'email_user_ids',
translation: 'er_email.email_group', hide: 'all',
display_option: 'object.get_email_group_data(@email_group_data)', translation: 'er_email.mail_to',
display_option: '"<br />#{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', hide: 'phone',
sort: 'email_group' sort: 'create_user_id'
footer link: 'new_panel_er_email_back_end_email_er_path' footer link: 'new_panel_er_email_back_end_email_er_path'
end %> end %>

View File

@ -10,18 +10,14 @@ en:
approve_email_er_fail: Approval Fail approve_email_er_fail: Approval Fail
approve_email_er_success: Approve Successfully approve_email_er_success: Approve Successfully
create_email_er_success: Create Successfully create_email_er_success: Create Successfully
email_resend: Resend mail_resend: Resend
test_send_email: Test Send Email test_send_email: Test Send Email
mail_subject: Mail Subject mail_subject: Mail Subject
mail_content: Mail Content mail_content: Mail Content
mail_sentdate: Email Time mail_sentdate: Email Time
email_group: Email Group mail_to: Email To
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
other_mailaddress: Other Email other_mailaddress: Other Email
other_mailaddress_note: Divide different email accounts with "," other_mailaddress_note: Divide different email accounts with ","
other_mailaddress_note_limit: maximum 1000 characters other_mailaddress_note_limit: maximum 1000 characters
email_file_limit: File upload size is limited to 1MB email_file_limit: File upload size is limited to 1MB
created_user: Creator

View File

@ -10,18 +10,14 @@ zh_tw:
approve_email_er_fail: 審核失敗 approve_email_er_fail: 審核失敗
approve_email_er_success: 審核成功 approve_email_er_success: 審核成功
create_email_er_success: 建立資料成功 create_email_er_success: 建立資料成功
email_resend: 重新寄送 mail_resend: 重新寄送
test_send_email: 測試寄信 test_send_email: 測試寄信
mail_subject: 主旨 mail_subject: 主旨
mail_content: 信件內容 mail_content: 信件內容
mail_sentdate: 寄送時間 mail_sentdate: 寄送時間
email_group: 寄送群組 mail_to: 寄送對象
other_mailaddress: 其他Mail other_mailaddress: 其他Mail
other_mailaddress_note: 輸入多組mail時,請用","逗號隔開 other_mailaddress_note: 輸入多組mail時,請用","逗號隔開
other_mailaddress_note_limit: 限制1000字元以內 other_mailaddress_note_limit: 限制1000字元以內
email_group_data_0: 全校教職員 email_file_limit: 檔案上傳容量限制為10MB
email_group_data_1: 大學部學生 created_user: 建立者
email_group_data_2: 日間部研究生
email_group_data_3: 進修部研究生
email_group_data_4: 其他
email_file_limit: 檔案上傳容量限制為10MB