1 /* ------------------------------------------------------------------------------------------------------ */
2 /* org tree utilities */
3 /* ------------------------------------------------------------------------------------------------------ */
5 /* takes an org unit or id and return the numeric depth */
6 function findOrgDepth(org_id_or_node) {
7 return findOrgType(findOrgUnit(org_id_or_node).ou_type()).depth();
10 /* takes the org type id from orgunit.ou_type() field and returns
11 the org type object */
12 function findOrgType(type_id) {
13 if(typeof type_id == 'object') return type_id;
14 for(var type in globalOrgTypes) {
15 var t =globalOrgTypes[type];
16 if( t.id() == type_id || t.id() == parseInt(type_id) )
23 /* returns an org unit by id. if an object is passed in as the id,
24 then the object is assumed to be an org unit and is returned */
25 function findOrgUnit(org_id) {
26 return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id];
30 /* builds a trail from the top of the org tree to the node provide.
31 basically fleshes out 'my orgs'
32 Returns an array of [org0, org1, ..., myorg] */
33 function orgNodeTrail(node) {
37 node = findOrgUnit(node.parent_ou());
42 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
46 var orgArraySearcher = {};
52 x.parent_ou(_l[i][2]);
54 orgArraySearcher[x.id()] = x;
56 for (var i in orgArraySearcher) {
57 var x = orgArraySearcher[i];
58 if (x.parent_ou() == null || x.parent_ou() == '') {
63 var parent = findOrgUnit(x.parent_ou());
64 if (!parent.children()) parent.children(new Array());
65 parent.children().push(x);
68 function _tree_killer () {
69 for (var i in orgArraySearcher) {
70 x=orgArraySearcher[i];
73 orgArraySearcher[i]=null;
76 orgArraySearcher = null;
77 globalOrgTypes = null;