From 9aa2b9d041f74d28a75a756d9c282fd8a0aba1cf Mon Sep 17 00:00:00 2001 From: tuuli Date: Thu, 22 Nov 2018 17:39:11 +0100 Subject: [PATCH] Fix form for donations thermometer --- app/models/plugins/donations_thermometer.rb | 2 +- app/views/plugins/actions_thermometers/_form.slim | 2 ++ .../plugins/donations_thermometers/_form.slim | 15 +++++++++++++-- spec/liquid/liquid_renderer_spec.rb | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/models/plugins/donations_thermometer.rb b/app/models/plugins/donations_thermometer.rb index f977116694..697510f645 100644 --- a/app/models/plugins/donations_thermometer.rb +++ b/app/models/plugins/donations_thermometer.rb @@ -37,7 +37,7 @@ def liquid_data(_supplemental_data = {}) def currencies_hash(amount) # Get a hash with amount converted into all supported currencies. # Transform values from arrays of amounts to single amounts (e.g. GBP: [10] to GBP: 10) - Donations::Currencies.for([amount]).to_hash.with_indifferent_access.transform_values(&:pop) + Donations::Currencies.for([amount]).to_hash.with_indifferent_access.transform_values(&:pop).transform_values(&:to_d) end def fundraising_goal diff --git a/app/views/plugins/actions_thermometers/_form.slim b/app/views/plugins/actions_thermometers/_form.slim index 20cb4eb3a3..c2776a2f3e 100644 --- a/app/views/plugins/actions_thermometers/_form.slim +++ b/app/views/plugins/actions_thermometers/_form.slim @@ -1,4 +1,6 @@ .col-md-7 + // There's a single ThermometersController that handles both actions and donations thermometers, so use the + // generic plugins_thermometer_path for the toggle. = render partial: 'plugins/shared/toggle_form', locals: { plugin: plugin, path: plugins_thermometer_path(plugin) } - name = "plugins_actions_thermometer_#{plugin.id}" diff --git a/app/views/plugins/donations_thermometers/_form.slim b/app/views/plugins/donations_thermometers/_form.slim index e153d67621..4ad4413d1b 100644 --- a/app/views/plugins/donations_thermometers/_form.slim +++ b/app/views/plugins/donations_thermometers/_form.slim @@ -1,4 +1,6 @@ .col-md-7 + // There's a single ThermometersController that handles both actions and donations thermometers, so use the + // generic plugins_thermometer_path for the toggle. = render partial: 'plugins/shared/toggle_form', locals: { plugin: plugin, path: plugins_thermometer_path(plugin) } - name = "plugins_donations_thermometer_#{plugin.id}" @@ -8,5 +10,14 @@ = render 'plugins/shared/plugin_metadata', f: f .form-group - = label_with_tooltip(f, :offset, t('plugins.thermometer.offset'), t('tooltips.thermometer.donations.offset')) - = f.text_field(:offset, class: 'form-control') + = label_with_tooltip(f, :offset_amount, t('plugins.thermometer.offset'), t('tooltips.thermometer.donations.offset')) + = number_field_tag :offset_amount, plugin.offset/100, class: 'form-control' + = f.hidden_field :offset, class: 'offset-in-cents' + +javascript: + $(function () { + $('#offset_amount').on('change', function(){ + // change the value of the hidden offset-in-cents field to the manually entered offset amount * 100 + $('.offset-in-cents').val($(this).val() * 100); + }) + }); diff --git a/spec/liquid/liquid_renderer_spec.rb b/spec/liquid/liquid_renderer_spec.rb index 2584fe9596..c2325e6cbf 100644 --- a/spec/liquid/liquid_renderer_spec.rb +++ b/spec/liquid/liquid_renderer_spec.rb @@ -220,6 +220,7 @@ end before :each do + allow_any_instance_of(Plugins::DonationsThermometer).to receive(:liquid_data).and_return({}) allow(PaymentProcessor::Currency).to receive(:convert) end