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