From 446da7bf3a3ad0c889861706aafdca54e693a389 Mon Sep 17 00:00:00 2001 From: chiu Date: Sun, 12 Jan 2020 14:39:32 +0800 Subject: [PATCH 1/6] add the auto send email feature --- app/controllers/admin/seminars_controller.rb | 19 ++++++ app/controllers/seminars_controller.rb | 49 ++++++++++++-- app/helpers/admin/seminars_field_helper.rb | 43 ++++++++---- app/models/seminar_email_set.rb | 10 +++ app/models/seminar_main.rb | 2 + app/views/admin/seminars/_form.html.erb | 67 ++++++++++++++++++- .../admin/seminars/seminar_signup.html.erb | 28 ++++---- app/views/email/add_file_email.html.erb | 8 +++ app/views/email/edit_file_email.html.erb | 8 +++ app/views/email/signup_email.html.erb | 8 +++ app/views/email/submission_email.html.erb | 8 +++ app/views/seminars/add_file.html.erb | 4 +- app/views/seminars/edit_file.html.erb | 2 +- config/locales/en.yml | 15 +++++ config/locales/zh_tw.yml | 15 +++++ 15 files changed, 250 insertions(+), 36 deletions(-) create mode 100644 app/models/seminar_email_set.rb create mode 100644 app/views/email/add_file_email.html.erb create mode 100644 app/views/email/edit_file_email.html.erb create mode 100644 app/views/email/signup_email.html.erb create mode 100644 app/views/email/submission_email.html.erb diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index 108c4c4..a79858e 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -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 diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index e18c63f..4f3c037 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -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 diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index 48d0afe..ee646e8 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -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 \ 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/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: 已存在 From b0d1ae2951ea14b58df9c13cb7ae8b00a5bdb463 Mon Sep 17 00:00:00 2001 From: chiu Date: Sun, 12 Jan 2020 14:57:33 +0800 Subject: [PATCH 2/6] remove puts --- app/controllers/seminars_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index 4f3c037..c3ece27 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -289,7 +289,6 @@ class SeminarsController < ApplicationController seminar_signup = {} end con = SeminarSignupContribute.find(params[:con_no]) - puts ['con',con.inspect] { 'con' => con, 'seminar' => seminar, From c1866d56904e7d85664697aaf1bc458d8d02c193 Mon Sep 17 00:00:00 2001 From: chiu Date: Sun, 12 Jan 2020 14:58:41 +0800 Subject: [PATCH 3/6] remove puts --- app/models/seminar_signup_value.rb | 3 --- 1 file changed, 3 deletions(-) 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 From e67cb911de41725bee73a98d094b8760e30e0344 Mon Sep 17 00:00:00 2001 From: chiu Date: Sun, 12 Jan 2020 14:59:32 +0800 Subject: [PATCH 4/6] remove puts --- app/helpers/admin/seminars_field_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/helpers/admin/seminars_field_helper.rb b/app/helpers/admin/seminars_field_helper.rb index ee646e8..f3d385c 100644 --- a/app/helpers/admin/seminars_field_helper.rb +++ b/app/helpers/admin/seminars_field_helper.rb @@ -201,7 +201,6 @@ protected end # div_class_ary = ["tab-pane" ,"fade","#{get_pairing_tab_class({})}_#{key}"] div_class_ary = ["tab-pane" ,"fade"] - puts ['div_id',@key_field.inspect] if @show_set_field && @markup=='text_area' div_id = "ckeditor_#{get_pairing_tab_class({})}_#{key}" puts 'ckeditor_' From 125a0879ecd4bdf1c4bdd365d8bf2742a89144b1 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 22 Jan 2020 21:52:32 +0800 Subject: [PATCH 5/6] fix sort error --- app/controllers/seminars_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index c3ece27..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, From 9203dbdb9315455bae7942ab49d91be6c0f45dbe Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 11 Mar 2020 12:01:52 +0800 Subject: [PATCH 6/6] fix error for new in admin page --- app/controllers/admin/seminars_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/seminars_controller.rb b/app/controllers/admin/seminars_controller.rb index a79858e..f3eb263 100644 --- a/app/controllers/admin/seminars_controller.rb +++ b/app/controllers/admin/seminars_controller.rb @@ -321,7 +321,11 @@ class Admin::SeminarsController < OrbitAdminController 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) + 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