diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 2869ea86..b398a65c 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -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); + } } } diff --git a/kfet/urls.py b/kfet/urls.py index 03c174f3..88220845 100644 --- a/kfet/urls.py +++ b/kfet/urls.py @@ -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", diff --git a/kfet/views.py b/kfet/views.py index d7a7be55..c06bd074 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -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": {}}