Woohoo for .then

This commit is contained in:
Oliver 2018-05-09 21:32:48 +10:00
parent 517569f510
commit 690ec83265
2 changed files with 21 additions and 37 deletions

View File

@ -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

View File

@ -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) {
method: 'post',
}).then(function(response) {
closeModal(modal);
if (options.success) {
options.success();
}
},
error: function(error) {
}).fail(function(xhr, status, error) {
alert(error);
},
method: 'post'
}
);
});
});
}
@ -162,19 +160,13 @@ function adjustStock(options) {
else {
// Lookup of individual item
if (options.query.pk) {
getStockDetail(options.query.pk,
{
success: function(response) {
getStockDetail(options.query.pk).then(function(response) {
updateStock([response], options);
}
});
}
else {
getStockList(options.query,
{
success: function(response) {
getStockList(options.query).then(function(response) {
updateStock(response, options);
}
});
}
}