From 6cadd2499267a7a16d2596666e53d901b50aa15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 11 Oct 2023 22:04:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=BE=A9=E9=8C=AF=E8=AA=A4=E8=A8=8A?= =?UTF-8?q?=E6=81=AF=E7=84=A1=E6=B3=95=E9=A1=AF=E7=A4=BA=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=EF=BC=8C=E5=B0=87=E8=A1=A8=E5=96=AE=E6=94=B9=E7=82=BAajax?= =?UTF-8?q?=E9=80=81=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/seminars_controller.rb | 34 +++++++--- .../edit_login_seminar_signup.html.erb | 66 ++++++++++++++----- app/views/seminars/show.html.erb | 66 ++++++++++++++----- 3 files changed, 124 insertions(+), 42 deletions(-) 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();