Skip to content

Commit

Permalink
Merge pull request #4674 from nebulab/elia/backport-4625
Browse files Browse the repository at this point in the history
Update deprecated jQuery methods (Backport #4625 to v3.2)
  • Loading branch information
kennyadsl authored Oct 14, 2022
2 parents a88815b + 57823b2 commit 2d695fb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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});
});
}
Expand Down
22 changes: 9 additions & 13 deletions backend/app/assets/javascripts/spree/backend/shipments.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions backend/spec/features/admin/orders/shipments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d695fb

Please sign in to comment.