Simplify JS-Python interface for cancel_ops

This commit is contained in:
Ludovic Stephan 2017-03-24 23:57:27 -03:00
parent 1fcd53d780
commit aa6a50a6e7
2 changed files with 13 additions and 14 deletions

View file

@ -59,11 +59,16 @@ class History {
$(document).on('keydown', function(e) { $(document).on('keydown', function(e) {
if (e.keyCode == 46) { if (e.keyCode == 46) {
//DEL key ; we delete the selected operations (if any) //DEL key ; we delete the selected operations (if any)
var to_cancel = []; var to_cancel = {'transfers': [], 'opes': [],};
that._$container.find('.ope.ui-selected').each(function() { that._$container.find('.ope.ui-selected').each(function() {
to_cancel.push($(this).parent().attr('id')) ; var [type, id] = $(this).parent().attr('id').split('-');
if (type === 'transfer')
to_cancel['transfers'].push(id);
else
to_cancel['opes'].push(id);
}); });
if (to_cancel.length > 0) if (to_cancel['opes'].length > 0 || to_cancel['transfers'].length > 0)
that.cancel_operations(to_cancel); that.cancel_operations(to_cancel);
} }
}); });
@ -86,13 +91,11 @@ class History {
var focus_next = undefined; var focus_next = undefined;
} }
var data = { 'operations': to_cancel };
$.ajax({ $.ajax({
dataType: "json", dataType: "json",
url : Urls['kfet.kpsul.cancel_operations'](), url : Urls['kfet.kpsul.cancel_operations'](),
method : "POST", method : "POST",
data : data, data : to_cancel,
beforeSend: function ($xhr) { beforeSend: function ($xhr) {
$xhr.setRequestHeader("X-CSRFToken", csrftoken); $xhr.setRequestHeader("X-CSRFToken", csrftoken);
if (password != '') if (password != '')

View file

@ -1134,14 +1134,10 @@ def kpsul_cancel_operations(request):
# Checking if BAD REQUEST (opes_pk not int or not existing) # Checking if BAD REQUEST (opes_pk not int or not existing)
try: try:
# Set pour virer les doublons # Set pour virer les doublons
opes_post = set(map(lambda s: int(s.split('-')[1]), opes_post = set(map(lambda s: int(s),
filter(lambda s: s.split('-')[0] == 'purchase' request.POST.getlist('opes[]', [])))
or s.split('-')[0] == 'specialope', transfers_post = set(map(lambda s: int(s),
request.POST.getlist('operations[]', [])))) request.POST.getlist('transfers[]', [])))
transfers_post = \
set(map(lambda s: int(s.split('-')[1]),
filter(lambda s: s.split('-')[0] == 'transfer',
request.POST.getlist('operations[]', []))))
except ValueError: except ValueError:
return JsonResponse(data, status=400) return JsonResponse(data, status=400)