Merge branch 'master' into 'master'

add auto send email feature



See merge request !3
This commit is contained in:
chiu 2020-03-11 12:05:07 +08:00
commit 4734906e5f
16 changed files with 255 additions and 43 deletions

View File

@ -308,5 +308,28 @@ class Admin::SeminarsController < OrbitAdminController
@seminar.seminar_signup_field_customs.create(seminar_signup_field_id:field.id) @seminar.seminar_signup_field_customs.create(seminar_signup_field_id:field.id)
end end
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
if save_flag
email_set = @seminar.seminar_email_sets.create(field_name:field_name,title:title,content:content)
else
email_set = @seminar.seminar_email_sets.new(field_name:field_name,title:title,content:content)
end
else
email_set = email_set[0]
end
@email_set << email_set
end
end end
end end

View File

@ -7,9 +7,8 @@ class SeminarsController < ApplicationController
def index def index
time_now = Time.now time_now = Time.now
seminars = SeminarMain.filter_by_categories.desc(:signup_start_date).page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) seminars = SeminarMain.all.desc(:seminar_start_date).filter_by_categories
{ {
"seminars" => seminars, "seminars" => seminars,
'time_now' => time_now, 'time_now' => time_now,
@ -134,7 +133,13 @@ class SeminarsController < ApplicationController
@signup = SeminarSignup.where(email: params[:seminar_signup][:email], seminar_main_id: params[:seminar_signup][:seminar_main_id] ).first @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) @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 @signup.blank? && @seminar_signup.save
# if gotcha_valid? && @seminar_signup.save # if gotcha_valid? && @seminar_signup.save
@ -146,8 +151,10 @@ class SeminarsController < ApplicationController
end end
if params['seminar_signup']['status']=='C' if params['seminar_signup']['status']=='C'
status_param = '&status=' status_param = '&status='
send_mail('submission',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id])
else else
status_param = '' status_param = ''
send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id])
end end
redirect_to "#{params[:referer_url]}/?method=signup_ok#{status_param}" redirect_to "#{params[:referer_url]}/?method=signup_ok#{status_param}"
else else
@ -157,9 +164,9 @@ class SeminarsController < ApplicationController
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
end end
end end
#else else
# redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
#end end
end end
@ -188,7 +195,10 @@ class SeminarsController < ApplicationController
end end
@con = SeminarSignupContribute.new(update_params) @con = SeminarSignupContribute.new(update_params)
if @con.save 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" redirect_to "#{params[:referer_url]}/?method=con_upload"
else else
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
@ -219,6 +229,10 @@ class SeminarsController < ApplicationController
end end
@con.update_attributes(update_params) @con.update_attributes(update_params)
if @con.save 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" redirect_to "#{params[:referer_url]}/?method=con_upload"
else else
redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed') redirect_to "#{params[:referer_url]}", :notice => t('recaptcha.errors.verification_failed')
@ -274,7 +288,6 @@ class SeminarsController < ApplicationController
seminar_signup = {} seminar_signup = {}
end end
con = SeminarSignupContribute.find(params[:con_no]) con = SeminarSignupContribute.find(params[:con_no])
puts ['con',con.inspect]
{ {
'con' => con, 'con' => con,
'seminar' => seminar, 'seminar' => seminar,
@ -358,5 +371,27 @@ class SeminarsController < ApplicationController
def seminar_signup_values_params def seminar_signup_values_params
params.require(:seminar_signup_values).permit! params.require(:seminar_signup_values).permit!
end 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 end

View File

@ -201,8 +201,12 @@ protected
end end
# div_class_ary = ["tab-pane" ,"fade","#{get_pairing_tab_class({})}_#{key}"] # div_class_ary = ["tab-pane" ,"fade","#{get_pairing_tab_class({})}_#{key}"]
div_class_ary = ["tab-pane" ,"fade"] div_class_ary = ["tab-pane" ,"fade"]
if @show_set_field && @markup=='text_area'
div_id = "#{get_pairing_tab_class({})}_#{key}" div_id = "ckeditor_#{get_pairing_tab_class({})}_#{key}"
puts 'ckeditor_'
else
div_id = "#{get_pairing_tab_class({})}_#{key}"
end
if can_add_more if can_add_more
add_more_value = add_more_params[0][:value] add_more_value = add_more_params[0][:value]
add_more_counter = add_more_params[0][:counter] add_more_counter = add_more_params[0][:counter]
@ -217,7 +221,11 @@ protected
tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do tmp2 = content_tag(:div,:class => 'btn-group', :data=>{:toggle=>"buttons-radio"}) do
buff2 = valid_locales.each.collect do |key| 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 = 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_ary << ".add_more_item_#{add_more_counter}" if can_add_more
link_entry = link_entry_ary.join 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) link_to(I18n.t(key),link_entry,:data=>{:toggle=>"tab"},:class=>"btn #{(key == I18n.locale ? "active" : nil)}",:for=>key)
@ -301,7 +309,6 @@ protected
result << gen_modal_dialog if self.markup == "address" result << gen_modal_dialog if self.markup == "address"
# result << add_more_unt if can_add_more # result << add_more_unt if can_add_more
else #cross lang field else #cross lang field
case can_add_more case can_add_more
when true when true
value = add_more_params[0][:value] value = add_more_params[0][:value]
@ -464,15 +471,17 @@ protected
} }
) )
end 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? def self.can_muti_lang_input?
true true
end end
def self.can_add_more def self.can_add_more
false false
end end
@markup = markup
def self.markup def self.markup
'text_field' @markup
end end
def self.add_more def self.add_more
false false
@ -486,7 +495,8 @@ protected
'' ''
end end
def self.end_block 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 end
@key_field = key_field @key_field = key_field
@field = field @field = field
@ -498,15 +508,23 @@ protected
end end
@attribute_value = field_sets @attribute_value = field_sets
@prefiled_value = field_sets[field] @prefiled_value = field_sets[field]
a = content_tag(:span,:class => 'btn-group') do a = control_group_wrapper do |key,value|
control_group_wrapper do |key,value| add_more_blank = ""
add_more_blank = "" if markup=='text_field'
text_field_tag([get_field_name_base,"[#{key}]"].join,value) if key_field == 'seminar_email_sets'
end 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 end
@key_field = nil @key_field = nil
@key_index = nil @key_index = nil
@field = nil @field = nil
@show_set_field = nil
return a.html_safe return a.html_safe
end end
end end

View File

@ -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

View File

@ -39,6 +39,7 @@ class SeminarMain
has_many :seminar_reviews, :autosave => true, :dependent => :destroy has_many :seminar_reviews, :autosave => true, :dependent => :destroy
has_many :seminar_signup_field_sets, 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_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 has_many :seminar_signup_field_customs, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :seminar_links, :allow_destroy => true accepts_nested_attributes_for :seminar_links, :allow_destroy => true
accepts_nested_attributes_for :seminar_files, :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_reviews, :allow_destroy => true
accepts_nested_attributes_for :seminar_signup_field_sets, :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_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 accepts_nested_attributes_for :seminar_signup_field_customs, :allow_destroy => true
def self.time_range(date1 = null, date2 = null) def self.time_range(date1 = null, date2 = null)

View File

@ -156,11 +156,8 @@ class SeminarSignupValue
if field_value_status.eql?(true) if field_value_status.eql?(true)
@seminar_signup_field_value = member.seminar_signup_values.find(field_value_id) rescue nil @seminar_signup_field_value = member.seminar_signup_values.find(field_value_id) rescue nil
if @seminar_signup_field_value!=nil if @seminar_signup_field_value!=nil
puts ['yes']
@seminar_signup_field_value.update(field_value_param) rescue nil @seminar_signup_field_value.update(field_value_param) rescue nil
@seminar_signup_field_value.save rescue nil @seminar_signup_field_value.save rescue nil
else
puts ['no']
end end
else else
@seminar_signup_field_value = member.seminar_signup_values.build(field_value_param) rescue nil @seminar_signup_field_value = member.seminar_signup_values.build(field_value_param) rescue nil

View File

@ -29,7 +29,8 @@
<li><a href="#review" data-toggle="tab"><%= t('seminar.review') %></a></li> <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="#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="#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> </ul>
<!-- Module --> <!-- Module -->
@ -243,6 +244,70 @@
</tbody> </tbody>
</table> </table>
</div> </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> </div>
<!-- Language Tabs --> <!-- Language Tabs -->

View File

@ -55,7 +55,7 @@
<% if show3 %> <% if show3 %>
<th class='span2'><%= t('seminar_signup.description')%></th> <th class='span2'><%= t('seminar_signup.description')%></th>
<% end %> <% 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> <th class='span2'><%= submission_field.title %></th>
<% end %> <% end %>
</tr> </tr>
@ -176,20 +176,20 @@
count_field = @seminar.seminar_submission_fields.count count_field = @seminar.seminar_submission_fields.count
%> %>
<% if count_value == count_field %> <% if count_value == count_field %>
<% seminar_signup_contribute.seminar_submission_values.each do |value| %> <% seminar_signup_contribute.seminar_submission_values.asc(:seminar_submission_field_id).each do |value| %>
<td> <td>
<span style="display: list-item;"> <span style="display: list-item;">
<% if value.value.class == String || value.value.nil? %> <% if value.value.class == String || value.value.nil? %>
<%= value.get_value_by_locale(I18n.locale,value) %> <%= value.get_value_by_locale(I18n.locale,value) %>
<% else %> <% else %>
<% value.value.each do |key,v| %> <% value.value.each do |key,v| %>
<%= "#{I18n.t(key)}:#{value.get_value_by_locale(key,value)}" %> <%= "#{I18n.t(key)}:#{value.get_value_by_locale(key,value)}" %>
<br> <br>
<% end %>
<% end %> <% end %>
<% end %> </span>
</span> </td>
</td> <% end %>
<% end %>
<% else %> <% else %>
<% for i in 1..(count_field-count_value) %> <% for i in 1..(count_field-count_value) %>
<td> <td>

View File

@ -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 %>

View File

@ -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 %>

View File

@ -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 %>

View File

@ -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 %>

View File

@ -68,13 +68,13 @@
<div class="form-group" style="display: flex;justify-content: flex-end;text-align: right;"> <div class="form-group" style="display: flex;justify-content: flex-end;text-align: right;">
<span style="margin-right: 0.5em;"> <span style="margin-right: 0.5em;">
<label for="note" class="col-sm-2 control-label" style="display: contents;"> <label for="note" class="col-sm-2 control-label" style="display: contents;">
<%= name3 %> *<%= name3 %>
</label> </label>
<br> <br>
<%= "(#{plc3})" if !(plc3.to_s.blank?) %> <%= "(#{plc3})" if !(plc3.to_s.blank?) %>
</span> </span>
<div class="col-sm-10"> <div class="col-sm-10">
<%= f.file_field :file %> <%= f.file_field :file, :required => true %>
</div> </div>
</div> </div>
<% end %> <% end %>

View File

@ -66,7 +66,7 @@
<div class="form-group" style="display: flex;justify-content: flex-end;text-align: right;"> <div class="form-group" style="display: flex;justify-content: flex-end;text-align: right;">
<span style="margin-right: 0.5em;"> <span style="margin-right: 0.5em;">
<label for="note" class="col-sm-2 control-label" style="display: contents;"> <label for="note" class="col-sm-2 control-label" style="display: contents;">
<%= name3 %> *<%= name3 %>
</label> </label>
<br> <br>
<%= "(#{plc3})" if !(plc3.to_s.blank?) %> <%= "(#{plc3})" if !(plc3.to_s.blank?) %>

View File

@ -17,6 +17,21 @@ en:
verification_failed: Verification Failed #驗證碼錯誤 verification_failed: Verification Failed #驗證碼錯誤
seminar: 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 click_to_contribute: Click here to contribute
required: Required required: Required
already_used: Already Used already_used: Already Used

View File

@ -17,6 +17,21 @@ zh_tw:
verification_failed: 驗證碼錯誤 verification_failed: 驗證碼錯誤
seminar: 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: 按此登入投稿 click_to_contribute: 按此登入投稿
required: 必填 required: 必填
already_used: 已存在 already_used: 已存在