From 9b548c9e456ec241edda0a92010806c913347e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Thu, 25 Aug 2016 02:32:11 +0200 Subject: [PATCH] Annulations sur la page `Historique` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Possibilité une (ou plusieurs) opération(s). L'affichage de l'annulation n'est pas encore en direct --- kfet/templates/kfet/history.html | 116 +++++++++++++++++++++++++++++++ kfet/templates/kfet/kpsul.html | 3 +- 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/kfet/templates/kfet/history.html b/kfet/templates/kfet/history.html index d8db7032..c7405435 100644 --- a/kfet/templates/kfet/history.html +++ b/kfet/templates/kfet/history.html @@ -3,9 +3,11 @@ {% load l10n %} {% block extra_head %} + + @@ -133,6 +135,120 @@ $(document).ready(function() { getHistory(); }); + khistory.$container.selectable({ + filter: 'div.opegroup, div.ope', + selected: function(e, ui) { + $(ui.selected).each(function() { + if ($(this).hasClass('opegroup')) { + var opegroup = $(this).data('opegroup'); + $(this).siblings('.ope').filter(function() { + return $(this).data('opegroup') == opegroup + }).addClass('ui-selected'); + } + }); + }, + }); + + $(document).on('keydown', function (e) { + if (e.keyCode == 46) { + // DEL (Suppr) + var opes_to_cancel = []; + khistory.$container.find('.ope.ui-selected').each(function () { + opes_to_cancel.push($(this).data('ope')); + }); + if (opes_to_cancel.length > 0) + confirmCancel(opes_to_cancel); + } + }); + + function confirmCancel(opes_to_cancel) { + var nb = opes_to_cancel.length; + var content = nb+" opérations vont être annulées"; + $.confirm({ + title: 'Confirmation', + content: content, + backgroundDismiss: true, + animation: 'top', + closeAnimation: 'bottom', + keyboardEnabled: true, + confirm: function() { + cancelOperations(opes_to_cancel); + } + }); + } + + function requestAuth(data, callback) { + var content = getErrorsHtml(data); + content += '', + $.confirm({ + title: 'Authentification requise', + content: content, + backgroundDismiss: true, + animation:'top', + closeAnimation:'bottom', + keyboardEnabled: true, + confirm: function() { + var password = this.$content.find('input').val(); + callback(password); + }, + onOpen: function() { + var that = this; + this.$content.find('input').on('keypress', function(e) { + if (e.keyCode == 13) + that.$confirmButton.click(); + }); + }, + }); + } + + function getErrorsHtml(data) { + var content = ''; + if ('missing_perms' in data['errors']) { + content += 'Permissions manquantes'; + content += ''; + } + if ('negative' in data['errors']) + content += 'Autorisation de négatif requise'; + return content; + } + + function cancelOperations(opes_array, password = '') { + var data = { 'operations' : opes_array } + $.ajax({ + dataType: "json", + url : "{% url 'kfet.kpsul.cancel_operations' %}", + method : "POST", + data : data, + beforeSend: function ($xhr) { + $xhr.setRequestHeader("X-CSRFToken", csrftoken); + if (password != '') + $xhr.setRequestHeader("KFetPassword", password); + }, + + }) + .done(function(data) { + khistory.$container.find('.ui-selected').removeClass('ui-selected'); + }) + .fail(function($xhr) { + var data = $xhr.responseJSON; + switch ($xhr.status) { + case 403: + requestAuth(data, function(password) { + cancelOperations(opes_array, password); + }); + break; + case 400: + displayErrors(getErrorsHtml(data)); + break; + } + + }); + } + + getHistory(); }); diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index c5153f78..2b64c8d5 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -1065,11 +1065,12 @@ $(document).ready(function() { filter: 'div.opegroup, div.ope', selected: function(e, ui) { $(ui.selected).each(function() { - if ($(this).hasClass('opegroup')) + if ($(this).hasClass('opegroup')) { var opegroup = $(this).data('opegroup'); $(this).siblings('.ope').filter(function() { return $(this).data('opegroup') == opegroup }).addClass('ui-selected'); + } }); }, });