Edit enterprise fee

This commit is contained in:
Rohan Mitchell
2012-11-21 11:50:37 +11:00
parent bcc2ef99fd
commit 77b78f5bbb
3 changed files with 60 additions and 6 deletions

View File

@@ -0,0 +1,26 @@
// Hide calculator preference fields when calculator type changed
// Fixes 'Enterprise fee is not found' error when changing calculator type
// See spree/core/app/assets/javascripts/admin/calculator.js
$(document).ready(function() {
// Store original value
$("select.calculator_type").each(function(i, ct) {
ct = $(ct);
ct.data('original-value', ct.attr('value'));
});
// Hide and disable calculator fields when calculator type is changed
$("select.calculator_type").change(function() {
var ct = $(this);
var cs = ct.parent().parent().find("div.calculator-settings");
if(ct.attr('value') == ct.data('original-value')) {
cs.show();
cs.find("input").prop("disabled", false);
} else {
cs.hide();
cs.find("input").prop("disabled", true);
}
});
});

View File

@@ -20,10 +20,11 @@
%td= f.collection_select :enterprise_id, Enterprise.all, :id, :name, :include_blank => true
%td= f.select :fee_type, enterprise_fee_options
%td= f.text_field :name
%td= f.collection_select :calculator_type, @calculators, :name, :description
%td= f.collection_select :calculator_type, @calculators, :name, :description, {}, {:class => 'calculator_type'}
%td
- if !enterprise_fee.new_record?
= f.fields_for :calculator do |calculator_form|
= preference_fields(enterprise_fee.calculator, calculator_form)
.calculator-settings
= f.fields_for :calculator do |calculator_form|
= preference_fields(enterprise_fee.calculator, calculator_form)
%td TODO
= enterprise_fee_set_form.submit 'Update'

View File

@@ -14,10 +14,10 @@ feature %q{
click_link 'Configuration'
click_link 'Enterprise Fees'
page.should have_selector 'option', text: fee.enterprise.name
page.should have_selector 'option', text: 'Packing'
page.should have_selector "option[selected]", text: fee.enterprise.name
page.should have_selector "option[selected]", text: 'Packing'
page.should have_selector "input[value='$0.50 / kg']"
page.should have_selector 'option', text: 'Weight (per kg)'
page.should have_selector "option[selected]", text: 'Weight (per kg)'
page.should have_selector "input[value='0.5']"
end
@@ -49,4 +49,31 @@ feature %q{
page.should have_selector "#enterprise_fee_set_collection_attributes_0_calculator_attributes_preferred_flat_percent[value='12.34']"
end
scenario "editing an enterprise fee", js: true do
# Given an enterprise fee
fee = create(:enterprise_fee)
create(:enterprise, name: 'Foo')
# When I go to the enterprise fees page
login_to_admin_section
click_link 'Configuration'
click_link 'Enterprise Fees'
binding.pry
# And I update the fields for the enterprise fee and click update
select 'Foo', from: 'enterprise_fee_set_collection_attributes_0_enterprise_id'
select 'Admin', from: 'enterprise_fee_set_collection_attributes_0_fee_type'
fill_in 'enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!'
select 'Flat Percent', from: 'enterprise_fee_set_collection_attributes_0_calculator_type'
binding.pry
click_button 'Update'
# Then I should see the updated fields for my fee
page.should have_selector "option[selected]", text: 'Foo'
page.should have_selector "option[selected]", text: 'Admin'
page.should have_selector "input[value='Greetings!']"
page.should have_selector "option[selected]", text: 'Flat Percent'
end
end