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.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') %>
+
+ |
+