app/assets/javascripts/spree/backend/shipments.js.erb in spree_backend-2.3.13 vs app/assets/javascripts/spree/backend/shipments.js.erb in spree_backend-2.4.0.rc1
- old
+ new
@@ -64,14 +64,11 @@
var link = $(this);
var shipment_number = link.data('shipment-number');
var url = Spree.url(Spree.routes.shipments_api + '/' + shipment_number + '/ship.json');
$.ajax({
type: 'PUT',
- url: url,
- data: {
- token: Spree.api_key
- }
+ url: url
}).done(function () {
window.location.reload();
}).error(function (msg) {
console.log(msg);
});
@@ -96,12 +93,11 @@
url: url,
data: {
shipment: {
selected_shipping_rate_id: selected_shipping_rate_id,
unlock: unlock
- },
- token: Spree.api_key
+ }
}
}).done(function () {
window.location.reload();
}).error(function (msg) {
console.log(msg);
@@ -133,12 +129,11 @@
type: 'PUT',
url: url,
data: {
shipment: {
tracking: tracking
- },
- token: Spree.api_key
+ }
}
}).done(function (data) {
link.parents('tbody').find('tr.edit-tracking').toggle();
var show = link.parents('tbody').find('tr.show-tracking');
@@ -166,15 +161,11 @@
if(new_quantity!=0){
$.ajax({
type: "PUT",
url: Spree.url(url),
- data: {
- variant_id: variant_id,
- quantity: new_quantity,
- token: Spree.api_key
- }
+ data: { variant_id: variant_id, quantity: new_quantity }
}).done(function( msg ) {
window.location.reload();
});
}
}
@@ -214,12 +205,11 @@
async: false,
url: Spree.url(Spree.routes.variants_api),
data: {
q: {
"id_eq": variant_id
- },
- token: Spree.api_key
+ }
}
}).success(function( data ) {
variant = data['variants'][0];
}).error(function( msg ) {
console.log(msg);
@@ -241,12 +231,17 @@
$('#item_stock_location').select2({ width: 'resolve', placeholder: Spree.translations.item_stock_placeholder });
}
completeItemSplit = function(event) {
event.preventDefault();
+
+ if($('#item_stock_location').val() === ""){
+ alert('Please select the split destination.');
+ return false;
+ }
+
var link = $(this);
- var order_number = link.closest('tbody').data('order-number');
var stock_item_row = link.closest('tr');
var variant_id = stock_item_row.data('variant-id');
var quantity = stock_item_row.find('#item_quantity').val();
var stock_location_id = stock_item_row.find('#item_stock_location').val();
@@ -255,51 +250,48 @@
var selected_shipment = stock_item_row.find($('#item_stock_location').select2('data').element);
var target_shipment_number = selected_shipment.data('shipment-number');
var new_shipment = selected_shipment.data('new-shipment');
if (stock_location_id != 'new_shipment') {
- // first remove item(s) from original shipment
- $.ajax({
- type: "PUT",
- async: false,
- url: Spree.url(Spree.routes.shipments_api + "/" + original_shipment_number + "/remove.json"),
- data: { variant_id: variant_id, quantity: quantity }
- });
-
if (new_shipment != undefined) {
+ // TRANSFER TO A NEW LOCATION
$.ajax({
type: "POST",
async: false,
- url: Spree.url(Spree.routes.shipments_api + "?shipment[order_id]=" + order_number),
- data: { variant_id: variant_id, quantity: quantity, stock_location_id: stock_location_id, token: Spree.api_key }
+ url: Spree.url(Spree.routes.shipments_api + "/transfer_to_location"),
+ data: {
+ original_shipment_number: original_shipment_number,
+ variant_id: variant_id,
+ quantity: quantity,
+ stock_location_id: stock_location_id
+ }
+ }).error(function(msg) {
+ alert(msg.responseJSON['message']);
}).done(function(msg) {
- advanceOrder();
+ window.Spree.advanceOrder();
});
} else {
- $.ajax({
- type: "PUT",
- async: false,
- url: Spree.url(Spree.routes.shipments_api + "/" + target_shipment_number + "/add.json"),
- data: { variant_id: variant_id, quantity: quantity, token: Spree.api_key }
- }).done(function(msg) {
- advanceOrder();
- });
+ // TRANSFER TO AN EXISTING SHIPMENT
+ $.ajax({
+ type: "POST",
+ async: false,
+ url: Spree.url(Spree.routes.shipments_api + "/transfer_to_shipment"),
+ data: {
+ original_shipment_number: original_shipment_number,
+ target_shipment_number: target_shipment_number,
+ variant_id: variant_id,
+ quantity: quantity
+ }
+ }).error(function(msg) {
+ alert(msg.responseJSON['message']);
+ }).done(function(msg) {
+ window.Spree.advanceOrder();
+ });
}
}
}
-advanceOrder = function() {
- $.ajax({
- type: "PUT",
- async: false,
- url: Spree.url(Spree.routes.checkouts_api + "/" + order_number + "/advance"),
- data: { token: Spree.api_key }
- }).done(function() {
- window.location.reload();
- });
-}
-
cancelItemSplit = function(event) {
event.preventDefault();
var link = $(this);
var prev_row = link.closest('tr').prev();
link.closest('tr').remove();
@@ -323,15 +315,10 @@
if(shipment==undefined){
$.ajax({
type: "POST",
url: Spree.url(Spree.routes.shipments_api + "?shipment[order_id]=" + order_number),
- data: {
- variant_id: variant_id,
- quantity: quantity,
- stock_location_id: stock_location_id,
- token: Spree.api_key
- }
+ data: { variant_id: variant_id, quantity: quantity, stock_location_id: stock_location_id }
}).done(function( msg ) {
window.location.reload();
}).error(function( msg ) {
console.log(msg);
});