diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index f21c96a27e..0a68ce9d94 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -27,7 +27,7 @@ angular.module("admin.enterprises") # Provide a callback for generating warning messages displayed before leaving the page. This is passed in # from a directive "nav-check" in the page - if we pass it here it will be called in the test suite, - # and on all new uses of this contoller, and we might not want that . + # and on all new uses of this contoller, and we might not want that. enterpriseNavCallback = -> if $scope.Enterprise.$dirty "Your changes to the enterprise are not saved yet." diff --git a/app/helpers/spree/admin/base_helper_decorator.rb b/app/helpers/spree/admin/base_helper_decorator.rb index ff9e2b76a7..9430ab8733 100644 --- a/app/helpers/spree/admin/base_helper_decorator.rb +++ b/app/helpers/spree/admin/base_helper_decorator.rb @@ -9,6 +9,20 @@ module Spree end end alias_method_chain :preference_field_tag, :files + + + # Add support for options[:html], allowing additional HTML attributes + 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] + + html_options = {class: "remove_fields #{options[:class]}", data: {action: 'remove'}, title: t(:remove)} + html_options.merge!(options[:html]) + + link_to_with_icon('icon-trash', name, '#', html_options) + f.hidden_field(:_destroy) + end + end end end diff --git a/app/views/admin/producer_properties/_producer_property_fields.html.haml b/app/views/admin/producer_properties/_producer_property_fields.html.haml index 314cbfc31a..6fe0b1d7ad 100644 --- a/app/views/admin/producer_properties/_producer_property_fields.html.haml +++ b/app/views/admin/producer_properties/_producer_property_fields.html.haml @@ -12,4 +12,4 @@ = f.text_field :value, :class => 'autocomplete' %td.actions - unless @enterprise.producer_properties.empty? - = link_to_remove_fields t(:remove), f, no_text: true, url: (f.object.persisted? && main_app.admin_enterprise_producer_property_path(@enterprise, f.object)) + = link_to_remove_fields t(:remove), f, no_text: true, url: (f.object.persisted? && main_app.admin_enterprise_producer_property_path(@enterprise, f.object)), html: {"onclick" => "if(typeof(enterprise_form) != 'undefined') { angular.element(enterprise_form).scope().setFormDirty() }".html_safe} diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 8b5a08a7cc..c051c9eade 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -439,7 +439,10 @@ feature %q{ end within("#spree_producer_property_#{pp.id}") { page.find('a.remove_fields').click } + click_button 'Update' + + expect(page).to have_content 'Enterprise "First Supplier" has been successfully updated!' supplier1.producer_properties(true).should be_empty end end