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 function findOrgTypeFromDepth(depth) {
11 if( depth == null ) return null;
12 for( var type in globalOrgTypes ) {
13 var t = globalOrgTypes[type];
14 if( t.depth() == depth ) return t;
18 /* takes the org type id from orgunit.ou_type() field and returns
19 the org type object */
20 function findOrgType(type_id) {
21 if(typeof type_id == 'object') return type_id;
22 for(var type in globalOrgTypes) {
23 var t =globalOrgTypes[type];
24 if( t.id() == type_id || t.id() == parseInt(type_id) )
31 /* returns an org unit by id. if an object is passed in as the id,
32 then the object is assumed to be an org unit and is returned */
33 function findOrgUnit(org_id) {
34 return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id];
38 /* builds a trail from the top of the org tree to the node provide.
39 basically fleshes out 'my orgs'
40 Returns an array of [org0, org1, ..., myorg] */
41 function orgNodeTrail(node) {
45 node = findOrgUnit(node.parent_ou());
50 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
52 /* true if 'org' is 'me' or a child of mine */
53 function orgIsMine(me, org) {
54 if(me.id() == org.id()) return true;
55 for( var i in me.children() ) {
56 if(orgIsMine(me.children()[i], org))
64 var orgArraySearcher = {};
70 x.parent_ou(_l[i][2]);
72 orgArraySearcher[x.id()] = x;
74 for (var i in orgArraySearcher) {
75 var x = orgArraySearcher[i];
76 if (x.parent_ou() == null || x.parent_ou() == '') {
81 var parent = findOrgUnit(x.parent_ou());
82 if (!parent.children()) parent.children(new Array());
83 parent.children().push(x);
86 function _tree_killer () {
87 for (var i in orgArraySearcher) {
88 x=orgArraySearcher[i];
91 orgArraySearcher[i]=null;
94 orgArraySearcher = null;
95 globalOrgTypes = null;