From c3b5de336a23fe86b9514092bca92ecaf52f900c Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Mon, 23 Dec 2019 11:30:25 +0100 Subject: [PATCH] =?UTF-8?q?G=C3=A8re=20l'affichage=20des=20transferts=20da?= =?UTF-8?q?ns=20l'historique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/static/kfet/css/history.css | 9 ++++ kfet/static/kfet/js/history.js | 78 ++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/kfet/static/kfet/css/history.css b/kfet/static/kfet/css/history.css index 9cd4cd28..e1e1ab42 100644 --- a/kfet/static/kfet/css/history.css +++ b/kfet/static/kfet/css/history.css @@ -108,3 +108,12 @@ #history .transfer .from_acc { padding-left:10px; } + +#history .opegroup .infos { + text-align:center; + width:145px; +} + +#history .ope .glyphicon { + padding-left:15px; +} diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index a7372b87..cb9399b2 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -19,10 +19,22 @@ function KHistory(options = {}) { var trigramme = opegroup['on_acc_trigramme']; var is_cof = opegroup['is_cof']; - for (var i = 0; i < opegroup['opes'].length; i++) { - var $ope = this._opeHtml(opegroup['opes'][i], is_cof, trigramme); - $ope.data('opegroup', opegroup['id']); - $opegroup.after($ope); + var type = opegroup['type'] + switch (type) { + case 'opegroup': + for (let ope of opegroup['opes']) { + var $ope = this._opeHtml(ope, is_cof, trigramme); + $ope.data('opegroup', opegroup['id']); + $opegroup.after($ope); + } + break; + case 'transfergroup': + for (let transfer of opegroup['opes']) { + var $transfer = this._transferHtml(transfer); + $transfer.data('transfergroup', opegroup['id']); + $opegroup.after($transfer); + } + break; } } @@ -54,7 +66,8 @@ function KHistory(options = {}) { } $ope_html - .data('ope', ope['id']) + .data('type', 'ope') + .data('id', ope['id']) .find('.amount').text(amount).end() .find('.infos1').text(infos1).end() .find('.infos2').text(infos2).end(); @@ -62,7 +75,7 @@ function KHistory(options = {}) { var addcost_for = ope['addcost_for__trigramme']; if (addcost_for) { var addcost_amount = parseFloat(ope['addcost_amount']); - $ope_html.find('.addcost').text('(' + amountDisplay(addcost_amount, is_cof) + 'UKF pour ' + addcost_for + ')'); + $ope_html.find('.addcost').text('(' + amountDisplay(addcost_amount, is_cof) + ' UKF pour ' + addcost_for + ')'); } if (ope['canceled_at']) @@ -71,9 +84,28 @@ function KHistory(options = {}) { return $ope_html; } + this._transferHtml = function (transfer) { + var $transfer_html = $(this.template_transfer); + var parsed_amount = parseFloat(transfer['amount']); + var amount = parsed_amount.toFixed(2) + '€'; + + $transfer_html + .data('type', 'transfer') + .data('id', transfer['id']) + .find('.amount').text(amount).end() + .find('.infos1').text(transfer['from_acc']).end() + .find('.infos2').text(transfer['to_acc']).end(); + + if (transfer['canceled_at']) + this.cancelOpe(transfer, $transfer_html); + + return $transfer_html; + } + + this.cancelOpe = function (ope, $ope = null) { if (!$ope) - $ope = this.findOpe(ope['id']); + $ope = this.findOpe(ope['id'], ope["type"]); var cancel = 'Annulé'; var canceled_at = dateUTCToParis(ope['canceled_at']); @@ -85,16 +117,31 @@ function KHistory(options = {}) { } this._opeGroupHtml = function (opegroup) { - var $opegroup_html = $(this.template_opegroup); + var type = opegroup['type']; + + + switch (type) { + case 'opegroup': + var $opegroup_html = $(this.template_opegroup); + var trigramme = opegroup['on_acc__trigramme']; + var amount = amountDisplay( + parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme); + break; + case 'transfergroup': + var $opegroup_html = $(this.template_transfergroup); + $opegroup_html.find('.infos').text('Transferts').end() + var trigramme = ''; + var amount = ''; + break; + } + var at = dateUTCToParis(opegroup['at']).format('HH:mm:ss'); - var trigramme = opegroup['on_acc__trigramme']; - var amount = amountDisplay( - parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme); var comment = opegroup['comment'] || ''; $opegroup_html - .data('opegroup', opegroup['id']) + .data('type', type) + .data('id', opegroup['id']) .find('.time').text(at).end() .find('.amount').text(amount).end() .find('.comment').text(comment).end() @@ -102,6 +149,7 @@ function KHistory(options = {}) { if (!this.display_trigramme) $opegroup_html.find('.trigramme').remove(); + $opegroup_html.find('.info').remove(); if (opegroup['valid_by__trigramme']) $opegroup_html.find('.valid_by').text('Par ' + opegroup['valid_by__trigramme']); @@ -127,9 +175,9 @@ function KHistory(options = {}) { }); } - this.findOpe = function (id) { + this.findOpe = function (id, type = 'ope') { return this.$container.find('.ope').filter(function () { - return $(this).data('ope') == id + return ($(this).data('id') == id && $(this).data('type') == type) }); } @@ -147,6 +195,8 @@ KHistory.default_options = { container: '#history', template_day: '
', template_opegroup: '
', + template_transfergroup: '
', template_ope: '
', + template_transfer: '
', display_trigramme: true, }