WIP: Aureplop/kpsul js refactor #501
3 changed files with 38 additions and 14 deletions
|
@ -155,26 +155,47 @@ class KHistory {
|
|||
is_valid(opegroup) {
|
||||
var options = this.api_options;
|
||||
|
||||
if (options.from && dateUTCToParis(opegroup.at).isBefore(moment(options.from)))
|
||||
if (options.from && dateUTCToParis(opegroup.content.at).isBefore(moment(options.from)))
|
||||
return false;
|
||||
|
||||
if (options.to && dateUTCToParis(opegroup.at).isAfter(moment(options.to)))
|
||||
if (options.to && dateUTCToParis(opegroup.content.at).isAfter(moment(options.to)))
|
||||
return false;
|
||||
|
||||
if (options.transfersonly && opegroup.constructor.verbose_name == 'opegroup')
|
||||
return false;
|
||||
var accounts_filter = options.accounts && options.accounts.length;
|
||||
var checkouts_filter = options.checkouts && options.checkouts.length;
|
||||
|
||||
if (options.opesonly && opegroup.constructor.verbose_name == 'transfergroup')
|
||||
return false;
|
||||
if (opegroup.modelname == 'opegroup') {
|
||||
|
||||
if (options.accounts && options.accounts.length &&
|
||||
options.accounts.indexOf(opegroup.account_id) < 0)
|
||||
return false;
|
||||
if (options.transfersonly)
|
||||
return false;
|
||||
|
||||
if (options.checkouts && options.checkouts.length &&
|
||||
(opegroup.modelname == 'transfergroup' ||
|
||||
options.checkouts.indexOf(opegroup.checkout_id) < 0))
|
||||
return false;
|
||||
if (accounts_filter && options.accounts.indexOf(opegroup.content.account_id) < 0)
|
||||
return false;
|
||||
|
||||
if (checkouts_filter && options.checkouts.indexOf(opegroup.content.checkout_id) < 0)
|
||||
return false;
|
||||
|
||||
} else if (opegroup.modelname == 'transfergroup') {
|
||||
|
||||
if (options.opesonly)
|
||||
return false;
|
||||
|
||||
if (checkouts_filter)
|
||||
return false;
|
||||
|
||||
if (accounts_filter) {
|
||||
opegroup.content.children =
|
||||
opegroup.content.children.filter( function(transfer) {
|
||||
var is_from_in =
|
||||
options.accounts.indexOf(transfer.content.from_acc_id) >= 0;
|
||||
var is_to_in =
|
||||
options.accounts.indexOf(transfer.content.to_acc_id) >= 0;
|
||||
return is_from_in || is_to_in;
|
||||
});
|
||||
if (opegroup.content.children.length == 0)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -94,7 +94,8 @@ $(document).ready(function() {
|
|||
if ($checkouts)
|
||||
data['checkouts'] = checkouts;
|
||||
var accounts = getSelectedMultiple($accounts);
|
||||
data['accounts'] = accounts;
|
||||
if (accounts)
|
||||
data['accounts'] = accounts.map(id => parseInt(id));
|
||||
|
||||
// Update history
|
||||
khistory.fetch(data);
|
||||
|
|
|
@ -1817,6 +1817,8 @@ def perform_transfers(request):
|
|||
'from_acc': transfer.from_acc.trigramme,
|
||||
'to_acc': transfer.to_acc.trigramme,
|
||||
'canceled_by__trigramme': None, 'canceled_at': None,
|
||||
'from_acc_id': transfer.from_acc.id,
|
||||
'to_acc_id': transfer.to_acc.id,
|
||||
},
|
||||
}
|
||||
websocket_data['opegroups'][0]['content']['children'].append(ope_data)
|
||||
|
|
Loading…
Reference in a new issue