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 || !org) return false;
59 if(me.id() == org.id()) return true;
60 for( var i in me.children() ) {
61 if(orgIsMine(me.children()[i], org))
69 var orgArraySearcher = {};
75 x.parent_ou(_l[i][2]);
77 orgArraySearcher[x.id()] = x;
79 for (var i in orgArraySearcher) {
80 var x = orgArraySearcher[i];
81 if (x.parent_ou() == null || x.parent_ou() == '') {
86 var parent = findOrgUnit(x.parent_ou());
87 if (!parent.children()) parent.children(new Array());
88 parent.children().push(x);
91 function _tree_killer () {
92 for (var i in orgArraySearcher) {
93 x=orgArraySearcher[i];
96 orgArraySearcher[i]=null;
99 orgArraySearcher = null;
100 globalOrgTypes = null;