diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 6a77a8ff..15e63438 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -1,6 +1,8 @@ +var cancelHistory = new Event("history_cancel"); + class KHistory { - static get default_options { + static get default_options() { return { 'templates': { 'purchase': '
', @@ -70,19 +72,12 @@ class KHistory { } cancel_operations(to_cancel) { - if (window.kpsul) { - var on_success = kpsul._env.coolReset; - var focus_next = kpsul; - } else { - var on_success = () => this.selection.reset() - var focus_next = undefined; - } + var on_success = () => document.dispatchEvent(cancelHistory); api_with_auth({ url: Urls['kfet.kpsul.cancel_operations'](), data: to_cancel, on_success: on_success, - focus_next: focus_next, }) } diff --git a/kfet/static/kfet/js/kpsul.js b/kfet/static/kfet/js/kpsul.js index 137843c7..8833d072 100644 --- a/kfet/static/kfet/js/kpsul.js +++ b/kfet/static/kfet/js/kpsul.js @@ -13,6 +13,8 @@ class KPsulManager { this.checkout_manager = new CheckoutManager(this); this.article_manager = new ArticleManager(this); this.history = new KHistory(); + + this._init_events(); } reset(soft) { @@ -39,6 +41,14 @@ class KPsulManager { return this; } + _init_events() { + var that = this ; + $(document).on("history_cancel", function(e) { + that.reset(true); + that.focus; + }); + } + } diff --git a/kfet/templates/kfet/account_read.html b/kfet/templates/kfet/account_read.html index 6c0d697a..54b91de4 100644 --- a/kfet/templates/kfet/account_read.html +++ b/kfet/templates/kfet/account_read.html @@ -109,6 +109,10 @@ $(document).ready(function() { var khistory = new KHistory({'no_trigramme': true}); + $(document).on("cancel_history", function(e) { + khistory.selection.reset(); + }); + // ----- // Synchronization // ----- diff --git a/kfet/templates/kfet/history.html b/kfet/templates/kfet/history.html index 864396eb..d432079f 100644 --- a/kfet/templates/kfet/history.html +++ b/kfet/templates/kfet/history.html @@ -129,6 +129,10 @@ $(document).ready(function() { updateHistory(); }); + $(document).on("cancel_history", function(e) { + khistory.selection.reset(); + }); + // ----- // Synchronization // ----- diff --git a/kfet/templates/kfet/transfers.html b/kfet/templates/kfet/transfers.html index ba59d197..910c5ab9 100644 --- a/kfet/templates/kfet/transfers.html +++ b/kfet/templates/kfet/transfers.html @@ -51,11 +51,12 @@ $(document).ready(function() { 'use strict'; - // Lock to avoid multiple requests - window.lock = 0; - var history = new KHistory(); + $(document).on("cancel_history", function(e) { + khistory.selection.reset(); + }); + // ----- // Synchronization // -----