mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Admin can remove producer properties
This commit is contained in:
@@ -1,19 +1,25 @@
|
||||
module Admin
|
||||
class ProducerPropertiesController < ResourceController
|
||||
before_filter :find_properties
|
||||
|
||||
before_filter :load_enterprise
|
||||
before_filter :load_properties
|
||||
before_filter :setup_property, only: [:index]
|
||||
|
||||
|
||||
|
||||
private
|
||||
|
||||
def find_properties
|
||||
def collection_url
|
||||
main_app.admin_enterprise_producer_properties_url(@enterprise)
|
||||
end
|
||||
|
||||
def load_enterprise
|
||||
@enterprise = Enterprise.find params[:enterprise_id]
|
||||
end
|
||||
|
||||
def load_properties
|
||||
@properties = Spree::Property.pluck(:name)
|
||||
end
|
||||
|
||||
def setup_property
|
||||
@enterprise = Enterprise.find params[:enterprise_id]
|
||||
@enterprise.producer_properties.build
|
||||
end
|
||||
end
|
||||
|
||||
20
app/helpers/spree/admin/base_helper_decorator.rb
Normal file
20
app/helpers/spree/admin/base_helper_decorator.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
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 with-tip' 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
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,4 +8,4 @@
|
||||
= f.text_field :value, :class => 'autocomplete'
|
||||
%td.actions
|
||||
- unless @enterprise.producer_properties.empty?
|
||||
-#= link_to_remove_fields t(:remove), f, :no_text => true
|
||||
= link_to_remove_fields t(:remove), f, no_text: true, url: (f.object.persisted? && main_app.admin_enterprise_producer_property_path(@enterprise, f.object))
|
||||
|
||||
@@ -206,6 +206,25 @@ feature %q{
|
||||
s.producer_properties.first.property.presentation.should == "Biodynamic"
|
||||
s.producer_properties.first.value.should == "Shininess"
|
||||
end
|
||||
|
||||
it "removes producer properties", js: true do
|
||||
# Given a producer enterprise with a property
|
||||
s = create(:supplier_enterprise)
|
||||
pp = s.producer_properties.create! property_name: 'Certified Organic', value: 'NASAA 12345'
|
||||
|
||||
# When I go to its properties page
|
||||
login_to_admin_section
|
||||
visit main_app.admin_enterprise_producer_properties_path(s)
|
||||
|
||||
# And I remove the property
|
||||
page.should have_field 'enterprise_producer_properties_attributes_0_property_name', with: 'Certified Organic'
|
||||
within("#producer_property_#{pp.id}") { page.find('a.remove_fields').click }
|
||||
|
||||
# Then the property should have been removed
|
||||
page.should_not have_field 'enterprise_producer_properties_attributes_0_property_name', with: 'Certified Organic'
|
||||
page.should_not have_selector '#progress'
|
||||
s.producer_properties(true).should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user