diff --git a/backend/app/assets/javascripts/spree/backend/models/image_upload.js b/backend/app/assets/javascripts/spree/backend/models/image_upload.js index 11524fa3794..01e6721cb32 100644 --- a/backend/app/assets/javascripts/spree/backend/models/image_upload.js +++ b/backend/app/assets/javascripts/spree/backend/models/image_upload.js @@ -56,7 +56,7 @@ Spree.Models.ImageUpload = Backbone.Model.extend({ processData: false, // tell jQuery not to process the data contentType: false, // tell jQuery not to set contentType xhr: function () { - var xhr = $.ajaxSettings.xhr(); + var xhr = $.ajaxSetup.xhr(); // Using default ajax builder but inputting upload settings if (xhr.upload) { xhr.upload.onprogress = function (event) { if (event.lengthComputable) { @@ -67,9 +67,9 @@ Spree.Models.ImageUpload = Backbone.Model.extend({ } return xhr; } - }).done(function() { + }).then(function() { that.set({progress: 100}) - }).error(function(jqXHR, textStatus, errorThrown) { + }).fail(function() { that.set({serverError: true}); }); } diff --git a/backend/app/assets/javascripts/spree/backend/shipments.js b/backend/app/assets/javascripts/spree/backend/shipments.js index 202a647b8b8..2ab3d5a7b12 100644 --- a/backend/app/assets/javascripts/spree/backend/shipments.js +++ b/backend/app/assets/javascripts/spree/backend/shipments.js @@ -100,30 +100,26 @@ var ShipmentSplitItemView = Backbone.View.extend({ variant_id: this.variant.id, quantity: quantity }; - var jqXHR; + var path; if (target_type == 'stock_location') { // transfer to a new location split_attr.stock_location_id = target_id; - jqXHR = Spree.ajax({ - type: "POST", - url: Spree.pathFor('api/shipments/transfer_to_location'), - data: split_attr - }); + path = Spree.pathFor("api/shipments/transfer_to_location"); } else if (target_type == 'shipment') { // transfer to an existing shipment split_attr.target_shipment_number = target_id; - jqXHR = Spree.ajax({ - type: "POST", - url: Spree.pathFor('api/shipments/transfer_to_shipment'), - data: split_attr - }); + path = Spree.pathFor('api/shipments/transfer_to_shipment'); } else { alert('Please select the split destination.'); return false; } - jqXHR.error(function(msg) { + Spree.ajax({ + type: "POST", + url: path, + data: split_attr + }).fail(function(msg) { alert(Spree.t("split_failed")); - }).done(function(response) { + }).then(function(response) { if (response.success) { window.Spree.advanceOrder(); } else { diff --git a/backend/spec/features/admin/orders/shipments_spec.rb b/backend/spec/features/admin/orders/shipments_spec.rb index 2043dbbab64..3ef15183e6f 100644 --- a/backend/spec/features/admin/orders/shipments_spec.rb +++ b/backend/spec/features/admin/orders/shipments_spec.rb @@ -155,9 +155,13 @@ def ship_shipment alert_text = page.driver.browser.switch_to.alert.text expect(alert_text).to include 'Please select the split destination' page.driver.browser.switch_to.alert.accept + find('#item_quantity').fill_in(with: 'text') find('.select2-container').click find(:xpath, '//body').all('.select2-drop li.select2-result', text: "#{location_name} (0 on hand)")[1].click find('.save-split').click + accept_alert 'Quantity must be greater than 0' # Test Ajax error handling + find('#item_quantity').fill_in(with: '1') + find('.save-split').click end expect(page).to have_content /Pending package from '#{location_name}'/i end