diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index caa4fd8..f7718c3 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -3,7 +3,7 @@ class SeminarsController < ApplicationController include MemberHelper include ActionView::Context #vary important (only add this can access @@session from view) include Admin::SeminarsHelper - FrontendMethods = ["show_privacy", "show_data", "check_email", "check_availability", "signup_ok", "add_file", "edit_file", "con_login", "con_upload", "con_logout","confirm_email_page","reset_password_page","edit_login_seminar_signup"] + FrontendMethods = ["show_privacy", "show_data", "check_email", "check_name", "check_availability", "signup_ok", "add_file", "edit_file", "con_login", "con_upload", "con_logout","confirm_email_page","reset_password_page","edit_login_seminar_signup"] # include SimpleCaptcha::ControllerHelpers def index @@ -419,6 +419,24 @@ class SeminarsController < ApplicationController end + def check_name + + params = OrbitHelper.params + success = true + if !params[:name].blank? + count = SeminarSignup.where(:name => params[:name], :seminar_main_id => params[:no]).count + + result = count > 0 ? t('seminar.already_used') : t('seminar.available') + success = count > 0 ? false : true + end + + render :json => { + "result" => result, + "success" => success + }.to_json + + end + def check_availability params = OrbitHelper.params @@ -477,7 +495,7 @@ class SeminarsController < ApplicationController end end end - @signup = SeminarSignup.where(email: params[:seminar_signup][:email], seminar_main_id: seminar_id ).first + @signup = SeminarSignup.where(name: params[:seminar_signup][:name], email: params[:seminar_signup][:email], seminar_main_id: seminar_id ).first @seminar_signup = SeminarSignup.new(seminar_signup_params) not_signup_yet = @signup.blank? @@ -529,7 +547,7 @@ class SeminarsController < ApplicationController end end if !not_signup_yet - notice_words = t('seminar.email_exist') + notice_words = t('seminar.email_or_name_exist') referer_url = get_referer_url_for_notice(notice_words) show_alert(notice_words) else diff --git a/app/views/seminars/show.html.erb b/app/views/seminars/show.html.erb index a5ab61e..d9ca678 100644 --- a/app/views/seminars/show.html.erb +++ b/app/views/seminars/show.html.erb @@ -160,6 +160,11 @@ <%= f.text_field :tel, :class=>"input-medium form-control", :placeholder=> signup_field.placeholder[I18n.locale], :required => true, pattern: "[\\d\\+\\-\\(\\)]{10,13}", title: t("seminar.phone_hint") %>

(<%= t("seminar.phone_hint") %>)

+ <% elsif signup_field.field_name == 'name' %> +
+ <%= f.text_field signup_field['field_name'], :class=>"input-medium form-control", :id=>signup_field['field_name'], :placeholder=> signup_field.placeholder[I18n.locale], :required => true %> +
+
<% else %>
<%= f.text_field signup_field['field_name'], :class=>"input-medium form-control", :id=>signup_field['field_name'], :placeholder=> signup_field.placeholder[I18n.locale], :required => true %> @@ -400,7 +405,30 @@ return false; }); - + $('#name').blur(function(){ + var type = $(this).attr("id"), + loader = $(this).parent().find('.loader'), + elem = $(this), + value = $(this).val().trim() || null; + var checkAvailability = function(){ + $.ajax({ + url : "<%= "/xhr/seminars/check_name/#{@seminar.id}" %>", + data : {"type" : type, "name" : value}, + dataType : "json", + type : "get", + success : function(data){ + if( data.success == true ){ + loader.removeClass("error"); + }else{ + loader.addClass("error"); + } + loader.text(data.result); + } + }) + } + loader.text("Checking...") + checkAvailability(); + }); $('input[type="email"]').blur(function(){ var type = $(this).attr("id"), loader = $(this).parent().find('.loader'), diff --git a/config/locales/en.yml b/config/locales/en.yml index f919cab..ac37abf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -94,7 +94,7 @@ en: dashboard: Dashboard display_field: Display field note: Note - email_exist: "Email exist!" + email_exist: "Email or name exist!" email_signup_success: Signup success email_submission_success: Submission registration success email_add_file_success: Add file success diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 46edc78..b867ff8 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -94,7 +94,7 @@ zh_tw: dashboard: 儀錶板 display_field: 顯示的欄位 note: 附註 - email_exist: "email已存在!" + email_exist: "已存在!" email_signup_success: 報名成功 email_submission_success: 投稿註冊成功 email_add_file_success: 新增上傳成功 diff --git a/config/routes.rb b/config/routes.rb index 4453b3a..043d2e5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -116,6 +116,7 @@ Rails.application.routes.draw do end end get "/xhr/seminars/check_email/:no" => "seminars#check_email" + get "/xhr/seminars/check_name/:no" => "seminars#check_name" end end