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(); }
44 /* true if 'org' is 'me' or a child of mine */
45 function orgIsMine(me, org) {
46 if(me.id() == org.id()) return true;
47 for( var i in me.children() ) {
48 if(orgIsMine(me.children()[i], org))
56 var orgArraySearcher = {};
62 x.parent_ou(_l[i][2]);
64 orgArraySearcher[x.id()] = x;
66 for (var i in orgArraySearcher) {
67 var x = orgArraySearcher[i];
68 if (x.parent_ou() == null || x.parent_ou() == '') {
73 var parent = findOrgUnit(x.parent_ou());
74 if (!parent.children()) parent.children(new Array());
75 parent.children().push(x);
78 function _tree_killer () {
79 for (var i in orgArraySearcher) {
80 x=orgArraySearcher[i];
83 orgArraySearcher[i]=null;
86 orgArraySearcher = null;
87 globalOrgTypes = null;