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];
41 var orgArraySearcherSN = {};
42 function findOrgUnitSN(shortname) {
43 if (typeof shortname == 'object') return shortname;
44 if( orgArraySearcherSN[shortname] ) return orgArraySearcherSN[shortname];
45 _debug("fetching org by shortname "+shortname);
46 var req = new Request(FETCH_ORG_BY_SHORTNAME, shortname);
47 req.request.alertEvent = false;
53 /* builds a trail from the top of the org tree to the node provide.
54 basically fleshes out 'my orgs'
55 Returns an array of [org0, org1, ..., myorg] */
56 function orgNodeTrail(node) {
60 node = findOrgUnit(node.parent_ou());
65 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
67 /* true if 'org' is 'me' or a child of mine */
68 function orgIsMine(me, org) {
69 if(!me || !org) return false;
70 if(me.id() == org.id()) return true;
71 for( var i in me.children() ) {
72 if(orgIsMine(me.children()[i], org))
80 var orgArraySearcher = {};
86 x.parent_ou(_l[i][2]);
88 orgArraySearcher[x.id()] = x;
90 for (var i in orgArraySearcher) {
91 var x = orgArraySearcher[i];
92 if (x.parent_ou() == null || x.parent_ou() == '') {
97 var parent = findOrgUnit(x.parent_ou());
98 if (!parent.children()) parent.children(new Array());
99 parent.children().push(x);
102 function _tree_killer () {
103 for (var i in orgArraySearcher) {
104 x=orgArraySearcher[i];
107 orgArraySearcher[i]=null;
109 globalOrgTree = null;
110 orgArraySearcher = null;
111 globalOrgTypes = null;