forked from spen/seminar
修復錯誤訊息無法顯示問題,將表單改為ajax送出
This commit is contained in:
parent
2b15ecb5fe
commit
6cadd24992
|
@ -383,7 +383,7 @@ class SeminarsController < ApplicationController
|
||||||
|
|
||||||
referer_url = OrbitHelper.request.referer
|
referer_url = OrbitHelper.request.referer
|
||||||
|
|
||||||
if (referer_url.nil? || referer_url.match(/(\?|&)method=show_privacy/).nil?) && !OrbitHelper.request.flash[:notice]
|
if (referer_url.nil? || referer_url.match(/(\?|&)method=show_privacy/).nil?) && !OrbitHelper.request.params[:notice]
|
||||||
return {
|
return {
|
||||||
"seminar" => seminar,
|
"seminar" => seminar,
|
||||||
"seminar_signup" => seminar_signup,
|
"seminar_signup" => seminar_signup,
|
||||||
|
@ -443,7 +443,7 @@ class SeminarsController < ApplicationController
|
||||||
if @seminar.enable_recaptcha && (!gotcha_valid?)
|
if @seminar.enable_recaptcha && (!gotcha_valid?)
|
||||||
notice_words = t('recaptcha.errors.verification_failed')
|
notice_words = t('recaptcha.errors.verification_failed')
|
||||||
referer_url = get_referer_url_for_notice(notice_words)
|
referer_url = get_referer_url_for_notice(notice_words)
|
||||||
redirect_to referer_url, :notice => notice_words
|
show_alert(notice_words)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
signup_limit = @seminar.signup_limit
|
signup_limit = @seminar.signup_limit
|
||||||
|
@ -462,7 +462,7 @@ class SeminarsController < ApplicationController
|
||||||
else
|
else
|
||||||
notice_words = t('seminar.sign_up_is_full')
|
notice_words = t('seminar.sign_up_is_full')
|
||||||
referer_url = get_referer_url_for_notice(notice_words)
|
referer_url = get_referer_url_for_notice(notice_words)
|
||||||
redirect_to referer_url, :notice => notice_words
|
show_alert(notice_words)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -471,7 +471,7 @@ class SeminarsController < ApplicationController
|
||||||
if signup_limit <= signup_count
|
if signup_limit <= signup_count
|
||||||
notice_words = t('seminar.sign_up_is_full')
|
notice_words = t('seminar.sign_up_is_full')
|
||||||
referer_url = get_referer_url_for_notice(notice_words)
|
referer_url = get_referer_url_for_notice(notice_words)
|
||||||
redirect_to referer_url, :notice => notice_words
|
show_alert(notice_words)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -518,7 +518,9 @@ class SeminarsController < ApplicationController
|
||||||
end
|
end
|
||||||
send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id],extra_text)
|
send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id],extra_text)
|
||||||
end
|
end
|
||||||
redirect_to "#{params[:referer_url].to_s.chomp('/').gsub(/\/([^\/?#]+)(|[^\/]+)$/){|f| '/'+$1}}?method=signup_ok#{status_param}&serial_number=#{@seminar_signup.display_serial_number}&seminar=#{@seminar.uid}"
|
|
||||||
|
redirect_with_js("#{params[:referer_url].to_s.chomp('/').gsub(/\/([^\/?#]+)(|[^\/]+)$/){|f| '/'+$1}}?method=signup_ok#{status_param}&serial_number=#{@seminar_signup.display_serial_number}&seminar=#{@seminar.uid}")
|
||||||
|
|
||||||
else
|
else
|
||||||
if has_counter
|
if has_counter
|
||||||
OrbitHelper::SharedMutex.synchronize do
|
OrbitHelper::SharedMutex.synchronize do
|
||||||
|
@ -528,11 +530,11 @@ class SeminarsController < ApplicationController
|
||||||
if !not_signup_yet
|
if !not_signup_yet
|
||||||
notice_words = t('seminar.email_exist')
|
notice_words = t('seminar.email_exist')
|
||||||
referer_url = get_referer_url_for_notice(notice_words)
|
referer_url = get_referer_url_for_notice(notice_words)
|
||||||
redirect_to referer_url, :notice => notice_words
|
show_alert(notice_words)
|
||||||
else
|
else
|
||||||
notice_words = t('seminar.sign_up_failed')
|
notice_words = t('seminar.sign_up_failed')
|
||||||
referer_url = get_referer_url_for_notice(notice_words)
|
referer_url = get_referer_url_for_notice(notice_words)
|
||||||
redirect_to referer_url, :notice => notice_words
|
show_alert(notice_words)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -572,7 +574,7 @@ class SeminarsController < ApplicationController
|
||||||
end
|
end
|
||||||
send_mail('signup',tmp_seminar_signup_params[:email],tmp_seminar_signup_params[:seminar_main_id],extra_text)
|
send_mail('signup',tmp_seminar_signup_params[:email],tmp_seminar_signup_params[:seminar_main_id],extra_text)
|
||||||
end
|
end
|
||||||
redirect_to "#{params[:referer_url].to_s.chomp('/').gsub(/\/([^\/?#]+)(|[^\/]+)$/){|f| '/'+$1}}?method=con_upload"
|
redirect_with_js("#{params[:referer_url].to_s.chomp('/').gsub(/\/([^\/?#]+)(|[^\/]+)$/){|f| '/'+$1}}?method=con_upload")
|
||||||
end
|
end
|
||||||
|
|
||||||
def signup_ok
|
def signup_ok
|
||||||
|
@ -934,4 +936,20 @@ class SeminarsController < ApplicationController
|
||||||
def seminar_signup_values_params
|
def seminar_signup_values_params
|
||||||
params.require(:seminar_signup_values).permit!
|
params.require(:seminar_signup_values).permit!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def show_alert(notice_words)
|
||||||
|
respond_to do |format|
|
||||||
|
format.js{
|
||||||
|
render :js => "alert('#{notice_words}');"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def redirect_with_js(url)
|
||||||
|
respond_to do |format|
|
||||||
|
format.js{
|
||||||
|
render :js => "window.location.href = '#{url}';"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -315,22 +315,42 @@
|
||||||
for (var i=0;i< all_values.length;i++){
|
for (var i=0;i< all_values.length;i++){
|
||||||
if (values.includes(all_values[i][1])){
|
if (values.includes(all_values[i][1])){
|
||||||
all_values[i][0].setCustomValidity("<%= t('seminar.repeat_hint') %>");
|
all_values[i][0].setCustomValidity("<%= t('seminar.repeat_hint') %>");
|
||||||
all_values[i][0].reportValidity();
|
all_values[i][0].focus();
|
||||||
|
$(all_values[i][0]).parents('form')[0].reportValidity();
|
||||||
validated = false;
|
validated = false;
|
||||||
window.setTimeout(function(){
|
$(all_values[i][0]).one('keyup change', function(){
|
||||||
all_values[i][0].setCustomValidity("");
|
this.setCustomValidity("");
|
||||||
}, 500);
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
values.push(all_values[i][1]);
|
values.push(all_values[i][1]);
|
||||||
}
|
}
|
||||||
return validated;
|
return validated;
|
||||||
}
|
}
|
||||||
|
function uploadSubmit(form){
|
||||||
|
$.ajax({
|
||||||
|
type: 'post',
|
||||||
|
method: 'post',
|
||||||
|
async: false,
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
dataType: "script",
|
||||||
|
url: $(form).attr('action'),
|
||||||
|
data: new FormData(form)
|
||||||
|
});
|
||||||
|
}
|
||||||
$(".rucaptcha-image").siblings("input[type=\"text\"]").attr("placeholder","Verification");
|
$(".rucaptcha-image").siblings("input[type=\"text\"]").attr("placeholder","Verification");
|
||||||
var validated = false,
|
var validated = false,
|
||||||
chks = false,
|
chks = false,
|
||||||
pwd = $('#seminar_signup_password')
|
pwd = $('#seminar_signup_password')
|
||||||
|
$('input[type=submit]').on('click', function(){
|
||||||
|
var form = $(this).parents('form')[0];
|
||||||
|
if (form){
|
||||||
|
window.setTimeout(function(){
|
||||||
|
form.reportValidity();
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
});
|
||||||
$("form.content").submit(function(event) {
|
$("form.content").submit(function(event) {
|
||||||
if (!check_repeat_value(event)){
|
if (!check_repeat_value(event)){
|
||||||
return false;
|
return false;
|
||||||
|
@ -376,6 +396,9 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uploadSubmit(this);
|
||||||
|
return false;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('input[type="email"]').blur(function(){
|
$('input[type="email"]').blur(function(){
|
||||||
|
@ -429,34 +452,43 @@
|
||||||
// $("#seminar_signup_values_3_value").removeAttr("placeholder");
|
// $("#seminar_signup_values_3_value").removeAttr("placeholder");
|
||||||
|
|
||||||
let currentGroup = 1 + $("#new-seminar-signup div[id^=group]:visible").length;
|
let currentGroup = 1 + $("#new-seminar-signup div[id^=group]:visible").length;
|
||||||
|
function showGroup($group){
|
||||||
|
$group.show();
|
||||||
|
$group.find('.fake-clean-file').remove();
|
||||||
|
$group.find('input,textarea').attr("required", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideGroup($group){
|
||||||
|
$group.hide();
|
||||||
|
$group.find("input[type!=hidden], textarea").val("");
|
||||||
|
$.each($group.find("input[type=file]"), function(k, v) {
|
||||||
|
$(v).after("<input class=\"fake-clean-file\" type=\"hidden\" name=\""+$(v).attr('name')+"\" value=\"\">");
|
||||||
|
});
|
||||||
|
$group.find('input,textarea').attr("required", false);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentGroup > 1){
|
if (currentGroup > 1){
|
||||||
$("#remove-member").show();
|
$("#remove-member").show();
|
||||||
|
for (var i = 1; i < currentGroup; i++){
|
||||||
|
showGroup($("#group" + i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$("#add-member").on("click",function () {
|
$("#add-member").on("click",function () {
|
||||||
if(currentGroup < 5){
|
if(currentGroup < 5){
|
||||||
$("#remove-member").show();
|
$("#remove-member").show();
|
||||||
currentGroup++;
|
currentGroup++;
|
||||||
$("#group" + currentGroup).show();
|
|
||||||
$("#group" + currentGroup + " .fake-clean-file").remove();
|
|
||||||
if(currentGroup == 5){
|
if(currentGroup == 5){
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$("#group" + currentGroup + " input").attr("required", true);
|
showGroup($("#group" + currentGroup));
|
||||||
$("#group" + currentGroup + " textarea").attr("required", true);
|
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
$("#remove-member").on("click",function () {
|
$("#remove-member").on("click",function () {
|
||||||
$("#add-member").show();
|
$("#add-member").show();
|
||||||
if(currentGroup > 0){
|
if(currentGroup > 0){
|
||||||
$("#group" + currentGroup).hide();
|
hideGroup($("#group" + currentGroup));
|
||||||
$("#group" + currentGroup + " input").attr("required", false);
|
|
||||||
$("#group" + currentGroup + " input[type!=hidden]").val("");
|
|
||||||
$.each($("#group" + currentGroup + " input[type=file]"), function(k, v) {
|
|
||||||
$(v).after("<input class=\"fake-clean-file\" type=\"hidden\" name=\""+$(v).attr('name')+"\" value=\"\">");
|
|
||||||
});
|
|
||||||
$("#group" + currentGroup + " textarea").attr("required", false);
|
|
||||||
$("#group" + currentGroup + " textarea").val("");
|
|
||||||
currentGroup--;
|
currentGroup--;
|
||||||
if(currentGroup == 1){
|
if(currentGroup == 1){
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
|
|
|
@ -315,22 +315,42 @@
|
||||||
for (var i=0;i< all_values.length;i++){
|
for (var i=0;i< all_values.length;i++){
|
||||||
if (values.includes(all_values[i][1])){
|
if (values.includes(all_values[i][1])){
|
||||||
all_values[i][0].setCustomValidity("<%= t('seminar.repeat_hint') %>");
|
all_values[i][0].setCustomValidity("<%= t('seminar.repeat_hint') %>");
|
||||||
all_values[i][0].reportValidity();
|
all_values[i][0].focus();
|
||||||
|
$(all_values[i][0]).parents('form')[0].reportValidity();
|
||||||
validated = false;
|
validated = false;
|
||||||
window.setTimeout(function(){
|
$(all_values[i][0]).one('keyup change', function(){
|
||||||
all_values[i][0].setCustomValidity("");
|
this.setCustomValidity("");
|
||||||
}, 500);
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
values.push(all_values[i][1]);
|
values.push(all_values[i][1]);
|
||||||
}
|
}
|
||||||
return validated;
|
return validated;
|
||||||
}
|
}
|
||||||
|
function uploadSubmit(form){
|
||||||
|
$.ajax({
|
||||||
|
type: 'post',
|
||||||
|
method: 'post',
|
||||||
|
async: false,
|
||||||
|
contentType: false,
|
||||||
|
processData: false,
|
||||||
|
dataType: "script",
|
||||||
|
url: $(form).attr('action'),
|
||||||
|
data: new FormData(form)
|
||||||
|
});
|
||||||
|
}
|
||||||
$(".rucaptcha-image").siblings("input[type=\"text\"]").attr("placeholder","Verification");
|
$(".rucaptcha-image").siblings("input[type=\"text\"]").attr("placeholder","Verification");
|
||||||
var validated = false,
|
var validated = false,
|
||||||
chks = false,
|
chks = false,
|
||||||
pwd = $('#seminar_signup_password')
|
pwd = $('#seminar_signup_password')
|
||||||
|
$('input[type=submit]').on('click', function(){
|
||||||
|
var form = $(this).parents('form')[0];
|
||||||
|
if (form){
|
||||||
|
window.setTimeout(function(){
|
||||||
|
form.reportValidity();
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
});
|
||||||
$("form.content").submit(function(event) {
|
$("form.content").submit(function(event) {
|
||||||
if (!check_repeat_value(event)){
|
if (!check_repeat_value(event)){
|
||||||
return false;
|
return false;
|
||||||
|
@ -376,6 +396,9 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uploadSubmit(this);
|
||||||
|
return false;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('input[type="email"]').blur(function(){
|
$('input[type="email"]').blur(function(){
|
||||||
|
@ -429,34 +452,43 @@
|
||||||
// $("#seminar_signup_values_3_value").removeAttr("placeholder");
|
// $("#seminar_signup_values_3_value").removeAttr("placeholder");
|
||||||
|
|
||||||
let currentGroup = 1 + $("#new-seminar-signup div[id^=group]:visible").length;
|
let currentGroup = 1 + $("#new-seminar-signup div[id^=group]:visible").length;
|
||||||
|
function showGroup($group){
|
||||||
|
$group.show();
|
||||||
|
$group.find('.fake-clean-file').remove();
|
||||||
|
$group.find('input,textarea').attr("required", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideGroup($group){
|
||||||
|
$group.hide();
|
||||||
|
$group.find("input[type!=hidden], textarea").val("");
|
||||||
|
$.each($group.find("input[type=file]"), function(k, v) {
|
||||||
|
$(v).after("<input class=\"fake-clean-file\" type=\"hidden\" name=\""+$(v).attr('name')+"\" value=\"\">");
|
||||||
|
});
|
||||||
|
$group.find('input,textarea').attr("required", false);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentGroup > 1){
|
if (currentGroup > 1){
|
||||||
$("#remove-member").show();
|
$("#remove-member").show();
|
||||||
|
for (var i = 1; i < currentGroup; i++){
|
||||||
|
showGroup($("#group" + i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$("#add-member").on("click",function () {
|
$("#add-member").on("click",function () {
|
||||||
if(currentGroup < 5){
|
if(currentGroup < 5){
|
||||||
$("#remove-member").show();
|
$("#remove-member").show();
|
||||||
currentGroup++;
|
currentGroup++;
|
||||||
$("#group" + currentGroup).show();
|
|
||||||
$("#group" + currentGroup + " .fake-clean-file").remove();
|
|
||||||
if(currentGroup == 5){
|
if(currentGroup == 5){
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$("#group" + currentGroup + " input").attr("required", true);
|
showGroup($("#group" + currentGroup));
|
||||||
$("#group" + currentGroup + " textarea").attr("required", true);
|
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
$("#remove-member").on("click",function () {
|
$("#remove-member").on("click",function () {
|
||||||
$("#add-member").show();
|
$("#add-member").show();
|
||||||
if(currentGroup > 0){
|
if(currentGroup > 0){
|
||||||
$("#group" + currentGroup).hide();
|
hideGroup($("#group" + currentGroup));
|
||||||
$("#group" + currentGroup + " input").attr("required", false);
|
|
||||||
$("#group" + currentGroup + " input[type!=hidden]").val("");
|
|
||||||
$.each($("#group" + currentGroup + " input[type=file]"), function(k, v) {
|
|
||||||
$(v).after("<input class=\"fake-clean-file\" type=\"hidden\" name=\""+$(v).attr('name')+"\" value=\"\">");
|
|
||||||
});
|
|
||||||
$("#group" + currentGroup + " textarea").attr("required", false);
|
|
||||||
$("#group" + currentGroup + " textarea").val("");
|
|
||||||
currentGroup--;
|
currentGroup--;
|
||||||
if(currentGroup == 1){
|
if(currentGroup == 1){
|
||||||
$(this).hide();
|
$(this).hide();
|
||||||
|
|
Loading…
Reference in New Issue