From a173be4f7d8996fa7f281042f435daf7b4bfedaf Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 3 Apr 2017 21:14:06 -0300 Subject: [PATCH] Use api_with_auth in history --- kfet/static/kfet/js/history.js | 40 +++++----------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index e23d4c6a..c95b3575 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -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", - 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); - }, + api_with_auth({ + url: Urls['kfet.kpsul.cancel_operations'](), + data: to_cancel, + 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) {