mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Woohoo for .then
This commit is contained in:
parent
517569f510
commit
690ec83265
@ -18,7 +18,7 @@ function getCookie(name) {
|
||||
}
|
||||
|
||||
function inventreeGet(url, filters={}, options={}) {
|
||||
$.ajax({
|
||||
return $.ajax({
|
||||
url: url,
|
||||
type: 'GET',
|
||||
data: filters,
|
||||
@ -39,7 +39,7 @@ function inventreeGet(url, filters={}, options={}) {
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function inventreeUpdate(url, data={}, options={}) {
|
||||
@ -57,7 +57,7 @@ function inventreeUpdate(url, data={}, options={}) {
|
||||
//var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();
|
||||
var csrftoken = getCookie('csrftoken');
|
||||
|
||||
$.ajax({
|
||||
return $.ajax({
|
||||
beforeSend: function(xhr, settings) {
|
||||
xhr.setRequestHeader('X-CSRFToken', csrftoken);
|
||||
},
|
||||
@ -69,20 +69,12 @@ function inventreeUpdate(url, data={}, options={}) {
|
||||
success: function(response, status) {
|
||||
response['_status_code'] = status;
|
||||
console.log('UPDATE object to ' + url + ' - result = ' + status);
|
||||
if (options.success) {
|
||||
options.success(response);
|
||||
}
|
||||
},
|
||||
error: function(xhr, ajaxOptions, thrownError) {
|
||||
console.error('Error on UPDATE to ' + url);
|
||||
console.error(thrownError);
|
||||
if (options.error) {
|
||||
options.error({
|
||||
error: thrownError
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
// Return list of parts with optional filters
|
||||
|
@ -50,11 +50,12 @@ function updateStock(items, options={}) {
|
||||
var item = items[idx];
|
||||
|
||||
var vMin = 0;
|
||||
var vMax = item.quantity;
|
||||
var vMax = 0;
|
||||
var vCur = item.quantity;
|
||||
|
||||
if (options.action == 'remove') {
|
||||
vCur = 0;
|
||||
vMax = item.quantity;
|
||||
}
|
||||
else if (options.action == 'add') {
|
||||
vCur = 0;
|
||||
@ -140,18 +141,15 @@ function updateStock(items, options={}) {
|
||||
'notes': $(modal).find('#stocktake-notes').val()
|
||||
},
|
||||
{
|
||||
success: function(response) {
|
||||
closeModal(modal);
|
||||
if (options.success) {
|
||||
options.success();
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
alert(error);
|
||||
},
|
||||
method: 'post'
|
||||
}
|
||||
);
|
||||
method: 'post',
|
||||
}).then(function(response) {
|
||||
closeModal(modal);
|
||||
if (options.success) {
|
||||
options.success();
|
||||
}
|
||||
}).fail(function(xhr, status, error) {
|
||||
alert(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -162,20 +160,14 @@ function adjustStock(options) {
|
||||
else {
|
||||
// Lookup of individual item
|
||||
if (options.query.pk) {
|
||||
getStockDetail(options.query.pk,
|
||||
{
|
||||
success: function(response) {
|
||||
updateStock([response], options);
|
||||
}
|
||||
});
|
||||
getStockDetail(options.query.pk).then(function(response) {
|
||||
updateStock([response], options);
|
||||
});
|
||||
}
|
||||
else {
|
||||
getStockList(options.query,
|
||||
{
|
||||
success: function(response) {
|
||||
updateStock(response, options);
|
||||
}
|
||||
});
|
||||
getStockList(options.query).then(function(response) {
|
||||
updateStock(response, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user