1 /* takes an org unit or id and return the numeric depth */
2 function findOrgDepth(org_id_or_node) {
4 if(org_id_or_node == null || globalOrgTypes == null)
7 var org = findOrgUnit(org_id_or_node);
9 var t = findOrgType(org.ou_type());
10 if(t != null) return t.depth();
15 /* takes the org type id from orgunit.ou_type() field and returns
16 the org type object */
17 function findOrgType(type_id) {
19 if(type_id == null || globalOrgTypes == null)
22 if(typeof type_id == 'object')
25 for(var type in globalOrgTypes) {
26 var t =globalOrgTypes[type];
27 if( t.id() == type_id || t.id() == parseInt(type_id) )
34 /* locates a specific org unit by id, acts as a cache of orgs*/
35 var orgArraySearcher = null;
37 /* flatten the org tree for faster searching */
38 function _flattenOrgs(node) {
42 orgArraySearcher = new Object();
45 orgArraySearcher[node.id()] = node;
46 for(var idx in node.children()) {
47 _flattenOrgs(node.children()[idx]);
51 /* returns an org unit by id. if an object is passed in as the id,
52 then the object is assumed to be an org unit and is returned */
53 function findOrgUnit(org_id, branch) {
55 if(org_id == null) return null;
56 if(typeof org_id == 'object') return org_id;
58 /* if we don't have the global org tree, grab the org unit from the server */
59 var tree_exists = false;
60 try{if(globalOrgTree != null) tree_exists = true;}catch(E){}
63 var org = orgArraySearcher[org_id];
65 var r = new RemoteRequest(
67 "open-ils.actor.org_unit.retrieve", null, org_id);
69 orgArraySearcher[org_id] = r.getResultObject();
70 return orgArraySearcher[org_id];
73 if(orgArraySearcher == null)
76 return orgArraySearcher[org_id];
80 /* builds a trail from the top of the org tree to the node provide.
81 basically fleshes out 'my orgs'
82 Returns an array of [org0, org1, ..., myorg]
84 function orgNodeTrail(node) {
85 var nodeArray = new Array();
88 node = findOrgUnit(node.parent_ou());
90 nodeArray = nodeArray.reverse();
95 /* returns an array of sibling org units */
96 function findSiblingOrgs(node) {
97 return findOrgUnit(node.parent_ou()).children();