diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index b398a65c..22aff4d6 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -35,14 +35,14 @@ function KHistory(options = {}) { var is_cof = opegroup['is_cof']; var type = opegroup['type'] switch (type) { - case 'opegroup': + case 'operation': 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': + case 'transfer': for (let transfer of opegroup['opes']) { var $transfer = this._transferHtml(transfer); $transfer.data('transfergroup', opegroup['id']); @@ -80,7 +80,7 @@ function KHistory(options = {}) { } $ope_html - .data('type', 'ope') + .data('type', 'operation') .data('id', ope['id']) .find('.amount').text(amount).end() .find('.infos1').text(infos1).end() @@ -119,7 +119,7 @@ function KHistory(options = {}) { this.cancelOpe = function (ope, $ope = null) { if (!$ope) - $ope = this.findOpe(ope['id'], ope["type"]); + $ope = this.findOpe(ope["id"], ope["type"]); var cancel = 'Annulé'; var canceled_at = dateUTCToParis(ope['canceled_at']); @@ -135,13 +135,13 @@ function KHistory(options = {}) { switch (type) { - case 'opegroup': + case 'operation': 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': + case 'transfer': var $opegroup_html = $(this.template_transfergroup); $opegroup_html.find('.infos').text('Transferts').end() var trigramme = ''; @@ -183,20 +183,20 @@ function KHistory(options = {}) { return $day.data('date', at_ser).text(at.format('D MMMM YYYY')); } - this.findOpeGroup = function (id) { + this.findOpeGroup = function (id, type = "operation") { return this.$container.find('.opegroup').filter(function () { - return $(this).data('opegroup') == id + return ($(this).data('id') == id && $(this).data("type") == type) }); } - this.findOpe = function (id, type = 'ope') { + this.findOpe = function (id, type = 'operation') { return this.$container.find('.ope').filter(function () { return ($(this).data('id') == id && $(this).data('type') == type) }); } - this.cancelOpeGroup = function (opegroup) { - var $opegroup = this.findOpeGroup(opegroup['id']); + this.update_opegroup = function (opegroup, type = "operation") { + var $opegroup = this.findOpeGroup(opegroup['id'], type); var trigramme = $opegroup.find('.trigramme').text(); var amount = amountDisplay( parseFloat(opegroup['amount']), opegroup['is_cof'], trigramme); @@ -218,13 +218,14 @@ function KHistory(options = {}) { }); } - this.cancel = function (type, opes, password = "") { + this._cancel = function (type, opes, password = "") { if (window.lock == 1) return false window.lock = 1; + var that = this; $.ajax({ dataType: "json", - url: django_urls[`kfet.${type}.cancel`](), + url: django_urls[`kfet.${type}s.cancel`](), method: "POST", data: opes, beforeSend: function ($xhr) { @@ -235,6 +236,16 @@ function KHistory(options = {}) { }).done(function (data) { window.lock = 0; + that.$container.find('.ui-selected').removeClass('ui-selected'); + for (let ope of data["canceled"]) { + ope["type"] = type; + that.cancelOpe(ope); + } + if (type == "operation") { + for (let opegroup of data["opegroups_to_update"]) { + that.update_opegroup(opegroup) + } + } }).fail(function ($xhr) { var data = $xhr.responseJSON; switch ($xhr.status) { @@ -274,10 +285,10 @@ function KHistory(options = {}) { }); } else if (opes_to_cancel["transfers"].length > 0) { delete opes_to_cancel["operations"]; - this.cancel("transfers", opes_to_cancel); + this._cancel("transfer", opes_to_cancel); } else if (opes_to_cancel["operations"].length > 0) { delete opes_to_cancel["transfers"]; - this.cancel("operations", opes_to_cancel); + this._cancel("operation", opes_to_cancel); } } } diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index c745d598..0b7f946e 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -1256,13 +1256,6 @@ $(document).ready(function() { for (var i=0; i