diff --git a/app/assets/javascripts/admin/spree/orders/shipments.js.erb b/app/assets/javascripts/admin/spree/orders/shipments.js.erb
index 16cce0932d..aba5848c9d 100644
--- a/app/assets/javascripts/admin/spree/orders/shipments.js.erb
+++ b/app/assets/javascripts/admin/spree/orders/shipments.js.erb
@@ -69,15 +69,19 @@ $(document).ready(function() {
var tracking = ''
var url = Spree.url( Spree.routes.orders_api + "/" + order_number + "/shipments/" + shipment_number + ".json");
- $.ajax({
- type: "PUT",
- url: url,
- data: { shipment: { tracking: tracking } }
- }).done(function( msg ) {
- window.location.reload();
- }).error(function( msg ) {
- console.log(msg);
- });
+ displayDeleteAlert(function(choice) {
+ if (choice) {
+ $.ajax({
+ type: "PUT",
+ url: url,
+ data: { shipment: { tracking: tracking } }
+ }).done(function( msg ) {
+ window.location.reload();
+ }).error(function( msg ) {
+ console.log(msg);
+ });
+ }
+ });
}
handle_note_save = function(){
@@ -100,16 +104,37 @@ $(document).ready(function() {
var link = $(this);
var note = ''
var url = Spree.url( Spree.routes.orders_api + "/" + order_number);
+ displayDeleteAlert(function(choice) {
+ if (choice) {
+ $.ajax({
+ type: "PUT",
+ url: url,
+ data: { note: note }
+ }).done(function( msg ) {
+ window.location.reload();
+ }).error(function( msg ) {
+ console.log(msg);
+ });
+ }
+ });
+ return false;
+ }
- $.ajax({
- type: "PUT",
- url: url,
- data: { note: note }
- }).done(function( msg ) {
- window.location.reload();
- }).error(function( msg ) {
- console.log(msg);
+ displayDeleteAlert = function(callback) {
+ i18nKey = "are_you_sure";
+ $('#custom-confirm .message').html(
+ ` ${t(i18nKey)}
+
+
`);
+ $('#custom-confirm button.confirm').unbind( "click" ).click(() => {
+ $('#custom-confirm').hide();
+ callback(true);
});
+ $('#custom-confirm button.cancel').click(() => {
+ $('#custom-confirm').hide();
+ callback(false)
+ });
+ $('#custom-confirm').show();
}
$('[data-hook=admin_order_edit_form] a.save-tracking').click(handle_tracking_save);
diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb
index 50bcfe73ff..12639d1df7 100644
--- a/spec/system/admin/order_spec.rb
+++ b/spec/system/admin/order_spec.rb
@@ -584,6 +584,17 @@ describe '
expect(page).to have_content test_tracking_number
find('.delete-tracking.icon-trash').click
+ # Cancel Deletion
+ # Check if the alert box shows and after clicking cancel
+ # the alert box vanishes and tracking num is still present
+ expect(page).to have_content 'Are you sure?'
+ find('.cancel').click
+ expect(page).to_not have_content 'Are you sure?'
+ expect(page).to have_content test_tracking_number
+
+ find('.delete-tracking.icon-trash').click
+ expect(page).to have_content 'Are you sure?'
+ find('.confirm').click
expect(page).to_not have_content test_tracking_number
end
@@ -598,6 +609,17 @@ describe '
expect(page).to have_content test_note
find('.delete-note.icon-trash').click
+ # Cancel Deletion
+ # Check if the alert box shows and after clicking cancel
+ # the alert box vanishes and note is still present
+ expect(page).to have_content 'Are you sure?'
+ find('.cancel').click
+ expect(page).to_not have_content 'Are you sure?'
+ expect(page).to have_content test_note
+
+ find('.delete-note.icon-trash').click
+ expect(page).to have_content 'Are you sure?'
+ find('.confirm').click
expect(page).to_not have_content test_note
end