Use api_with_auth in history

This commit is contained in:
Ludovic Stephan 2017-04-03 21:14:06 -03:00
parent 07290f6fec
commit a173be4f7d

View file

@ -74,14 +74,7 @@ class History {
});
}
//TODO: permission management in another class ?
//TODO: idem for confirmation
cancel_operations(to_cancel, password='') {
if (lock == 1)
return false;
lock = 1;
var that = this;
if (window.kpsul) {
var on_success = kpsul._env.coolReset;
var focus_next = kpsul.account_manager._$input_trigramme;
@ -91,35 +84,12 @@ class History {
var focus_next = undefined;
}
$.ajax({
dataType: "json",
api_with_auth({
url: Urls['kfet.kpsul.cancel_operations'](),
method : "POST",
data: to_cancel,
beforeSend: function ($xhr) {
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
if (password != '')
$xhr.setRequestHeader("KFetPassword", password);
},
on_success: on_success,
focus_next: focus_next,
})
.done(function(data) {
on_success();
lock = 0;
})
.fail(function($xhr) {
var data = $xhr.responseJSON;
switch ($xhr.status) {
case 403:
requestAuth(data, function(password) {
cancelOperations(to_cancel, password);
}, focus_next);
break;
case 400:
displayErrors(getErrorsHtml(data));
break;
}
lock = 0;
});
}
add_node(data) {