diff --git a/kfet/static/kfet/css/history.css b/kfet/static/kfet/css/history.css index 976f5782..fc6a46ad 100644 --- a/kfet/static/kfet/css/history.css +++ b/kfet/static/kfet/css/history.css @@ -40,6 +40,11 @@ width:90px; } +#history .opegroup .infos { + text-align:center; + width:145px; +} + #history .opegroup .valid_by { padding-left:20px } @@ -67,6 +72,10 @@ text-align:right; } +#history .ope .glyphicon { + padding-left:15px; +} + #history .ope .infos2 { padding-left:15px; } diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 7deb407d..599dd9c6 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -34,10 +34,22 @@ function KHistory(options={}) { var trigramme = opegroup['on_acc_trigramme']; var is_cof = opegroup['is_cof']; - for (var i=0; i', template_opegroup: '
', + template_transfergroup: '
', template_ope: '
', + template_transfer: '
', display_trigramme: true, } diff --git a/kfet/static/kfet/js/kfet.js b/kfet/static/kfet/js/kfet.js index 455d2d95..aa58d1ce 100644 --- a/kfet/static/kfet/js/kfet.js +++ b/kfet/static/kfet/js/kfet.js @@ -165,3 +165,9 @@ function requestAuth(data, callback, focus_next = null) { }); } + +String.prototype.pluralize = function(count, irreg_plural = false) { + if (Math.abs(count) >= 2) + return irreg_plural ? irreg_plural : this+'s' ; + return this ; +} diff --git a/kfet/templates/kfet/history.html b/kfet/templates/kfet/history.html index 091b4f2f..78f8ddea 100644 --- a/kfet/templates/kfet/history.html +++ b/kfet/templates/kfet/history.html @@ -7,6 +7,7 @@ + @@ -62,6 +63,8 @@ $(document).ready(function() { settings = { 'subvention_cof': parseFloat({{ settings.subvention_cof|unlocalize }})} + lock = 0 ; + khistory = new KHistory(); var $from_date = $('#from_date'); @@ -142,9 +145,10 @@ $(document).ready(function() { selected: function(e, ui) { $(ui.selected).each(function() { if ($(this).hasClass('opegroup')) { - var opegroup = $(this).data('opegroup'); + var type = $(this).data('type'); + var id = $(this).data('id'); $(this).siblings('.ope').filter(function() { - return $(this).data('opegroup') == opegroup + return $(this).data(type) == id }).addClass('ui-selected'); } }); @@ -156,7 +160,7 @@ $(document).ready(function() { // DEL (Suppr) var opes_to_cancel = []; khistory.$container.find('.ope.ui-selected').each(function () { - opes_to_cancel.push($(this).data('ope')); + opes_to_cancel.push($(this).data('type')+' '+$(this).data('id')); }); if (opes_to_cancel.length > 0) confirmCancel(opes_to_cancel); @@ -165,7 +169,7 @@ $(document).ready(function() { function confirmCancel(opes_to_cancel) { var nb = opes_to_cancel.length; - var content = nb+" opérations vont être annulées"; + var content = nb+' opération va être annulée'.pluralize(nb, ' opérations vont être annulées') $.confirm({ title: 'Confirmation', content: content, @@ -179,50 +183,10 @@ $(document).ready(function() { }); } - 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']) { - var url_base = "{% url 'kfet.account.update' LIQ}"; - url_base = base_url(0, url_base.length-8); - for (var i=0; iAutorisation de négatif requise pour '+data['errors']['negative'][i]+''; - } - } - return content; - } - function cancelOperations(opes_array, password = '') { + if (lock == 1) + return false + lock = 1 ; var data = { 'operations' : opes_array } $.ajax({ dataType: "json", @@ -238,6 +202,7 @@ $(document).ready(function() { }) .done(function(data) { khistory.$container.find('.ui-selected').removeClass('ui-selected'); + lock = 0 ; }) .fail(function($xhr) { var data = $xhr.responseJSON; @@ -251,10 +216,37 @@ $(document).ready(function() { displayErrors(getErrorsHtml(data)); break; } + lock = 0 ; }); } + // ----- + // Synchronization + // ----- + + + websocket_msg_default = {'opegroups':[],'opes':[]} + + var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; + var location_host = window.location.host; + var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host; + socket = new ReconnectingWebSocket(websocket_protocol+"://" + location_url + "/ws/k-fet/k-psul/"); + socket.onmessage = function(e) { + data = $.extend({}, websocket_msg_default, JSON.parse(e.data)); + + for (var i=0; i 0) cancelOperations(opes_to_cancel); diff --git a/kfet/templates/kfet/transfers.html b/kfet/templates/kfet/transfers.html index cbdf0fe3..a580709f 100644 --- a/kfet/templates/kfet/transfers.html +++ b/kfet/templates/kfet/transfers.html @@ -4,9 +4,14 @@ {% block extra_head %} + + + + + {% endblock %} {% block title %}Transferts{% endblock %} @@ -31,22 +36,7 @@

Liste des transferts

-
- {% for transfergroup in transfergroups %} -
- {{ transfergroup.at }} - {{ transfergroup.valid_by.trigramme }} - {{ transfergroup.comment }} -
- {% for transfer in transfergroup.transfers.all %} -
- {{ transfer.amount }} € - {{ transfer.from_acc.trigramme }} - - {{ transfer.to_acc.trigramme }} -
- {% endfor %} - {% endfor %} +
@@ -70,15 +60,80 @@ $(document).ready(function() { }); } + khistory = new KHistory({ + display_trigramme: false, + }); + + function getHistory() { + var data = {'transfersonly': true}; - function cancelTransfers(transfers_array, password = '') { - if (lock == 1) - return false - lock = 1; - var data = { 'transfers' : transfers_array } $.ajax({ dataType: "json", - url : "{% url 'kfet.transfers.cancel' %}", + url : "{% url 'kfet.history.json' %}", + method : "POST", + data : data, + }) + .done(function(data) { + for (var i=0; i 0) + confirmCancel(opes_to_cancel); + } + }); + + function confirmCancel(opes_to_cancel) { + var nb = opes_to_cancel.length; + var content = nb+' opération'.pluralize(nb) + +' va'.pluralize(nb, ' vont') + + ' être' + + ' annulée'.pluralize(nb); + $.confirm({ + title: 'Confirmation', + content: content, + backgroundDismiss: true, + animation: 'top', + closeAnimation: 'bottom', + keyboardEnabled: true, + confirm: function() { + cancelOperations(opes_to_cancel); + } + }); + } + + function cancelOperations(opes_array, password = '') { + if (lock == 1) + return false + lock = 1 ; + var data = { 'operations' : opes_array } + $.ajax({ + dataType: "json", + url : "{% url 'kfet.kpsul.cancel_operations' %}", method : "POST", data : data, beforeSend: function ($xhr) { @@ -89,11 +144,7 @@ $(document).ready(function() { }) .done(function(data) { - for (var i=0; i 0) - cancelTransfers(transfers_to_cancel); + + websocket_msg_default = {'opes':[]} + + var websocket_protocol = window.location.protocol == 'https:' ? 'wss' : 'ws'; + var location_host = window.location.host; + var location_url = window.location.pathname.startsWith('/gestion/') ? location_host + '/gestion' : location_host; + socket = new ReconnectingWebSocket(websocket_protocol+"://" + location_url + "/ws/k-fet/k-psul/"); + socket.onmessage = function(e) { + data = $.extend({}, websocket_msg_default, JSON.parse(e.data)); + + for (var i=0; i