Suppression des opérations et des transferts

This commit is contained in:
Ludovic Stephan 2019-12-23 14:16:23 +01:00
parent c95e1818b2
commit af0de33d4c
3 changed files with 33 additions and 13 deletions

View file

@ -218,17 +218,15 @@ function KHistory(options = {}) {
});
}
this.cancel_opes = function (opes, password = "") {
this.cancel = function (type, opes, password = "") {
if (window.lock == 1)
return false
window.lock = 1;
$.ajax({
dataType: "json",
url: django_urls["kfet.kpsul.cancel_operations"](),
url: django_urls[`kfet.${type}.cancel`](),
method: "POST",
data: {
'operations': opes
},
data: opes,
beforeSend: function ($xhr) {
$xhr.setRequestHeader("X-CSRFToken", csrftoken);
if (password != '')
@ -254,11 +252,33 @@ function KHistory(options = {}) {
}
this.cancel_selected = function () {
var opes_to_cancel = this.$container.find('.ope.ui-selected').map(function () {
return $(this).data('id');
}).toArray();
if (opes_to_cancel.length > 0)
this.cancel(opes_to_cancel);
var opes_to_cancel = {
"transfers": [],
"operations": [],
}
this.$container.find('.ope.ui-selected').each(function () {
if ($(this).data("transfergroup"))
opes_to_cancel["transfers"].push($(this).data("id"));
else
opes_to_cancel["operations"].push($(this).data("id"));
});
if (opes_to_cancel["transfers"].length > 0 && opes_to_cancel["operations"].length > 0) {
// Lancer 2 requêtes AJAX et gérer tous les cas d'erreurs possibles est trop complexe
$.alert({
title: 'Erreur',
content: "Impossible de supprimer des transferts et des opérations en même temps !",
backgroundDismiss: true,
animation: 'top',
closeAnimation: 'bottom',
keyboardEnabled: true,
});
} else if (opes_to_cancel["transfers"].length > 0) {
delete opes_to_cancel["operations"];
this.cancel("transfers", opes_to_cancel);
} else if (opes_to_cancel["operations"].length > 0) {
delete opes_to_cancel["transfers"];
this.cancel("operations", opes_to_cancel);
}
}
}

View file

@ -219,8 +219,8 @@ urlpatterns = [
),
path(
"k-psul/cancel_operations",
views.kpsul_cancel_operations,
name="kfet.kpsul.cancel_operations",
views.cancel_operations,
name="kfet.operations.cancel",
),
path(
"k-psul/articles_data",

View file

@ -1208,7 +1208,7 @@ def kpsul_perform_operations(request):
@teamkfet_required
@kfet_password_auth
def kpsul_cancel_operations(request):
def cancel_operations(request):
# Pour la réponse
data = {"canceled": [], "warnings": {}, "errors": {}}