Gère l'affichage des transferts dans l'historique

This commit is contained in:
Ludovic Stephan 2019-12-23 11:30:25 +01:00
parent bf117ec070
commit c3b5de336a
2 changed files with 73 additions and 14 deletions

View file

@ -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;
}

View file

@ -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: '<div class="day"></div>',
template_opegroup: '<div class="opegroup"><span class="time"></span><span class="trigramme"></span><span class="amount"></span><span class="valid_by"></span><span class="comment"></span></div>',
template_transfergroup: '<div class="opegroup"><span class="time"></span><span class="infos"></span><span class="valid_by"></span><span class="comment"></span></div>',
template_ope: '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
template_transfer: '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="glyphicon glyphicon-arrow-right"></span><span class="infos2"></span><span class="canceled"></span></div>',
display_trigramme: true,
}