Created
March 26, 2014 13:53
-
-
Save asuraphel/9783603 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def treeOld() { | |
def locale = RequestContextUtils.getLocale(request) | |
def rootOrg = connectSecurityService.getCurrentUser()?.organization | |
if( rootOrg ) { | |
def root = buildTreeNode( rootOrg.name, "#", rootOrg.id.toString(), rootOrg.type.key ) | |
def children = organizationService.getOrganizationChildren(rootOrg) | |
children?.each { childOrg -> | |
addOrganizationToTreeNode(root, childOrg) | |
} | |
return [tree: root as JSON] | |
} | |
def rootNode = buildTreeNode(messageSource.getMessage( "organization.tree.top.parent.node.label",[].toArray(),"Organizations", locale), "", null, "") | |
rootNode.children = [] | |
rootNode.children << privateSEs << publicSEs | |
def organizations = organizationService.getOrganizationList() | |
organizations?.each { org -> | |
if(null == org.parent) | |
addOrganizationToTreeNode(rootNode, org) | |
} | |
return [tree: rootNode as JSON] | |
} | |
private void addOrganizationToTreeNode(Map<String, String> parentNode, Organization org) { | |
def node = buildTreeNode(org.name, "#", org.id.toString(), org.type.key) | |
if(!parentNode.children) | |
parentNode.children = [] | |
parentNode.children.add(node) | |
def organizationChildren = organizationService.getOrganizationChildren(org) | |
organizationChildren.each { childOrg -> | |
addOrganizationToTreeNode(node, childOrg) | |
} | |
} | |
private Map<String, String> buildTreeNode(String title, String href, String id, String type){ | |
def node = [:] | |
node.data = [title: title] | |
if(null != href) | |
node.data.attr = [href: href] | |
node.attr = [type: type, id: id ] | |
return node | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment