Added email reminder for bulletin
This commit is contained in:
parent
758ceaf5e3
commit
0e5909c1f5
|
@ -1,3 +1,4 @@
|
|||
# encoding: utf-8
|
||||
class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
||||
# include OrbitControllerLib::DivisionForDisable
|
||||
|
||||
|
@ -48,7 +49,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
|||
# GET /bulletins/new.xml
|
||||
def new
|
||||
if(session[:in_validate_object].blank?)
|
||||
@bulletin = Bulletin.new(:postdate => DateTime.now)
|
||||
@bulletin = Bulletin.new(:postdate => DateTime.now, :email_sentdate => DateTime.now)
|
||||
else
|
||||
@bulletin = session[:in_validate_object]
|
||||
session[:in_validate_object] = {}
|
||||
|
@ -65,6 +66,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
|||
# GET /bulletins/1/edit
|
||||
def edit
|
||||
@bulletin = Bulletin.find(params[:id])
|
||||
@email_users = @bulletin.get_email_users
|
||||
@tags = get_tags
|
||||
is_authorized_sub_manager = @bulletin.category.auth_sub_manager.authorized_user_ids rescue nil
|
||||
|
||||
|
@ -83,6 +85,10 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
|||
# POST /bulletins.xml
|
||||
def create
|
||||
@tags = get_tags
|
||||
|
||||
params[:bulletin][:email_user_ids] = params[:bulletin][:email_user_ids].uniq
|
||||
params[:bulletin][:email_user_ids].delete('')
|
||||
|
||||
@bulletin = Bulletin.new(params[:bulletin])
|
||||
@bulletin.deadline = nil if (@bulletin.deadline < @bulletin.postdate rescue nil)
|
||||
|
||||
|
@ -97,6 +103,14 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
|||
respond_to do |format|
|
||||
if @bulletin.save
|
||||
|
||||
if @bulletin.email_sent == true && (is_manager? || is_admin?)
|
||||
send_email_data(@bulletin)
|
||||
|
||||
@bulletin.email_sent = false
|
||||
@bulletin.save
|
||||
end
|
||||
|
||||
|
||||
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('announcement.create_bulletin_success')) }
|
||||
format.xml { render :xml => @bulletin, :status => :created, :location => @bulletin }
|
||||
# format.js
|
||||
|
@ -122,11 +136,23 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
|||
|
||||
def update
|
||||
@bulletin = Bulletin.find(params[:id])
|
||||
|
||||
params[:bulletin][:tag_ids] = (params[:bulletin][:tag_ids] ? params[:bulletin][:tag_ids] : [])
|
||||
|
||||
params[:bulletin][:email_user_ids] = params[:bulletin][:email_user_ids].uniq
|
||||
params[:bulletin][:email_user_ids].delete('')
|
||||
|
||||
delete_out_invalid_date_from_params
|
||||
respond_to do |format|
|
||||
if @bulletin.update_attributes(params[:bulletin])
|
||||
|
||||
if @bulletin.email_sent == true && (is_manager? || is_admin?)
|
||||
send_email_data(@bulletin)
|
||||
|
||||
@bulletin.email_sent = false
|
||||
@bulletin.save
|
||||
end
|
||||
|
||||
format.html { redirect_to(panel_announcement_back_end_bulletins_url, :notice => t('bulletin.update_bulletin_success')) }
|
||||
format.js { render 'toggle_enable' }
|
||||
format.xml { head :ok }
|
||||
|
@ -164,6 +190,45 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
|
|||
|
||||
protected
|
||||
|
||||
def send_email_data(bulletin)
|
||||
|
||||
@site = Site.first
|
||||
@user = User.find(bulletin.create_user_id)
|
||||
@host = request.host_with_port
|
||||
|
||||
@group_mail = MailCron.get_send_group_mail( bulletin.email_user_ids , bulletin.other_mailaddress )
|
||||
|
||||
if !@group_mail.join.blank?
|
||||
|
||||
@mail_content = {
|
||||
"host" => @host,
|
||||
"lang" => I18n.locale,
|
||||
"site_title" => @site.title,
|
||||
"title" => bulletin.title,
|
||||
"template" => 'announcement_mailer/cron_mail',
|
||||
"url" => "http://#{@host}#{panel_announcement_front_end_bulletin_path(bulletin, :category_id => bulletin.category.id)}"
|
||||
}
|
||||
|
||||
@mail_cron = {
|
||||
:mail_from_app => 'announcement',
|
||||
# :mail_from => @user.email,
|
||||
# :mail_reply_to => @user.email,
|
||||
:mail_subject => "#{t("announcement.mail_subject",:site_title => @site.title)}:#{bulletin.title}",
|
||||
:mail_to => @group_mail.join(','),
|
||||
:mail_content => @mail_content ,
|
||||
:mail_sentdate => bulletin.email_sentdate,
|
||||
:create_user_id => bulletin.create_user_id,
|
||||
:update_user_id => bulletin.create_user_id
|
||||
}
|
||||
|
||||
@mail_cron = MailCron.new(@mail_cron)
|
||||
|
||||
@mail_cron.save
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def delete_out_invalid_date_from_params
|
||||
if((params[:bulletin]["deadline(1i)"] && params[:bulletin]["deadline(1i)"].blank?) or (params[:bulletin]["deadline(2i)"] && params[:bulletin]["deadline(2i)"].blank?) or (params[:bulletin]["deadline(3i)"] && params[:bulletin]["deadline(3i)"].blank?))
|
||||
params[:bulletin].delete("deadline(1i)")
|
||||
|
|
|
@ -29,6 +29,11 @@ class Bulletin
|
|||
|
||||
field :public, :type => Boolean, :default => true
|
||||
|
||||
field :email_sent, :type => Boolean, :default => false
|
||||
field :email_sentdate , :type => DateTime
|
||||
field :email_user_ids
|
||||
field :other_mailaddress
|
||||
|
||||
mount_uploader :image, ImageUploader
|
||||
|
||||
has_many :bulletin_links, :autosave => true, :dependent => :destroy
|
||||
|
@ -149,6 +154,9 @@ class Bulletin
|
|||
preview_object
|
||||
end
|
||||
|
||||
def get_email_users
|
||||
User.find(self.email_user_ids) rescue []
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
<% # encoding: utf-8 %>
|
||||
|
||||
<% I18n.locale = @data.mail_content["lang"] %>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<div style="text-ident:20px">
|
||||
</div>
|
||||
|
||||
<%= t('announcement.mail_hi') %> <br /><br />
|
||||
<%= t('announcement.mail_url_view') %> <br /><br />
|
||||
<a href="<%= @data.mail_content["url"] %>" target="_blank"> <%= @data.mail_content["title"] %> </a> <br /><br />
|
||||
</div>
|
||||
<span style="color:#555">--<br />
|
||||
<%= t('announcement.mail_source') %> :<a href="http://<%= @data.mail_content["host"] %>" target="_blank"> <%= @data.mail_content["site_title"] %> </a><br />
|
||||
<%= t('announcement.mail_time') %> <%= DateTime.now %>
|
||||
</span>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
<%= javascript_include_tag "lib/modal-preview" %>
|
||||
<%= javascript_include_tag "lib/file-type" %>
|
||||
<%= javascript_include_tag "lib/module-area" %>
|
||||
<%= javascript_include_tag "member-selection" %>
|
||||
<% end %>
|
||||
|
||||
<%= f.error_messages %>
|
||||
|
@ -34,6 +35,9 @@
|
|||
<li>
|
||||
<a href="#imageupload" data-toggle="tab"><%= t(:image) %></a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#mail-group" data-toggle="tab"><%= t('announcement.email_reminder')%></a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Module -->
|
||||
|
@ -140,6 +144,46 @@
|
|||
|
||||
</div>
|
||||
|
||||
<!-- Mail Group Module -->
|
||||
<div class="tab-pane fade" id="mail-group">
|
||||
|
||||
<!-- Mail Group -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("announcement.email_to") %></label>
|
||||
<div class="controls">
|
||||
|
||||
<label class="checkbox inline">
|
||||
<%= check_box_tag('bulletin[email_sent]', '1', (!@bulletin.email_sent.blank? ? true : false), :id=>'remind-check') %><%= t('announcement.activate_email_reminder')%>
|
||||
</label>
|
||||
|
||||
<div class="content-box">
|
||||
<p>
|
||||
<%= render partial: 'admin/member_selects/email_selection_box', locals: {field: 'bulletin[email_user_ids][]', users: @email_users} %>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"></label>
|
||||
<div class="controls">
|
||||
<div class="content-box">
|
||||
<span class="help-block"><%= "#{t("announcement.other_mailaddress")}(#{t("announcement.other_mailaddress_note")})"%> </span>
|
||||
<%= f.text_area :other_mailaddress, :class=>"span12", :cols=>"25", :rows=>"10" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-box">
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("announcement.email_sentdate") %></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :email_sentdate, :no_label => true %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Language Tabs -->
|
||||
|
@ -301,6 +345,12 @@
|
|||
$(this).parents('.start-line').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('#remind-check').prop('checked') ? '':$('.content-box').addClass('hide')
|
||||
$('#remind-check').on('change', function() {
|
||||
$(this).prop('checked') ? $('.content-box').removeClass('hide'):$('.content-box').addClass('hide')
|
||||
})
|
||||
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
|
|
|
@ -37,6 +37,11 @@
|
|||
field type: 'tags',
|
||||
hide: 'all',
|
||||
sort: 'tags'
|
||||
field db_field: 'email_user_ids',
|
||||
hide: 'all',
|
||||
translation: 'announcement.email_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: 'update_user_id',
|
||||
model: User,
|
||||
|
|
|
@ -36,3 +36,15 @@ en:
|
|||
bulletins_and_web_links: Differential Nav.
|
||||
index: Index
|
||||
search: Search
|
||||
email_reminder: Email Reminder
|
||||
activate_email_reminder: Activate Email Reminder
|
||||
email_sentdate: Email Time
|
||||
email_to: Email To
|
||||
mail_subject: this is an announcement reminder from【%{site_title}】
|
||||
other_mailaddress: Other Email
|
||||
other_mailaddress_note: Divide different email accounts with ","
|
||||
mail_hi: Hi
|
||||
mail_url_view: This email is the reminder of an announcement, please click the link for the details
|
||||
mail_source: Source
|
||||
mail_time: Time
|
||||
image_upload_size_note: The following recommendations %{image_upload_size} upload size
|
||||
|
|
|
@ -39,3 +39,15 @@ zh_tw:
|
|||
index: 索引
|
||||
search: 搜尋
|
||||
more: 更多+
|
||||
email_reminder: 寄送提醒
|
||||
activate_email_reminder: 開啟寄送提醒
|
||||
email_sentdate: 寄送時間
|
||||
email_to: 寄送對象
|
||||
other_mailaddress: 其他Mail
|
||||
other_mailaddress_note: 輸入多組mail時,請用","逗號隔開
|
||||
mail_subject: 來自【%{site_title}】的公告事件提醒
|
||||
mail_hi: 您好
|
||||
mail_url_view: 此封信件為公告事件提醒,請點選以下連結詳細觀看
|
||||
mail_source: 來源
|
||||
mail_time: 時間
|
||||
image_upload_size_note: 建議檔案小於%{image_upload_size}
|
||||
|
|
Loading…
Reference in New Issue