diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index e220f2bb41..4cb79b6a4b 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -108,9 +108,15 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout $scope.categoryFilter = "0" $scope.importDateFilter = "0" + confirm_unsaved_changes = () -> + (DirtyProducts.count() > 0 and confirm(t("unsaved_changes_confirmation"))) or (DirtyProducts.count() == 0) + + editProductUrl = (product, variant) -> + "/admin/products/" + product.permalink_live + ((if variant then "/variants/" + variant.id else "")) + "/edit" + $scope.editWarn = (product, variant) -> - if (DirtyProducts.count() > 0 and confirm(t("unsaved_changes_confirmation"))) or (DirtyProducts.count() == 0) - window.location = "/admin/products/" + product.permalink_live + ((if variant then "/variants/" + variant.id else "")) + "/edit" + if confirm_unsaved_changes() + window.open(editProductUrl(product, variant), "_blank") $scope.toggleShowAllVariants = -> diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index f18854e4d1..b378631702 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -513,27 +513,37 @@ feature ' visit spree.admin_products_path end - it "shows an edit button for products, which takes the user to the standard edit page for that product" do + it "shows an edit button for products, which takes the user to the standard edit page for that product in a new window" do expect(page).to have_selector "a.edit-product", count: 2 - within "tr#p_#{p1.id}" do - find("a.edit-product").click + new_window = window_opened_by do + within "tr#p_#{p1.id}" do + find("a.edit-product").click + end end - expect(URI.parse(current_url).path).to eq "/admin/products/#{p1.permalink}/edit" + within_window new_window do + expect(URI.parse(current_url).path).to eq "/admin/products/#{p1.permalink}/edit" + page.execute_script('window.close()') + end end - it "shows an edit button for variants, which takes the user to the standard edit page for that variant" do + it "shows an edit button for variants, which takes the user to the standard edit page for that variant in a new window" do expect(page).to have_selector "a.view-variants" all("a.view-variants").each(&:click) expect(page).to have_selector "a.edit-variant", count: 2 - within "tr#v_#{v1.id}" do - find("a.edit-variant").click + new_window = window_opened_by do + within "tr#v_#{v1.id}" do + find("a.edit-variant").click + end end - expect(URI.parse(current_url).path).to eq "/admin/products/#{v1.product.permalink}/variants/#{v1.id}/edit" + within_window new_window do + expect(URI.parse(current_url).path).to eq "/admin/products/#{v1.product.permalink}/variants/#{v1.id}/edit" + page.execute_script('window.close()') + end end end