Fix link_to_remove_fields - does not immediately delete the field

This commit is contained in:
Rohan Mitchell
2016-06-10 11:24:23 +10:00
parent 48acf80c85
commit f33df883a0
4 changed files with 23 additions and 29 deletions

View File

@@ -30,8 +30,16 @@ show_flash_error = function(message) {
}
$(document).ready(function(){
$('a.close').click(function(event){
event.preventDefault();
$(this).parent().slideUp(250);
});
$('a.close').click(function(event){
event.preventDefault();
$(this).parent().slideUp(250);
});
// Spree locates hidden with prev(), which with our current version of jQuery
// does not locate the hidden field, resulting in the delete failing. This
// handler updates the hidden field, fixing the problem.
$('body').on('click', 'a.remove_fields', function() {
$(this).next("input[type=hidden]").val("1");
return false;
});
});

View File

@@ -271,9 +271,10 @@ module Admin
# Overriding method on Spree's resource controller
def location_after_save
referer_path = OpenFoodNetwork::RefererParser::path(request.referer)
refered_from_edit = referer_path =~ /\/edit$/
if params[:enterprise].key?(:producer_properties_attributes) && !refered_from_edit
main_app.admin_enterprises_path
refered_from_producer_properties = referer_path =~ /\/producer_properties$/
if refered_from_producer_properties
main_app.admin_enterprise_producer_properties_path(@enterprise)
else
main_app.edit_admin_enterprise_path(@enterprise)
end

View File

@@ -1,22 +1,6 @@
module Spree
module Admin
module BaseHelper
# Add url option to pass in link URL
def link_to_remove_fields(name, f, options = {})
name = '' if options[:no_text]
options[:class] = '' unless options[:class]
options[:class] += 'no-text' if options[:no_text]
url = if f.object.persisted?
options[:url] || [:admin, f.object]
else
'#'
end
link_to_with_icon('icon-trash', name, url, :class => "remove_fields #{options[:class]}", :data => {:action => 'remove'}, :title => t(:remove)) + f.hidden_field(:_destroy)
end
def preference_field_tag_with_files(name, value, options)
if options[:type] == :file
file_field_tag name, preference_field_options(options)

View File

@@ -210,8 +210,8 @@ feature %q{
fill_in 'enterprise_producer_properties_attributes_0_value', with: "NASAA 12345"
click_button 'Update'
# Then I should be returned to the enterprises page
page.should have_selector '#listing_enterprises a', text: s.name
# Then I should remain on the producer properties page
expect(current_path).to eq main_app.admin_enterprise_producer_properties_path(s)
# And the producer should have the property
s.producer_properties(true).count.should == 1
@@ -233,8 +233,8 @@ feature %q{
fill_in 'enterprise_producer_properties_attributes_0_value', with: "Shininess"
click_button 'Update'
# Then I should be returned to the enterprises
page.should have_selector '#listing_enterprises a', text: s.name
# Then I should remain on the producer properties page
expect(current_path).to eq main_app.admin_enterprise_producer_properties_path(s)
# And the property should be updated
s.producer_properties(true).count.should == 1
@@ -254,9 +254,10 @@ feature %q{
# And I remove the property
page.should have_field 'enterprise_producer_properties_attributes_0_property_name', with: 'Certified Organic'
within("#spree_producer_property_#{pp.id}") { page.find('a.remove_fields').click }
click_button 'Update'
# Then the property should have been removed
page.should_not have_selector '#progress'
expect(current_path).to eq main_app.admin_enterprise_producer_properties_path(s)
page.should_not have_field 'enterprise_producer_properties_attributes_0_property_name', with: 'Certified Organic'
s.producer_properties(true).should be_empty
end
@@ -438,7 +439,7 @@ feature %q{
end
within("#spree_producer_property_#{pp.id}") { page.find('a.remove_fields').click }
page.should_not have_selector '#progress'
click_button 'Update'
supplier1.producer_properties(true).should be_empty
end
end