forked from spen/seminar
add the auto send email feature
This commit is contained in:
parent
1c3f2e7ec8
commit
446da7bf3a
|
@ -308,5 +308,24 @@ class Admin::SeminarsController < OrbitAdminController
|
|||
@seminar.seminar_signup_field_customs.create(seminar_signup_field_id:field.id)
|
||||
end
|
||||
end
|
||||
@email_set = []
|
||||
['signup','submission','add_file','edit_file'].each do |field_name|
|
||||
email_set = @seminar.seminar_email_sets.select{|v| v.field_name==field_name}
|
||||
if email_set.length==0
|
||||
title = Hash.new
|
||||
content = Hash.new
|
||||
now_locale = I18n.locale
|
||||
I18n.available_locales.each do |locale|
|
||||
I18n.locale = locale
|
||||
title[locale] = t("seminar.email_#{field_name}_success")
|
||||
content[locale] = t("seminar.email_#{field_name}_content")
|
||||
end
|
||||
I18n.locale = now_locale
|
||||
email_set = @seminar.seminar_email_sets.create(field_name:field_name,title:title,content:content)
|
||||
else
|
||||
email_set = email_set[0]
|
||||
end
|
||||
@email_set << email_set
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -134,7 +134,13 @@ class SeminarsController < ApplicationController
|
|||
@signup = SeminarSignup.where(email: params[:seminar_signup][:email], seminar_main_id: params[:seminar_signup][:seminar_main_id] ).first
|
||||
|
||||
@seminar_signup = SeminarSignup.new(seminar_signup_params)
|
||||
#if gotcha_valid?
|
||||
@seminar = SeminarMain.where(id:params[:seminar_signup][:seminar_main_id]).first
|
||||
if @seminar.seminar_signup_field_sets.count!=0
|
||||
flag = @seminar.seminar_signup_field_sets.select{|v| v.field_name=='recaptcha'}[0].disabled
|
||||
else
|
||||
flag = false
|
||||
end
|
||||
if gotcha_valid? || flag
|
||||
if @signup.blank? && @seminar_signup.save
|
||||
# if gotcha_valid? && @seminar_signup.save
|
||||
|
||||
|
@ -146,8 +152,10 @@ class SeminarsController < ApplicationController
|
|||
end
|
||||
if params['seminar_signup']['status']=='C'
|
||||
status_param = '&status='
|
||||
send_mail('submission',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id])
|
||||
else
|
||||
status_param = ''
|
||||
send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id])
|
||||
end
|
||||
redirect_to "#{params[:referer_url]}/?method=signup_ok#{status_param}"
|
||||
else
|
||||
|
@ -157,9 +165,9 @@ class SeminarsController < ApplicationController
|
|||
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
|
||||
end
|
||||
end
|
||||
#else
|
||||
# redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
|
||||
#end
|
||||
else
|
||||
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -188,7 +196,10 @@ class SeminarsController < ApplicationController
|
|||
end
|
||||
@con = SeminarSignupContribute.new(update_params)
|
||||
if @con.save
|
||||
|
||||
signup = SeminarSignup.where(id:update_params['seminar_signup_id']).first
|
||||
seminar_id = signup.seminar_main_id
|
||||
@seminar = SeminarMain.where(id:seminar_id).first
|
||||
send_mail('add_file',signup.email,seminar_id)
|
||||
redirect_to "#{params[:referer_url]}/?method=con_upload"
|
||||
else
|
||||
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
|
||||
|
@ -219,6 +230,10 @@ class SeminarsController < ApplicationController
|
|||
end
|
||||
@con.update_attributes(update_params)
|
||||
if @con.save
|
||||
signup = SeminarSignup.where(id:update_params['seminar_signup_id']).first
|
||||
seminar_id = signup.seminar_main_id
|
||||
@seminar = SeminarMain.where(id:seminar_id).first
|
||||
send_mail('edit_file',signup.email,seminar_id)
|
||||
redirect_to "#{params[:referer_url]}/?method=con_upload"
|
||||
else
|
||||
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
|
||||
|
@ -358,5 +373,27 @@ class SeminarsController < ApplicationController
|
|||
def seminar_signup_values_params
|
||||
params.require(:seminar_signup_values).permit!
|
||||
end
|
||||
|
||||
def send_mail(field_name,email,seminar_id)
|
||||
email_set = @seminar.seminar_email_sets.select{|v| v.field_name == field_name}
|
||||
if email_set.length==0
|
||||
mail = Email.create(mail_to:[email],
|
||||
module_app_key:"seminar",
|
||||
template:"email/#{field_name}_email.html.erb",
|
||||
mail_sentdate:Time.current,
|
||||
mail_subject: t("seminar.email_#{field_name}_success"),
|
||||
template_data:{'seminar_id'=>seminar_id,'locale'=>I18n.locale})
|
||||
elsif !(email_set[0].disabled)
|
||||
mail = Email.create(mail_to:[email],
|
||||
module_app_key:"seminar",
|
||||
template:"email/#{field_name}_email.html.erb",
|
||||
mail_sentdate:Time.current,
|
||||
mail_subject: email_set[0].title[I18n.locale],
|
||||
template_data:{'seminar_id'=>seminar_id,'locale'=>I18n.locale})
|
||||
end
|
||||
begin
|
||||
mail.deliver
|
||||
rescue e
|
||||
puts ["email can't deliver",e]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -201,8 +201,13 @@ protected
|
|||
end
|
||||
# div_class_ary = ["tab-pane" ,"fade","#{get_pairing_tab_class({})}_#{key}"]
|
||||
div_class_ary = ["tab-pane" ,"fade"]
|
||||
|
||||
div_id = "#{get_pairing_tab_class({})}_#{key}"
|
||||
puts ['div_id',@key_field.inspect]
|
||||
if @show_set_field && @markup=='text_area'
|
||||
div_id = "ckeditor_#{get_pairing_tab_class({})}_#{key}"
|
||||
puts 'ckeditor_'
|
||||
else
|
||||
div_id = "#{get_pairing_tab_class({})}_#{key}"
|
||||
end
|
||||
if can_add_more
|
||||
add_more_value = add_more_params[0][:value]
|
||||
add_more_counter = add_more_params[0][:counter]
|
||||
|
@ -217,7 +222,11 @@ protected
|
|||
tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do
|
||||
buff2 = valid_locales.each.collect do |key|
|
||||
# link_entry = self.add_more ? "#{add_more_tab(:tab_btn,loop_counter,key)}" : "#tab"+id.to_s+"_#{key}"
|
||||
link_entry_ary = ["##{get_pairing_tab_class({})}","_#{key}"]
|
||||
if @show_set_field && @markup=='text_area'
|
||||
link_entry_ary = ["#ckeditor_#{get_pairing_tab_class({})}","_#{key}"]
|
||||
else
|
||||
link_entry_ary = ["##{get_pairing_tab_class({})}","_#{key}"]
|
||||
end
|
||||
link_entry_ary << ".add_more_item_#{add_more_counter}" if can_add_more
|
||||
link_entry = link_entry_ary.join
|
||||
link_to(I18n.t(key),link_entry,:data=>{:toggle=>"tab"},:class=>"btn #{(key == I18n.locale ? "active" : nil)}",:for=>key)
|
||||
|
@ -301,7 +310,6 @@ protected
|
|||
result << gen_modal_dialog if self.markup == "address"
|
||||
# result << add_more_unt if can_add_more
|
||||
else #cross lang field
|
||||
|
||||
case can_add_more
|
||||
when true
|
||||
value = add_more_params[0][:value]
|
||||
|
@ -464,15 +472,17 @@ protected
|
|||
}
|
||||
)
|
||||
end
|
||||
def show_set_field(field_sets,key_field,key_index,field)
|
||||
def show_set_field(field_sets,key_field,key_index,field,markup='text_field')
|
||||
@show_set_field = true
|
||||
def self.can_muti_lang_input?
|
||||
true
|
||||
end
|
||||
def self.can_add_more
|
||||
false
|
||||
end
|
||||
@markup = markup
|
||||
def self.markup
|
||||
'text_field'
|
||||
@markup
|
||||
end
|
||||
def self.add_more
|
||||
false
|
||||
|
@ -486,7 +496,8 @@ protected
|
|||
''
|
||||
end
|
||||
def self.end_block
|
||||
hidden_field_tag("seminar_main[#{@key_field}][#{@key_index}]"+"[id]",@attribute_value.id,:for=>"field_#{@key_index}")
|
||||
hidden_field_tag("seminar_main[#{@key_field}][#{@key_index}]"+"[id]",
|
||||
@attribute_value.id,:for=>"field_#{@key_index}")
|
||||
end
|
||||
@key_field = key_field
|
||||
@field = field
|
||||
|
@ -498,15 +509,23 @@ protected
|
|||
end
|
||||
@attribute_value = field_sets
|
||||
@prefiled_value = field_sets[field]
|
||||
a = content_tag(:span,:class => 'btn-group') do
|
||||
control_group_wrapper do |key,value|
|
||||
add_more_blank = ""
|
||||
text_field_tag([get_field_name_base,"[#{key}]"].join,value)
|
||||
end
|
||||
a = control_group_wrapper do |key,value|
|
||||
add_more_blank = ""
|
||||
if markup=='text_field'
|
||||
if key_field == 'seminar_email_sets'
|
||||
inside = text_field_tag([get_field_name_base,"[#{key}]"].join,value,:class=>'input-medium form-control')
|
||||
else
|
||||
inside = text_field_tag([get_field_name_base,"[#{key}]"].join,value)
|
||||
end
|
||||
else
|
||||
inside = cktext_area("seminar_main[#{@key_field}][#{@key_index}][#{@field}]","#{key}",value:value)
|
||||
end
|
||||
inside
|
||||
end
|
||||
@key_field = nil
|
||||
@key_index = nil
|
||||
@field = nil
|
||||
@show_set_field = nil
|
||||
return a.html_safe
|
||||
end
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class SeminarEmailSet
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :field_name, type: String
|
||||
field :title
|
||||
field :content
|
||||
field :disabled, type: Boolean, default: false
|
||||
belongs_to :seminar_main
|
||||
end
|
|
@ -39,6 +39,7 @@ class SeminarMain
|
|||
has_many :seminar_reviews, :autosave => true, :dependent => :destroy
|
||||
has_many :seminar_signup_field_sets, autosave: true, dependent: :destroy
|
||||
has_many :seminar_submission_field_sets, autosave: true, dependent: :destroy
|
||||
has_many :seminar_email_sets, autosave: true, dependent: :destroy
|
||||
has_many :seminar_signup_field_customs, :autosave => true, :dependent => :destroy
|
||||
accepts_nested_attributes_for :seminar_links, :allow_destroy => true
|
||||
accepts_nested_attributes_for :seminar_files, :allow_destroy => true
|
||||
|
@ -49,6 +50,7 @@ class SeminarMain
|
|||
accepts_nested_attributes_for :seminar_reviews, :allow_destroy => true
|
||||
accepts_nested_attributes_for :seminar_signup_field_sets, :allow_destroy => true
|
||||
accepts_nested_attributes_for :seminar_submission_field_sets, :allow_destroy => true
|
||||
accepts_nested_attributes_for :seminar_email_sets, :allow_destroy => true
|
||||
accepts_nested_attributes_for :seminar_signup_field_customs, :allow_destroy => true
|
||||
def self.time_range(date1 = null, date2 = null)
|
||||
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
<li><a href="#review" data-toggle="tab"><%= t('seminar.review') %></a></li>
|
||||
<li><a href="#signup_set" data-toggle="tab"><%= t('seminar.signup_set') %></a></li>
|
||||
<li><a href="#submission_set" data-toggle="tab"><%= t('seminar.submission_set') %></a></li>
|
||||
<li><a href="#custom_set" data-toggle="tab"><%= t('seminar.custom_set') %></a></li>
|
||||
<li><a href="#custom_set" data-toggle="tab"><%= t('seminar.custom_set') %></a></li>
|
||||
<li><a href="#auto_send_email_set" data-toggle="tab"><%= t('seminar.auto_send_email_set') %></a></li>
|
||||
</ul>
|
||||
|
||||
<!-- Module -->
|
||||
|
@ -243,6 +244,70 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!-- Email Set Module -->
|
||||
<div class="tab-pane fade in " id="auto_send_email_set" style="padding: 1.2em;">
|
||||
<ul class="nav nav-pills module-nav">
|
||||
<li class="active">
|
||||
<a href="#email_set0" data-toggle="tab">
|
||||
<%= t('seminar.email_signup') %>
|
||||
</a>
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="#email_set1" data-toggle="tab">
|
||||
<%= t('seminar.email_submission') %>
|
||||
</a>
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="#email_set2" data-toggle="tab">
|
||||
<%= t('seminar.email_add_file') %>
|
||||
</a>
|
||||
</li>
|
||||
<li class="">
|
||||
<a href="#email_set3" data-toggle="tab">
|
||||
<%= t('seminar.email_edit_file') %>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<% (0..3).each do |index1| %>
|
||||
<% active_email_set = index1==0 ? ' active' : '' %>
|
||||
<div class="tab-pane<%= active_email_set %>" id="email_set<%= index1 %>" style="padding: 1.2em;">
|
||||
<table style="width:100%;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<%= t('seminar.disable') %>
|
||||
</td>
|
||||
<td>
|
||||
<input type="hidden" class="field_set" name='<%= "seminar_main[seminar_email_sets][#{index1}][disabled]" %>' value="false">
|
||||
<%= check_box_tag("seminar_main[seminar_email_sets][#{index1}][disabled]", true ,@email_set[index1].disabled) %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<%= t('seminar.email_title') %>
|
||||
</td>
|
||||
<td>
|
||||
<%= show_set_field(@email_set[index1],'seminar_email_sets',index1,'title','text_field') %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<%= t('seminar.email_content') %>
|
||||
</td>
|
||||
<td>
|
||||
<div class="form-group">
|
||||
<%= show_set_field(@email_set[index1],'seminar_email_sets',index1,'content','text_area') %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Language Tabs -->
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
<% if show3 %>
|
||||
<th class='span2'><%= t('seminar_signup.description')%></th>
|
||||
<% end %>
|
||||
<% @seminar.seminar_submission_fields.each do |submission_field| %>
|
||||
<% @seminar.seminar_submission_fields.asc(:_id).each do |submission_field| %>
|
||||
<th class='span2'><%= submission_field.title %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
@ -176,20 +176,20 @@
|
|||
count_field = @seminar.seminar_submission_fields.count
|
||||
%>
|
||||
<% if count_value == count_field %>
|
||||
<% seminar_signup_contribute.seminar_submission_values.each do |value| %>
|
||||
<td>
|
||||
<span style="display: list-item;">
|
||||
<% if value.value.class == String || value.value.nil? %>
|
||||
<%= value.get_value_by_locale(I18n.locale,value) %>
|
||||
<% else %>
|
||||
<% value.value.each do |key,v| %>
|
||||
<%= "#{I18n.t(key)}:#{value.get_value_by_locale(key,value)}" %>
|
||||
<br>
|
||||
<% seminar_signup_contribute.seminar_submission_values.asc(:seminar_submission_field_id).each do |value| %>
|
||||
<td>
|
||||
<span style="display: list-item;">
|
||||
<% if value.value.class == String || value.value.nil? %>
|
||||
<%= value.get_value_by_locale(I18n.locale,value) %>
|
||||
<% else %>
|
||||
<% value.value.each do |key,v| %>
|
||||
<%= "#{I18n.t(key)}:#{value.get_value_by_locale(key,value)}" %>
|
||||
<br>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</span>
|
||||
</td>
|
||||
<% end %>
|
||||
</span>
|
||||
</td>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% for i in 1..(count_field-count_value) %>
|
||||
<td>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<% email_set = SeminarMain.where(id:@data['seminar_id']).first.seminar_email_sets.select{|v| v.field_name == 'add_file'} %>
|
||||
<% if email_set.length != 0 %>
|
||||
<% if !(email_set[0].content.nil?) %>
|
||||
<%= email_set[0].content[@data['locale']].html_safe %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= t('seminar.email_add_file_content') %>
|
||||
<% end %>
|
|
@ -0,0 +1,8 @@
|
|||
<% email_set = SeminarMain.where(id:@data['seminar_id']).first.seminar_email_sets.select{|v| v.field_name == 'edit_file'} %>
|
||||
<% if email_set.length != 0 %>
|
||||
<% if !(email_set[0].content.nil?) %>
|
||||
<%= email_set[0].content[@data['locale']].html_safe %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= t('seminar.email_edit_file_content') %>
|
||||
<% end %>
|
|
@ -0,0 +1,8 @@
|
|||
<% email_set = SeminarMain.where(id:@data['seminar_id']).first.seminar_email_sets.select{|v| v.field_name == 'signup'} %>
|
||||
<% if email_set.length != 0 %>
|
||||
<% if !(email_set[0].content.nil?) %>
|
||||
<%= email_set[0].content[@data['locale']].html_safe %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= t('seminar.email_signup_content') %>
|
||||
<% end %>
|
|
@ -0,0 +1,8 @@
|
|||
<% email_set = SeminarMain.where(id:@data['seminar_id']).first.seminar_email_sets.select{|v| v.field_name == 'submission'} %>
|
||||
<% if email_set.length != 0 %>
|
||||
<% if !(email_set[0].content.nil?) %>
|
||||
<%= email_set[0].content[@data['locale']].html_safe %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= t('seminar.email_submission_content') %>
|
||||
<% end %>
|
|
@ -68,13 +68,13 @@
|
|||
<div class="form-group" style="display: flex;justify-content: flex-end;text-align: right;">
|
||||
<span style="margin-right: 0.5em;">
|
||||
<label for="note" class="col-sm-2 control-label" style="display: contents;">
|
||||
<%= name3 %>
|
||||
*<%= name3 %>
|
||||
</label>
|
||||
<br>
|
||||
<%= "(#{plc3})" if !(plc3.to_s.blank?) %>
|
||||
</span>
|
||||
<div class="col-sm-10">
|
||||
<%= f.file_field :file %>
|
||||
<%= f.file_field :file, :required => true %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
<div class="form-group" style="display: flex;justify-content: flex-end;text-align: right;">
|
||||
<span style="margin-right: 0.5em;">
|
||||
<label for="note" class="col-sm-2 control-label" style="display: contents;">
|
||||
<%= name3 %>
|
||||
*<%= name3 %>
|
||||
</label>
|
||||
<br>
|
||||
<%= "(#{plc3})" if !(plc3.to_s.blank?) %>
|
||||
|
|
|
@ -17,6 +17,21 @@ en:
|
|||
verification_failed: Verification Failed #驗證碼錯誤
|
||||
|
||||
seminar:
|
||||
email_signup_success: Signup success
|
||||
email_submission_success: Submission registration success
|
||||
email_add_file_success: Add file success
|
||||
email_edit_file_success: Edit file success
|
||||
email_signup_content: Signup success
|
||||
email_submission_content: Submission registration success
|
||||
email_add_file_content: Add file success
|
||||
email_edit_file_content: Edit file success
|
||||
email_title: Title
|
||||
email_content: Content
|
||||
email_signup: Signup
|
||||
email_submission: Submission
|
||||
email_edit_file: Edit file
|
||||
email_add_file: Add file
|
||||
auto_send_email_set: Auto send email setting
|
||||
click_to_contribute: Click here to contribute
|
||||
required: Required
|
||||
already_used: Already Used
|
||||
|
|
|
@ -17,6 +17,21 @@ zh_tw:
|
|||
verification_failed: 驗證碼錯誤
|
||||
|
||||
seminar:
|
||||
email_signup_success: 報名成功
|
||||
email_submission_success: 投稿註冊成功
|
||||
email_add_file_success: 新增上傳成功
|
||||
email_edit_file_success: 編輯上傳成功
|
||||
email_signup_content: 報名成功
|
||||
email_submission_content: 投稿註冊成功
|
||||
email_add_file_content: 新增上傳成功
|
||||
email_edit_file_content: 編輯上傳成功
|
||||
email_title: 主旨
|
||||
email_content: 內文
|
||||
email_signup: 報名
|
||||
email_submission: 投稿
|
||||
email_edit_file: 編輯上傳
|
||||
email_add_file: 新增上傳
|
||||
auto_send_email_set: 自動發信設定
|
||||
click_to_contribute: 按此登入投稿
|
||||
required: 必填
|
||||
already_used: 已存在
|
||||
|
|
Loading…
Reference in New Issue