diff --git a/kfet/static/kfet/js/history.js b/kfet/static/kfet/js/history.js index 01ca1699..5fcb8f2c 100644 --- a/kfet/static/kfet/js/history.js +++ b/kfet/static/kfet/js/history.js @@ -4,7 +4,7 @@ class KHistory { return { from: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'), }; } - constructor(display_options) { + constructor(display_options, noselect) { this.templates = { 'purchase': '
', 'specialope': '
', @@ -21,7 +21,10 @@ class KHistory { this.display_options = display_options || {}; - this._init_selection(); + if (!noselect) { + this.selection = new KHistorySelection(this); + } + this._init_events(); } @@ -45,53 +48,25 @@ class KHistory { $('#nb_opes').text(nb_opes); } - _init_selection() { - this._$container.selectable({ - filter: 'div.opegroup, div.ope', - selected: function(e, ui) { - $(ui.selected).each(function() { - if ($(this).hasClass('opegroup')) { - $(this).parent().find('.ope').addClass('ui-selected'); - } - }); - }, - unselected: function(e, ui) { - $(ui.unselected).each(function() { - if ($(this).hasClass('opegroup')) { - $(this).parent().find('.ope').removeClass('ui-selected'); - } - }); - }, - }); - } - _init_events() { var that = this; $(document).on('keydown', function(e) { - if (e.keyCode == 46) { + if (e.keyCode == 46 && that.selection) { //DEL key ; we delete the selected operations (if any) - var to_cancel = {'transfers': [], 'opes': [],}; - that._$container.find('.ope.ui-selected').each(function() { - var [type, id] = $(this).parent().attr('id').split('-'); + var to_cancel = that.selection.get_selected(); - if (type === 'transfer') - to_cancel['transfers'].push(id); - else - to_cancel['opes'].push(id); - }); if (to_cancel['opes'].length > 0 || to_cancel['transfers'].length > 0) that.cancel_operations(to_cancel); } }); } - cancel_operations(to_cancel, password='') { + cancel_operations(to_cancel) { if (window.kpsul) { var on_success = kpsul._env.coolReset; - var focus_next = kpsul.account_manager._$input_trigramme; + var focus_next = kpsul; } else { - var on_success = () => this._$container.find('.ui-selected') - .removeClass('.ui-selected') ; + var on_success = () => this.selection.reset() var focus_next = undefined; } @@ -147,7 +122,6 @@ class KHistory { } update_data(data) { - //Filter opegroups before ? var opegroups = data['opegroups']; var opes = data['opes']; @@ -181,3 +155,50 @@ class KHistory { $('#nb_opes').text(nb_opes); } } + +class KHistorySelection { + + constructor(history) { + this._$container = history._$container; + this._init(); + } + + _init() { + this._$container.selectable({ + filter: 'div.opegroup, div.ope', + selected: function(e, ui) { + $(ui.selected).each(function() { + if ($(this).hasClass('opegroup')) { + $(this).parent().find('.ope').addClass('ui-selected'); + } + }); + }, + unselected: function(e, ui) { + $(ui.unselected).each(function() { + if ($(this).hasClass('opegroup')) { + $(this).parent().find('.ope').removeClass('ui-selected'); + } + }); + }, + }); + } + + get_selected() { + var selected = {'transfers': [], 'opes': [],}; + this._$container.find('.ope.ui-selected').each(function() { + var [type, id] = $(this).parent().attr('id').split('-'); + + if (type === 'transfer') + selected['transfers'].push(id); + else + selected['opes'].push(id); + }); + + return selected; + } + + reset() { + this._$container.find('.ui-selected') + .removeClass('.ui-selected'); + } +}