Mark admin enterprises form dirty when property removed

This commit is contained in:
Rohan Mitchell
2016-08-31 15:40:21 +10:00
parent 0e01350107
commit 3e565ad7cb
4 changed files with 19 additions and 2 deletions

View File

@@ -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."

View File

@@ -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

View File

@@ -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}

View File

@@ -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