diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index 108c4c4..f3eb263 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -308,5 +308,28 @@ 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 + 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 diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index e18c63f..6e07ed7 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -7,9 +7,8 @@ class SeminarsController < ApplicationController def index 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, '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 @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 +151,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 +164,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 +195,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 +229,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') @@ -274,7 +288,6 @@ class SeminarsController < ApplicationController seminar_signup = {} end con = SeminarSignupContribute.find(params[:con_no]) - puts ['con',con.inspect] { 'con' => con, 'seminar' => seminar, @@ -358,5 +371,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 diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index 48d0afe..f3d385c 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -201,8 +201,12 @@ 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}" + 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 +221,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 +309,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 +471,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 +495,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 +508,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 \ No newline at end of file diff --git a/app/models/seminar_email_set.rb b/app/models/seminar_email_set.rb new file mode 100644 index 0000000..f22f0c7 --- /dev/null +++ b/app/models/seminar_email_set.rb @@ -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 diff --git a/app/models/seminar_main.rb b/app/models/seminar_main.rb index 5342a47..51f7071 100644 --- a/app/models/seminar_main.rb +++ b/app/models/seminar_main.rb @@ -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) diff --git a/app/models/seminar_signup_value.rb b/app/models/seminar_signup_value.rb index d73f13d..f477f67 100644 --- a/app/models/seminar_signup_value.rb +++ b/app/models/seminar_signup_value.rb @@ -156,11 +156,8 @@ class SeminarSignupValue if field_value_status.eql?(true) @seminar_signup_field_value = member.seminar_signup_values.find(field_value_id) rescue nil if @seminar_signup_field_value!=nil - puts ['yes'] @seminar_signup_field_value.update(field_value_param) rescue nil @seminar_signup_field_value.save rescue nil - else - puts ['no'] end else @seminar_signup_field_value = member.seminar_signup_values.build(field_value_param) rescue nil diff --git a/app/views/admin/seminars/_form.html.erb b/app/views/admin/seminars/_form.html.erb index b6513bf..a5b975e 100644 --- a/app/views/admin/seminars/_form.html.erb +++ b/app/views/admin/seminars/_form.html.erb @@ -29,7 +29,8 @@
  • <%= t('seminar.review') %>
  • <%= t('seminar.signup_set') %>
  • <%= t('seminar.submission_set') %>
  • -
  • <%= t('seminar.custom_set') %>
  • +
  • <%= t('seminar.custom_set') %>
  • +
  • <%= t('seminar.auto_send_email_set') %>
  • @@ -243,6 +244,70 @@ + +
    + +
    + <% (0..3).each do |index1| %> + <% active_email_set = index1==0 ? ' active' : '' %> +
    + + + + + + + + + + + + + + + + +
    + <%= t('seminar.disable') %> + + + <%= check_box_tag("seminar_main[seminar_email_sets][#{index1}][disabled]", true ,@email_set[index1].disabled) %> +
    + <%= t('seminar.email_title') %> + + <%= show_set_field(@email_set[index1],'seminar_email_sets',index1,'title','text_field') %> +
    + <%= t('seminar.email_content') %> + +
    + <%= show_set_field(@email_set[index1],'seminar_email_sets',index1,'content','text_area') %> +
    +
    +
    + <% end %> +
    +
    diff --git a/app/views/admin/seminars/seminar_signup.html.erb b/app/views/admin/seminars/seminar_signup.html.erb index 67ad79f..a0cdf31 100644 --- a/app/views/admin/seminars/seminar_signup.html.erb +++ b/app/views/admin/seminars/seminar_signup.html.erb @@ -55,7 +55,7 @@ <% if show3 %> <%= t('seminar_signup.description')%> <% end %> - <% @seminar.seminar_submission_fields.each do |submission_field| %> + <% @seminar.seminar_submission_fields.asc(:_id).each do |submission_field| %> <%= submission_field.title %> <% end %> @@ -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| %> - - - <% 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)}" %> -
    + <% seminar_signup_contribute.seminar_submission_values.asc(:seminar_submission_field_id).each do |value| %> + + + <% 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)}" %> +
    + <% end %> <% end %> - <% end %> -
    - - <% end %> +
    + + <% end %> <% else %> <% for i in 1..(count_field-count_value) %> diff --git a/app/views/email/add_file_email.html.erb b/app/views/email/add_file_email.html.erb new file mode 100644 index 0000000..c4eb60c --- /dev/null +++ b/app/views/email/add_file_email.html.erb @@ -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 %> \ No newline at end of file diff --git a/app/views/email/edit_file_email.html.erb b/app/views/email/edit_file_email.html.erb new file mode 100644 index 0000000..5412b0e --- /dev/null +++ b/app/views/email/edit_file_email.html.erb @@ -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 %> \ No newline at end of file diff --git a/app/views/email/signup_email.html.erb b/app/views/email/signup_email.html.erb new file mode 100644 index 0000000..eb6a9a0 --- /dev/null +++ b/app/views/email/signup_email.html.erb @@ -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 %> \ No newline at end of file diff --git a/app/views/email/submission_email.html.erb b/app/views/email/submission_email.html.erb new file mode 100644 index 0000000..d3b4041 --- /dev/null +++ b/app/views/email/submission_email.html.erb @@ -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 %> \ No newline at end of file diff --git a/app/views/seminars/add_file.html.erb b/app/views/seminars/add_file.html.erb index efeb748..7b7146d 100644 --- a/app/views/seminars/add_file.html.erb +++ b/app/views/seminars/add_file.html.erb @@ -68,13 +68,13 @@

    <%= "(#{plc3})" if !(plc3.to_s.blank?) %>
    - <%= f.file_field :file %> + <%= f.file_field :file, :required => true %>
    <% end %> diff --git a/app/views/seminars/edit_file.html.erb b/app/views/seminars/edit_file.html.erb index 7185a46..7a1bdbf 100644 --- a/app/views/seminars/edit_file.html.erb +++ b/app/views/seminars/edit_file.html.erb @@ -66,7 +66,7 @@

    <%= "(#{plc3})" if !(plc3.to_s.blank?) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 144c2bf..d5eb7c9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 7c8b58e..9cccecd 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -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: 已存在