diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 9f6a31ee..01ca1699 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -1,6 +1,10 @@ class KHistory { + + static get default_options() { + return { from: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'), }; + } - constructor(api_options, display_options) { + constructor(display_options) { this.templates = { 'purchase': '
', 'specialope': '
', @@ -14,26 +18,33 @@ class KHistory { this._$nb_opes = $('#nb_opes'); this.list = new OperationList(); - this.api_options = - api_options || { from: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'), }; + this.display_options = display_options || {}; this._init_selection(); this._init_events(); } + fetch(api_options) { + this._$container.html(''); + this.list.clear(); + + if (api_options) + this.api_options = api_options; + else if (!this.api_options) + this.api_options = this.constructor.default_options; + + this.list.fromAPI(this.api_options) + .done( () => this.display() ); + + } + display() { this.list.display(this._$container, this.templates, this.display_options); var nb_opes = this._$container.find('.ope[canceled="false"]').length; $('#nb_opes').text(nb_opes); } - reset() { - this._$container.html(''); - this.list.clear(); - this.list.fromAPI(this.api_options, this.display.bind(this), $.noop); - } - _init_selection() { this._$container.selectable({ filter: 'div.opegroup, div.ope', diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 81ee2341..65f6fad8 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -24,6 +24,7 @@ class KPsulManager { if (!soft) { this.checkout_manager.reset(); this.article_manager.reset_data(); + this.history.fetch(); } } diff --git a/kfet/templates/kfet/account_read.html b/kfet/templates/kfet/account_read.html index 791c7512..b11a2cb0 100644 --- a/kfet/templates/kfet/account_read.html +++ b/kfet/templates/kfet/account_read.html @@ -105,10 +105,7 @@ $(document).ready(function() { // Lock to avoid multiple requests window.lock = 0; - var history = new KHistory(); - history.api_options = { - 'accounts': [{{ account.pk }}], - }; + var history = new KHistory({'remove_props': ['trigramme']}); // ----- // Synchronization @@ -116,7 +113,7 @@ $(document).ready(function() { OperationWebSocket.add_handler((data) => history.update_data(data)); - Config.reset(history.reset.bind(history)); + Config.reset(() => history.fetch({'accounts': [{{account.pk}}]})); }); diff --git a/kfet/templates/kfet/history.html b/kfet/templates/kfet/history.html index 04cfd062..1d0d8e06 100644 --- a/kfet/templates/kfet/history.html +++ b/kfet/templates/kfet/history.html @@ -93,10 +93,9 @@ $(document).ready(function() { data['checkouts'] = checkouts; var accounts = getSelectedMultiple($accounts); data['accounts'] = accounts; - history.api_options = data ; // Update history - history.reset(); + history.fetch(data); } $('#from_date').datetimepicker({ diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 2b98838e..2ba18251 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -668,7 +668,7 @@ $(document).ready(function() { Config.reset(function() { kpsul.article_manager.reset_data(); displayAddcost(); - kpsul.history.reset(); + kpsul.history.fetch(); }); } diff --git a/kfet/templates/kfet/transfers.html b/kfet/templates/kfet/transfers.html index b8bf8c70..ba59d197 100644 --- a/kfet/templates/kfet/transfers.html +++ b/kfet/templates/kfet/transfers.html @@ -55,9 +55,6 @@ $(document).ready(function() { window.lock = 0; var history = new KHistory(); - history.api_options = { - 'transfersonly': true, - }; // ----- // Synchronization @@ -65,7 +62,7 @@ $(document).ready(function() { OperationWebSocket.add_handler((data) => history.update_data(data)); - Config.reset(history.reset.bind(history)); + Config.reset(() => history.fetch({'transfersonly': true})); }); diff --git a/kfet/views.py b/kfet/views.py index 60ba25ac..5ef21330 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -1441,11 +1441,11 @@ def kpsul_cancel_operations(request): @login_required def history_json(request): # Récupération des paramètres - from_date = request.POST.get('from', None) - to_date = request.POST.get('to', None) - checkouts = request.POST.getlist('checkouts[]', None) - accounts = request.POST.getlist('accounts[]', None) - transfers_only = request.POST.get('transfersonly', None) + from_date = request.GET.get('from', None) + to_date = request.GET.get('to', None) + checkouts = request.GET.getlist('checkouts[]', None) + accounts = request.GET.getlist('accounts[]', None) + transfers_only = request.GET.get('transfersonly', None) # Construction de la requête (sur les opérations) pour le prefetch ope_queryset_prefetch = Operation.objects.select_related(