From debf60d3af6a46aa72ada394aaafd450c8fdda8d Mon Sep 17 00:00:00 2001 From: BrentyMcFatty Date: Fri, 28 Oct 2022 00:59:50 +0200 Subject: [PATCH 1/3] bank payment notice being deleted when a free ticket is selected --- app/assets/javascripts/registrations.js | 11 +++++++++++ app/views/registrations/_form.html.erb | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/registrations.js b/app/assets/javascripts/registrations.js index 66b33b47..b79bd529 100644 --- a/app/assets/javascripts/registrations.js +++ b/app/assets/javascripts/registrations.js @@ -39,10 +39,21 @@ $(document).on('turbolinks:load', function() { } }; + const hidePaymentInfoIfNeeded = function(value) { + + if (value.search("€") === -1) { + $("#payment-info").hide(); + } else { + $("#payment-info").show(); + } + }; + $("#registration_access_level").on('change', function() { + hidePaymentInfoIfNeeded($("option:selected", this).text()); return hideCommentFieldIfNeeded($(this).val()); }); + hidePaymentInfoIfNeeded($("#registration_access_level option:selected").text()); return hideCommentFieldIfNeeded($("#registration_access_level").val()); }); diff --git a/app/views/registrations/_form.html.erb b/app/views/registrations/_form.html.erb index 831aaeb4..a82830c2 100644 --- a/app/views/registrations/_form.html.erb +++ b/app/views/registrations/_form.html.erb @@ -17,8 +17,8 @@ <% end %>

-
+
Payments can be done by bank transfer, not by credit card.
-
+ \ No newline at end of file From 2eccb32d16610815694b7c7da74f1d8c64473446 Mon Sep 17 00:00:00 2001 From: BrentyMcFatty Date: Fri, 28 Oct 2022 01:52:28 +0200 Subject: [PATCH 2/3] trying to make solution less scuffed and bug-free --- app/assets/javascripts/registrations.js | 8 ++++---- app/views/registrations/_form.html.erb | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/registrations.js b/app/assets/javascripts/registrations.js index b79bd529..9ac4ca91 100644 --- a/app/assets/javascripts/registrations.js +++ b/app/assets/javascripts/registrations.js @@ -40,8 +40,8 @@ $(document).on('turbolinks:load', function() { }; const hidePaymentInfoIfNeeded = function(value) { - - if (value.search("€") === -1) { + const val = parseInt(value); + if (window.freeTickets && (window.freeTickets.indexOf(val) !== -1)) { $("#payment-info").hide(); } else { $("#payment-info").show(); @@ -49,11 +49,11 @@ $(document).on('turbolinks:load', function() { }; $("#registration_access_level").on('change', function() { - hidePaymentInfoIfNeeded($("option:selected", this).text()); + hidePaymentInfoIfNeeded($(this).val()); return hideCommentFieldIfNeeded($(this).val()); }); - hidePaymentInfoIfNeeded($("#registration_access_level option:selected").text()); + hidePaymentInfoIfNeeded($("#registration_access_level").val()); return hideCommentFieldIfNeeded($("#registration_access_level").val()); }); diff --git a/app/views/registrations/_form.html.erb b/app/views/registrations/_form.html.erb index a82830c2..67dc876a 100644 --- a/app/views/registrations/_form.html.erb +++ b/app/views/registrations/_form.html.erb @@ -12,6 +12,9 @@ <%= form_text_area f, :comment %> <%= javascript_tag do %> window.ticketsWithComments = <%= @event.access_levels.find_all(&:has_comment).map(&:id).to_json %> + window.freeTickets = <%= @event.access_levels.find_all{|_| :price == 0}.map(&:id).to_json %> + access_levels = <%= @event.access_levels.find_all{|_| true}.to_json %> + console.log("poop") <% end %> <%= f.submit "Register", class: 'btn btn-group btn-primary' %> <% end %> From 7f1d06533d8ac3b38cc6107bdbcbe52f0a13754c Mon Sep 17 00:00:00 2001 From: Xander Date: Wed, 19 Apr 2023 22:52:42 +0200 Subject: [PATCH 3/3] Fixes bugs --- app/assets/javascripts/registrations.js | 6 +++--- app/views/registrations/_form.html.erb | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/registrations.js b/app/assets/javascripts/registrations.js index 9ac4ca91..61aaeb1c 100644 --- a/app/assets/javascripts/registrations.js +++ b/app/assets/javascripts/registrations.js @@ -41,7 +41,7 @@ $(document).on('turbolinks:load', function() { const hidePaymentInfoIfNeeded = function(value) { const val = parseInt(value); - if (window.freeTickets && (window.freeTickets.indexOf(val) !== -1)) { + if (window.freeTickets && window.freeTickets.includes(val)) { $("#payment-info").hide(); } else { $("#payment-info").show(); @@ -50,10 +50,10 @@ $(document).on('turbolinks:load', function() { $("#registration_access_level").on('change', function() { hidePaymentInfoIfNeeded($(this).val()); - return hideCommentFieldIfNeeded($(this).val()); + hideCommentFieldIfNeeded($(this).val()); }); hidePaymentInfoIfNeeded($("#registration_access_level").val()); - return hideCommentFieldIfNeeded($("#registration_access_level").val()); + hideCommentFieldIfNeeded($("#registration_access_level").val()); }); diff --git a/app/views/registrations/_form.html.erb b/app/views/registrations/_form.html.erb index 67dc876a..6079fd3e 100644 --- a/app/views/registrations/_form.html.erb +++ b/app/views/registrations/_form.html.erb @@ -12,9 +12,7 @@ <%= form_text_area f, :comment %> <%= javascript_tag do %> window.ticketsWithComments = <%= @event.access_levels.find_all(&:has_comment).map(&:id).to_json %> - window.freeTickets = <%= @event.access_levels.find_all{|_| :price == 0}.map(&:id).to_json %> - access_levels = <%= @event.access_levels.find_all{|_| true}.to_json %> - console.log("poop") + window.freeTickets = <%= @event.access_levels.where(price: 0).map(&:id).to_json %> <% end %> <%= f.submit "Register", class: 'btn btn-group btn-primary' %> <% end %> @@ -24,4 +22,4 @@ Payments can be done by bank transfer, not by credit card. - \ No newline at end of file +