]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/common/js/org_utils.js
persisting font choice
[working/Evergreen.git] / Open-ILS / web / opac / common / js / org_utils.js
1 /* ------------------------------------------------------------------------------------------------------ */
2 /* org tree utilities */
3 /* ------------------------------------------------------------------------------------------------------ */
4
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();
8 }
9
10 /* takes the org type id from orgunit.ou_type() field and returns
11         the org type object */
12 function findOrgType(type_id) {
13         if(typeof type_id == 'object') return type_id;
14         for(var type in globalOrgTypes) {
15                 var t =globalOrgTypes[type]; 
16                 if( t.id() == type_id || t.id() == parseInt(type_id) ) 
17                         return t;
18         }
19         return null;
20 }
21
22
23 /* returns an org unit by id.  if an object is passed in as the id,
24         then the object is assumed to be an org unit and is returned */
25 function findOrgUnit(org_id) {
26         return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id];
27 }
28
29
30 /* builds a trail from the top of the org tree to the node provide.
31         basically fleshes out 'my orgs' 
32         Returns an array of [org0, org1, ..., myorg] */
33 function orgNodeTrail(node) {
34         var na = new Array();
35         while( node ) {
36                 na.push(node);
37                 node = findOrgUnit(node.parent_ou());
38         }
39         return na.reverse();
40 }
41
42 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
43
44
45
46 var orgArraySearcher = {};
47 var globalOrgTree;
48 for (var i in _l) {
49         var x = new aou();
50         x.id(_l[i][0]);
51         x.ou_type(_l[i][1]);
52         x.parent_ou(_l[i][2]);
53         x.name(_l[i][3]);
54         orgArraySearcher[x.id()] = x;
55 }
56 for (var i in orgArraySearcher) {
57         var x = orgArraySearcher[i];
58         if (x.parent_ou() == null || x.parent_ou() == '') {
59                 globalOrgTree = x;
60                 continue;
61         } 
62
63         var parent = findOrgUnit(x.parent_ou());
64         if (!parent.children()) parent.children(new Array());
65         parent.children().push(x);
66 }
67
68 function _tree_killer () {
69         for (var i in orgArraySearcher) {
70                 x=orgArraySearcher[i];
71                 x.children(null);
72                 x.parent_ou(null);
73                 orgArraySearcher[i]=null;
74         }
75         globalOrgTree = null;
76         orgArraySearcher = null;
77         globalOrgTypes = null;
78 }
79
80
81