diff --git a/app/controllers/seminars_controller.rb b/app/controllers/seminars_controller.rb index 2bf9443..24634e2 100644 --- a/app/controllers/seminars_controller.rb +++ b/app/controllers/seminars_controller.rb @@ -383,7 +383,7 @@ class SeminarsController < ApplicationController 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 { "seminar" => seminar, "seminar_signup" => seminar_signup, @@ -443,7 +443,7 @@ class SeminarsController < ApplicationController if @seminar.enable_recaptcha && (!gotcha_valid?) notice_words = t('recaptcha.errors.verification_failed') referer_url = get_referer_url_for_notice(notice_words) - redirect_to referer_url, :notice => notice_words + show_alert(notice_words) return end signup_limit = @seminar.signup_limit @@ -462,7 +462,7 @@ class SeminarsController < ApplicationController else notice_words = t('seminar.sign_up_is_full') referer_url = get_referer_url_for_notice(notice_words) - redirect_to referer_url, :notice => notice_words + show_alert(notice_words) return end end @@ -471,7 +471,7 @@ class SeminarsController < ApplicationController if signup_limit <= signup_count notice_words = t('seminar.sign_up_is_full') referer_url = get_referer_url_for_notice(notice_words) - redirect_to referer_url, :notice => notice_words + show_alert(notice_words) return end end @@ -518,7 +518,9 @@ class SeminarsController < ApplicationController end send_mail('signup',params[:seminar_signup][:email],params[:seminar_signup][:seminar_main_id],extra_text) 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 if has_counter OrbitHelper::SharedMutex.synchronize do @@ -528,11 +530,11 @@ class SeminarsController < ApplicationController if !not_signup_yet notice_words = t('seminar.email_exist') referer_url = get_referer_url_for_notice(notice_words) - redirect_to referer_url, :notice => notice_words + show_alert(notice_words) else notice_words = t('seminar.sign_up_failed') referer_url = get_referer_url_for_notice(notice_words) - redirect_to referer_url, :notice => notice_words + show_alert(notice_words) end end @@ -572,7 +574,7 @@ class SeminarsController < ApplicationController end send_mail('signup',tmp_seminar_signup_params[:email],tmp_seminar_signup_params[:seminar_main_id],extra_text) 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 def signup_ok @@ -934,4 +936,20 @@ class SeminarsController < ApplicationController def seminar_signup_values_params params.require(:seminar_signup_values).permit! 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 diff --git a/app/views/seminars/edit_login_seminar_signup.html.erb b/app/views/seminars/edit_login_seminar_signup.html.erb index 2e95b22..a5ab61e 100644 --- a/app/views/seminars/edit_login_seminar_signup.html.erb +++ b/app/views/seminars/edit_login_seminar_signup.html.erb @@ -315,22 +315,42 @@ for (var i=0;i< all_values.length;i++){ if (values.includes(all_values[i][1])){ 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; - window.setTimeout(function(){ - all_values[i][0].setCustomValidity(""); - }, 500); + $(all_values[i][0]).one('keyup change', function(){ + this.setCustomValidity(""); + }); break; } values.push(all_values[i][1]); } 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"); var validated = false, chks = false, 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) { if (!check_repeat_value(event)){ return false; @@ -376,6 +396,9 @@ return false; } + uploadSubmit(this); + return false; + }); $('input[type="email"]').blur(function(){ @@ -429,34 +452,43 @@ // $("#seminar_signup_values_3_value").removeAttr("placeholder"); 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(""); + }); + $group.find('input,textarea').attr("required", false); + } + if (currentGroup > 1){ $("#remove-member").show(); + for (var i = 1; i < currentGroup; i++){ + showGroup($("#group" + i)); + } } + $("#add-member").on("click",function () { if(currentGroup < 5){ $("#remove-member").show(); currentGroup++; - $("#group" + currentGroup).show(); - $("#group" + currentGroup + " .fake-clean-file").remove(); if(currentGroup == 5){ $(this).hide(); } } - $("#group" + currentGroup + " input").attr("required", true); - $("#group" + currentGroup + " textarea").attr("required", true); + showGroup($("#group" + currentGroup)); return false; }) $("#remove-member").on("click",function () { $("#add-member").show(); if(currentGroup > 0){ - $("#group" + currentGroup).hide(); - $("#group" + currentGroup + " input").attr("required", false); - $("#group" + currentGroup + " input[type!=hidden]").val(""); - $.each($("#group" + currentGroup + " input[type=file]"), function(k, v) { - $(v).after(""); - }); - $("#group" + currentGroup + " textarea").attr("required", false); - $("#group" + currentGroup + " textarea").val(""); + hideGroup($("#group" + currentGroup)); currentGroup--; if(currentGroup == 1){ $(this).hide(); diff --git a/app/views/seminars/show.html.erb b/app/views/seminars/show.html.erb index 2e95b22..a5ab61e 100644 --- a/app/views/seminars/show.html.erb +++ b/app/views/seminars/show.html.erb @@ -315,22 +315,42 @@ for (var i=0;i< all_values.length;i++){ if (values.includes(all_values[i][1])){ 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; - window.setTimeout(function(){ - all_values[i][0].setCustomValidity(""); - }, 500); + $(all_values[i][0]).one('keyup change', function(){ + this.setCustomValidity(""); + }); break; } values.push(all_values[i][1]); } 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"); var validated = false, chks = false, 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) { if (!check_repeat_value(event)){ return false; @@ -376,6 +396,9 @@ return false; } + uploadSubmit(this); + return false; + }); $('input[type="email"]').blur(function(){ @@ -429,34 +452,43 @@ // $("#seminar_signup_values_3_value").removeAttr("placeholder"); 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(""); + }); + $group.find('input,textarea').attr("required", false); + } + if (currentGroup > 1){ $("#remove-member").show(); + for (var i = 1; i < currentGroup; i++){ + showGroup($("#group" + i)); + } } + $("#add-member").on("click",function () { if(currentGroup < 5){ $("#remove-member").show(); currentGroup++; - $("#group" + currentGroup).show(); - $("#group" + currentGroup + " .fake-clean-file").remove(); if(currentGroup == 5){ $(this).hide(); } } - $("#group" + currentGroup + " input").attr("required", true); - $("#group" + currentGroup + " textarea").attr("required", true); + showGroup($("#group" + currentGroup)); return false; }) $("#remove-member").on("click",function () { $("#add-member").show(); if(currentGroup > 0){ - $("#group" + currentGroup).hide(); - $("#group" + currentGroup + " input").attr("required", false); - $("#group" + currentGroup + " input[type!=hidden]").val(""); - $.each($("#group" + currentGroup + " input[type=file]"), function(k, v) { - $(v).after(""); - }); - $("#group" + currentGroup + " textarea").attr("required", false); - $("#group" + currentGroup + " textarea").val(""); + hideGroup($("#group" + currentGroup)); currentGroup--; if(currentGroup == 1){ $(this).hide();