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 var org = findOrgUnit(org_id_or_node);
9 var type = findOrgType(org.ou_type());
10 if(type) return type.depth();
14 function findOrgTypeFromDepth(depth) {
15 if( depth == null ) return null;
16 for( var type in globalOrgTypes ) {
17 var t = globalOrgTypes[type];
18 if( t.depth() == depth ) return t;
22 /* takes the org type id from orgunit.ou_type() field and returns
23 the org type object */
24 function findOrgType(type_id) {
25 if(typeof type_id == 'object') return type_id;
26 for(var type in globalOrgTypes) {
27 var t =globalOrgTypes[type];
28 if( t.id() == type_id || t.id() == parseInt(type_id) )
35 /* returns an org unit by id. if an object is passed in as the id,
36 then the object is assumed to be an org unit and is returned */
37 function findOrgUnit(org_id) {
38 return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id];
42 /* builds a trail from the top of the org tree to the node provide.
43 basically fleshes out 'my orgs'
44 Returns an array of [org0, org1, ..., myorg] */
45 function orgNodeTrail(node) {
49 node = findOrgUnit(node.parent_ou());
54 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
56 /* true if 'org' is 'me' or a child of mine */
57 function orgIsMine(me, org) {
58 if(me.id() == org.id()) return true;
59 for( var i in me.children() ) {
60 if(orgIsMine(me.children()[i], org))
68 var orgArraySearcher = {};
74 x.parent_ou(_l[i][2]);
76 orgArraySearcher[x.id()] = x;
78 for (var i in orgArraySearcher) {
79 var x = orgArraySearcher[i];
80 if (x.parent_ou() == null || x.parent_ou() == '') {
85 var parent = findOrgUnit(x.parent_ou());
86 if (!parent.children()) parent.children(new Array());
87 parent.children().push(x);
90 function _tree_killer () {
91 for (var i in orgArraySearcher) {
92 x=orgArraySearcher[i];
95 orgArraySearcher[i]=null;
98 orgArraySearcher = null;
99 globalOrgTypes = null;