diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 0f07f73b..291cc675 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -5,53 +5,12 @@ class KHistory { static get default_options() { return { 'templates': { - 'purchase': ` -
- - - - - -
- `, - 'specialope': ` -
- - - - - -
- `, - 'opegroup': ` -
- - - - - -
`, - 'transfergroup': ` -
- - - - -
- `, - 'day': ` -
- -
- `, - 'transfer': ` -
- - - - - -
`, + 'purchase': '
', + 'specialope': '
', + 'opegroup': '
', + 'transfergroup': '
', + 'day': '
', + 'transfer': '
', }, 'api_options': { @@ -78,14 +37,7 @@ class KHistory { var templates = all_options.templates; if (all_options.no_trigramme) - templates['opegroup'] = ` -
- - - - -
- `; + templates['opegroup'] = '
'; this.display = new ForestDisplay(this._$container, templates, this.data); @@ -155,26 +107,47 @@ class KHistory { is_valid(opegroup) { var options = this.api_options; - if (options.from && dateUTCToParis(opegroup.at).isBefore(moment(options.from))) + if (options.from && dateUTCToParis(opegroup.content.at).isBefore(moment(options.from))) return false; - if (options.to && dateUTCToParis(opegroup.at).isAfter(moment(options.to))) + if (options.to && dateUTCToParis(opegroup.content.at).isAfter(moment(options.to))) return false; - if (options.transfersonly && opegroup.constructor.verbose_name == 'opegroup') - return false; + var accounts_filter = options.accounts && options.accounts.length; + var checkouts_filter = options.checkouts && options.checkouts.length; - if (options.opesonly && opegroup.constructor.verbose_name == 'transfergroup') - return false; + if (opegroup.modelname == 'opegroup') { - if (options.accounts && options.accounts.length && - options.accounts.indexOf(opegroup.account_id) < 0) - return false; + if (options.transfersonly) + return false; - if (options.checkouts && options.checkouts.length && - (opegroup.modelname == 'transfergroup' || - options.checkouts.indexOf(opegroup.checkout_id) < 0)) - return false; + if (accounts_filter && options.accounts.indexOf(opegroup.content.account_id) < 0) + return false; + + if (checkouts_filter && options.checkouts.indexOf(opegroup.content.checkout_id) < 0) + return false; + + } else if (opegroup.modelname == 'transfergroup') { + + if (options.opesonly) + return false; + + if (checkouts_filter) + return false; + + if (accounts_filter) { + opegroup.content.children = + opegroup.content.children.filter( function(transfer) { + var is_from_in = + options.accounts.indexOf(transfer.content.from_acc_id) >= 0; + var is_to_in = + options.accounts.indexOf(transfer.content.to_acc_id) >= 0; + return is_from_in || is_to_in; + }); + if (opegroup.content.children.length == 0) + return false; + } + } return true; } diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 9e14f709..4f37a47c 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -64,21 +64,9 @@ class AccountManager { // buttons: search, read or create this._$buttons_container = this._$container.find('.buttons'); this._buttons_templates = { - create: template` - - - - `, - read: template` - - - - `, - search: template` - - `, + create: template``, + read: template``, + search: template``, }; } @@ -208,10 +196,7 @@ class AccountSearch { constructor(manager) { this.manager = manager; - this._content = ` - -
- `; + this._content = '
'; this._input = '#search_autocomplete'; this._results_container = '#account_results'; @@ -305,16 +290,8 @@ class CheckoutManager { this._$buttons_container = this._$container.find('.buttons'); this._buttons_templates = { - read: template` - - - - `, - statement_create: template` - - - - `, + read: template``, + statement_create: template``, }; } @@ -457,18 +434,8 @@ class ArticleManager { this.data = new ArticleList(); var $container = $('#articles_data'); var templates = { - category: ` -
- -
- `, - article: ` -
- - - -
- `, + category: '
', + article: '
', }; this.display = new ForestDisplay($container, templates, this.data); this.autocomplete = new ArticleAutocomplete(this, $container); diff --git a/kfet/templates/kfet/history.html b/kfet/templates/kfet/history.html index 2075cf30..03a468ef 100644 --- a/kfet/templates/kfet/history.html +++ b/kfet/templates/kfet/history.html @@ -94,7 +94,8 @@ $(document).ready(function() { if ($checkouts) data['checkouts'] = checkouts; var accounts = getSelectedMultiple($accounts); - data['accounts'] = accounts; + if (accounts) + data['accounts'] = accounts.map(id => parseInt(id)); // Update history khistory.fetch(data); diff --git a/kfet/views.py b/kfet/views.py index 6751d95b..d2ed376c 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1799,22 +1799,29 @@ def perform_transfers(request): websocket_data['opegroups'] = [{ 'add': True, 'modelname': 'transfergroup', - 'id': transfergroup.pk, - 'at': transfergroup.at, - 'comment': transfergroup.comment, - 'valid_by__trigramme': (transfergroup.valid_by and - transfergroup.valid_by.trigramme or None), - 'opes': [], + 'content': { + 'id': transfergroup.pk, + 'at': transfergroup.at, + 'comment': transfergroup.comment, + 'valid_by__trigramme': (transfergroup.valid_by and + transfergroup.valid_by.trigramme or None), + 'children': [] + }, }] for transfer in transfers: ope_data = { - 'id': transfer.pk, - 'amount': transfer.amount, - 'from_acc': transfer.from_acc.trigramme, - 'to_acc': transfer.to_acc.trigramme, - 'canceled_by__trigramme': None, 'canceled_at': None, + 'modelname': 'transfer', + 'content': { + 'id': transfer.pk, + 'amount': transfer.amount, + 'from_acc': transfer.from_acc.trigramme, + 'to_acc': transfer.to_acc.trigramme, + 'canceled_by__trigramme': None, 'canceled_at': None, + 'from_acc_id': transfer.from_acc.id, + 'to_acc_id': transfer.to_acc.id, + }, } - websocket_data['opegroups'][0]['opes'].append(ope_data) + websocket_data['opegroups'][0]['content']['children'].append(ope_data) consumers.KPsul.group_send('kfet.kpsul', websocket_data) return JsonResponse(data)