Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Fix form for donations thermometer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuuleh committed Nov 22, 2018
1 parent f759950 commit 9aa2b9d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/models/plugins/donations_thermometer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/views/plugins/actions_thermometers/_form.slim
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
15 changes: 13 additions & 2 deletions app/views/plugins/donations_thermometers/_form.slim
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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);
})
});
1 change: 1 addition & 0 deletions spec/liquid/liquid_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9aa2b9d

Please sign in to comment.