From 4c4bdd78e77a0890f93ca637daf3c52c27360a17 Mon Sep 17 00:00:00 2001 From: Jackson Bates Date: Tue, 1 Oct 2019 22:13:28 +1000 Subject: [PATCH 1/4] makes edit button action open a new tab --- app/assets/javascripts/admin/bulk_product_update.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index e220f2bb41..fd85a0def4 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -110,7 +110,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout $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" + window.open("/admin/products/" + product.permalink_live + ((if variant then "/variants/" + variant.id else "")) + "/edit", "_blank") $scope.toggleShowAllVariants = -> From 7c264af0c2517a2f2994dd314ec209a611de212c Mon Sep 17 00:00:00 2001 From: Jackson Bates Date: Thu, 3 Oct 2019 22:32:43 +1000 Subject: [PATCH 2/4] updates specs for new edit button behaviour --- .../admin/bulk_product_update_spec.rb | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index f18854e4d1..bbd8d9417c 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -516,11 +516,16 @@ feature ' it "shows an edit button for products, which takes the user to the standard edit page for that product" 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 @@ -529,11 +534,16 @@ feature ' 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 From 8d30dc997f0a8c7b144806bae05da756670a2653 Mon Sep 17 00:00:00 2001 From: Jackson Bates Date: Wed, 16 Oct 2019 21:55:52 +1100 Subject: [PATCH 3/4] adds better description to specs and refactors editProductUrl and confirm_unsaved_changes --- .../javascripts/admin/bulk_product_update.js.coffee | 8 ++++++-- spec/features/admin/bulk_product_update_spec.rb | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index fd85a0def4..43158d04c1 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -108,9 +108,13 @@ 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.open("/admin/products/" + product.permalink_live + ((if variant then "/variants/" + variant.id else "")) + "/edit", "_blank") + 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 bbd8d9417c..b378631702 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -513,7 +513,7 @@ 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 new_window = window_opened_by do @@ -528,7 +528,7 @@ feature ' 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) From 4d49dc3689b167b249cf91a5911589768d730641 Mon Sep 17 00:00:00 2001 From: Jackson Bates Date: Wed, 16 Oct 2019 23:01:38 +1100 Subject: [PATCH 4/4] adds line breaks to methods for readability --- app/assets/javascripts/admin/bulk_product_update.js.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 43158d04c1..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,11 @@ 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) + 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" + editProductUrl = (product, variant) -> + "/admin/products/" + product.permalink_live + ((if variant then "/variants/" + variant.id else "")) + "/edit" $scope.editWarn = (product, variant) -> if confirm_unsaved_changes()