1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2025-07-01 03:58:38 -04:00

Reorganization around building JavaScript differently

This commit is contained in:
2016-02-13 17:02:22 -05:00
parent d6ddf0f65f
commit c5bca50113
14 changed files with 13 additions and 6 deletions

32
js/utils.js Normal file
View File

@ -0,0 +1,32 @@
const recursiveAccountDisplayInfo = function(account, prefix) {
var name = prefix + account.Name;
var accounts = [{AccountId: account.AccountId, Name: name}];
for (var i = 0; i < account.Children.length; i++)
accounts = accounts.concat(recursiveAccountDisplayInfo(account.Children[i], name + "/"));
return accounts
};
const getAccountDisplayList = function(account_list, includeRoot, rootName) {
var accounts = []
if (includeRoot)
accounts.push({AccountId: -1, Name: rootName});
for (var i = 0; i < account_list.length; i++) {
if (account_list[i].isRootAccount())
accounts = accounts.concat(recursiveAccountDisplayInfo(account_list[i], ""));
}
return accounts;
};
const getAccountDisplayName = function(account, account_map) {
var name = account.Name;
while (account.ParentAccountId >= 0) {
account = account_map[account.ParentAccountId];
name = account.Name + "/" + name;
}
return name;
};
module.exports = {
getAccountDisplayList: getAccountDisplayList,
getAccountDisplayName: getAccountDisplayName
};