forked from DGNum/gestioCOF
Move selection logic to another class
This commit is contained in:
parent
8d13c0a4bb
commit
88f7ea941d
1 changed files with 57 additions and 36 deletions
|
@ -4,7 +4,7 @@ class KHistory {
|
||||||
return { from: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'), };
|
return { from: moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss'), };
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(display_options) {
|
constructor(display_options, noselect) {
|
||||||
this.templates = {
|
this.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>',
|
||||||
'specialope': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
|
'specialope': '<div class="ope"><span class="amount"></span><span class="infos1"></span><span class="infos2"></span><span class="addcost"></span><span class="canceled"></span></div>',
|
||||||
|
@ -21,7 +21,10 @@ class KHistory {
|
||||||
|
|
||||||
this.display_options = display_options || {};
|
this.display_options = display_options || {};
|
||||||
|
|
||||||
this._init_selection();
|
if (!noselect) {
|
||||||
|
this.selection = new KHistorySelection(this);
|
||||||
|
}
|
||||||
|
|
||||||
this._init_events();
|
this._init_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,53 +48,25 @@ class KHistory {
|
||||||
$('#nb_opes').text(nb_opes);
|
$('#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() {
|
_init_events() {
|
||||||
var that = this;
|
var that = this;
|
||||||
$(document).on('keydown', function(e) {
|
$(document).on('keydown', function(e) {
|
||||||
if (e.keyCode == 46) {
|
if (e.keyCode == 46 && that.selection) {
|
||||||
//DEL key ; we delete the selected operations (if any)
|
//DEL key ; we delete the selected operations (if any)
|
||||||
var to_cancel = {'transfers': [], 'opes': [],};
|
var to_cancel = that.selection.get_selected();
|
||||||
that._$container.find('.ope.ui-selected').each(function() {
|
|
||||||
var [type, id] = $(this).parent().attr('id').split('-');
|
|
||||||
|
|
||||||
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)
|
if (to_cancel['opes'].length > 0 || to_cancel['transfers'].length > 0)
|
||||||
that.cancel_operations(to_cancel);
|
that.cancel_operations(to_cancel);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cancel_operations(to_cancel, password='') {
|
cancel_operations(to_cancel) {
|
||||||
if (window.kpsul) {
|
if (window.kpsul) {
|
||||||
var on_success = kpsul._env.coolReset;
|
var on_success = kpsul._env.coolReset;
|
||||||
var focus_next = kpsul.account_manager._$input_trigramme;
|
var focus_next = kpsul;
|
||||||
} else {
|
} else {
|
||||||
var on_success = () => this._$container.find('.ui-selected')
|
var on_success = () => this.selection.reset()
|
||||||
.removeClass('.ui-selected') ;
|
|
||||||
var focus_next = undefined;
|
var focus_next = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +122,6 @@ class KHistory {
|
||||||
}
|
}
|
||||||
|
|
||||||
update_data(data) {
|
update_data(data) {
|
||||||
//Filter opegroups before ?
|
|
||||||
var opegroups = data['opegroups'];
|
var opegroups = data['opegroups'];
|
||||||
var opes = data['opes'];
|
var opes = data['opes'];
|
||||||
|
|
||||||
|
@ -181,3 +155,50 @@ class KHistory {
|
||||||
$('#nb_opes').text(nb_opes);
|
$('#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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue