Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecated jQuery methods (Backport #4625 to v3.2) #4674

Merged
merged 3 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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