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='') { cancel_operations(to_cancel, password='') {
if (lock == 1)
return false;
lock = 1;
var that = this;
if (window.kpsul) { if (window.kpsul) {
var on_success = kpsul._env.coolReset; var on_success = kpsul._env.coolReset;
var focus_next = kpsul.account_manager._$input_trigramme; var focus_next = kpsul.account_manager._$input_trigramme;
@ -91,35 +84,12 @@ class History {
var focus_next = undefined; var focus_next = undefined;
} }
$.ajax({ api_with_auth({
dataType: "json",
url: Urls['kfet.kpsul.cancel_operations'](), url: Urls['kfet.kpsul.cancel_operations'](),
method : "POST",
data: to_cancel, data: to_cancel,
beforeSend: function ($xhr) { on_success: on_success,
$xhr.setRequestHeader("X-CSRFToken", csrftoken); focus_next: focus_next,
if (password != '')
$xhr.setRequestHeader("KFetPassword", password);
},
}) })
.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) { add_node(data) {