forked from spen/seminar
added name checking for the form
This commit is contained in:
parent
8398bb2c65
commit
bedb08bf82
|
@ -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
|
||||
|
|
|
@ -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") %>
|
||||
<p>(<%= t("seminar.phone_hint") %>)</p>
|
||||
</div>
|
||||
<% elsif signup_field.field_name == 'name' %>
|
||||
<div class="col-sm-10">
|
||||
<%= 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 %>
|
||||
<div class="loader"></div>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="col-sm-10">
|
||||
<%= 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'),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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: 新增上傳成功
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue