]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/lib/js/opac/org_utils.js
opac, here we come
[working/Evergreen.git] / Open-ILS / src / javascript / lib / js / opac / org_utils.js
1 /* takes an org unit or id and return the numeric depth */
2 function findOrgDepth(org_id_or_node) {
3
4         if(org_id_or_node == null || globalOrgTypes == null)
5                 return null;
6
7         var org = findOrgUnit(org_id_or_node);
8
9         var t = findOrgType(org.ou_type());
10         if(t != null) return t.depth();
11
12         return null;
13 }
14
15 /* takes the org type id from orgunit.ou_type() field and returns
16         the org type object */
17 function findOrgType(type_id) {
18
19         if(type_id == null || globalOrgTypes == null)
20                 return null;
21
22         if(typeof type_id == 'object')
23                 return type_id;
24
25         for(var type in globalOrgTypes) {
26                 var t =globalOrgTypes[type]; 
27                 if( t.id() == type_id || t.id() == parseInt(type_id) ) 
28                         return t;
29         }
30         return null;
31 }
32
33
34 /* returns an org unit by id.  if an object is passed in as the id,
35         then the object is assumed to be an org unit and is returned */
36 function findOrgUnit(org_id) {
37         if(org_id == null) return null;
38         if(typeof org_id == 'object') return org_id;
39         return orgArraySearcher[org_id];
40 }
41
42
43 /* builds a trail from the top of the org tree to the node provide.
44         basically fleshes out 'my orgs' 
45         Returns an array of [org0, org1, ..., myorg]
46  */
47 function orgNodeTrail(node) {
48         var nodeArray = new Array();
49         while( node ) {
50                 nodeArray.push(node);
51                 node = findOrgUnit(node.parent_ou());
52         }
53         nodeArray = nodeArray.reverse();
54         return nodeArray;
55 }
56
57
58 /* returns an array of sibling org units */
59 function findSiblingOrgs(node) {
60         return findOrgUnit(node.parent_ou()).children();
61 }
62