Add cancel_history event

This commit is contained in:
Ludovic Stephan 2017-04-10 12:32:35 -03:00
parent cfb39b1050
commit 983a55780f
5 changed files with 26 additions and 12 deletions

View file

@ -1,6 +1,8 @@
var cancelHistory = new Event("history_cancel");
class KHistory { class KHistory {
static get default_options { static get default_options() {
return { return {
'templates': { 'templates': {
'purchase': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>', 'purchase': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
@ -70,19 +72,12 @@ class KHistory {
} }
cancel_operations(to_cancel) { cancel_operations(to_cancel) {
if (window.kpsul) { var on_success = () => document.dispatchEvent(cancelHistory);
var on_success = kpsul._env.coolReset;
var focus_next = kpsul;
} else {
var on_success = () => this.selection.reset()
var focus_next = undefined;
}
api_with_auth({ api_with_auth({
url: Urls['kfet.kpsul.cancel_operations'](), url: Urls['kfet.kpsul.cancel_operations'](),
data: to_cancel, data: to_cancel,
on_success: on_success, on_success: on_success,
focus_next: focus_next,
}) })
} }

View file

@ -13,6 +13,8 @@ class KPsulManager {
this.checkout_manager = new CheckoutManager(this); this.checkout_manager = new CheckoutManager(this);
this.article_manager = new ArticleManager(this); this.article_manager = new ArticleManager(this);
this.history = new KHistory(); this.history = new KHistory();
this._init_events();
} }
reset(soft) { reset(soft) {
@ -39,6 +41,14 @@ class KPsulManager {
return this; return this;
} }
_init_events() {
var that = this ;
$(document).on("history_cancel", function(e) {
that.reset(true);
that.focus;
});
}
} }

View file

@ -109,6 +109,10 @@ $(document).ready(function() {
var khistory = new KHistory({'no_trigramme': true}); var khistory = new KHistory({'no_trigramme': true});
$(document).on("cancel_history", function(e) {
khistory.selection.reset();
});
// ----- // -----
// Synchronization // Synchronization
// ----- // -----

View file

@ -129,6 +129,10 @@ $(document).ready(function() {
updateHistory(); updateHistory();
}); });
$(document).on("cancel_history", function(e) {
khistory.selection.reset();
});
// ----- // -----
// Synchronization // Synchronization
// ----- // -----

View file

@ -51,11 +51,12 @@
$(document).ready(function() { $(document).ready(function() {
'use strict'; 'use strict';
// Lock to avoid multiple requests
window.lock = 0;
var history = new KHistory(); var history = new KHistory();
$(document).on("cancel_history", function(e) {
khistory.selection.reset();
});
// ----- // -----
// Synchronization // Synchronization
// ----- // -----