1 /* ------------------------------------------------------------------------------------------------------ */
2 /* org tree utilities */
3 /* ------------------------------------------------------------------------------------------------------ */
5 function fetchOrgSettingDefault(orgId, name) {
6 var req = new Request(FETCH_ORG_SETTING, orgId, name);
8 var res = req.result();
9 return (res) ? res.value : null;
14 /* takes an org unit or id and return the numeric depth */
15 function findOrgDepth(org_id_or_node) {
16 var org = findOrgUnit(org_id_or_node);
18 var type = findOrgType(org.ou_type());
19 if(type) return type.depth();
23 function findOrgTypeFromDepth(depth) {
24 if( depth == null ) return null;
25 for( var type in globalOrgTypes ) {
26 var t = globalOrgTypes[type];
27 if( t.depth() == depth ) return t;
31 /* takes the org type id from orgunit.ou_type() field and returns
32 the org type object */
33 function findOrgType(type_id) {
34 if(typeof type_id == 'object') return type_id;
35 for(var type in globalOrgTypes) {
36 var t =globalOrgTypes[type];
37 if( t.id() == type_id || t.id() == parseInt(type_id) )
44 /* returns an org unit by id. if an object is passed in as the id,
45 then the object is assumed to be an org unit and is returned */
46 function findOrgUnit(org_id) {
47 return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id];
50 function findOrgLasso(lasso_id) {
51 if (typeof lasso_id == 'object') return lasso_id;
52 for (var i in _lasso) {
53 if (_lasso[i].id() == lasso_id) return _lasso[i];
58 var orgArraySearcherSN = {};
59 function findOrgUnitSN(shortname) {
60 if (typeof shortname == 'object') return shortname;
61 if( orgArraySearcherSN[shortname] ) return orgArraySearcherSN[shortname];
62 _debug("fetching org by shortname "+shortname);
63 var req = new Request(FETCH_ORG_BY_SHORTNAME, shortname);
64 req.request.alertEvent = false;
70 /* builds a trail from the top of the org tree to the node provide.
71 basically fleshes out 'my orgs'
72 Returns an array of [org0, org1, ..., myorg] */
73 function orgNodeTrail(node) {
77 node = findOrgUnit(node.parent_ou());
82 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
84 /* true if 'org' is 'me' or a child of mine */
85 function orgIsMine(me, org) {
86 if(!me || !org) return false;
87 if(me.id() == org.id()) return true;
88 for( var i in me.children() ) {
89 if(orgIsMine(me.children()[i], org))
95 function orgIsMineFromSet(meList, org) {
96 org = findOrgUnit(org);
97 for(var i = 0; i < meList.length; i++) {
98 if(orgIsMine(findOrgUnit(meList[i]), org))
104 var orgArraySearcher = {};
110 x.parent_ou(_l[i][2]);
112 x.opac_visible(_l[i][4]);
113 orgArraySearcher[x.id()] = x;
115 for (var i in orgArraySearcher) {
116 var x = orgArraySearcher[i];
117 if (x.parent_ou() == null || x.parent_ou() == '') {
122 var par = findOrgUnit(x.parent_ou());
123 if (!par.children()) par.children(new Array());
124 par.children().push(x);
127 function _tree_killer () {
128 for (var i in orgArraySearcher) {
129 x=orgArraySearcher[i];
132 orgArraySearcher[i]=null;
134 globalOrgTree = null;
135 orgArraySearcher = null;
136 globalOrgTypes = null;