From 1ab9e9a32bc63fe5c2ff9b295967a5665987afcc Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 23 Aug 2005 16:13:19 +0000 Subject: [PATCH] breaking out org stuff git-svn-id: svn://svn.open-ils.org/ILS/trunk@1705 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/opac/common/js/org_utils.js | 76 ++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Open-ILS/web/opac/common/js/org_utils.js diff --git a/Open-ILS/web/opac/common/js/org_utils.js b/Open-ILS/web/opac/common/js/org_utils.js new file mode 100644 index 0000000000..3a6b744fd1 --- /dev/null +++ b/Open-ILS/web/opac/common/js/org_utils.js @@ -0,0 +1,76 @@ +/* ------------------------------------------------------------------------------------------------------ */ +/* org tree utilities */ +/* ------------------------------------------------------------------------------------------------------ */ + +/* takes an org unit or id and return the numeric depth */ +function findOrgDepth(org_id_or_node) { + return findOrgType(findOrgUnit(org_id_or_node).ou_type()).depth(); +} + +/* takes the org type id from orgunit.ou_type() field and returns + the org type object */ +function findOrgType(type_id) { + if(typeof type_id == 'object') return type_id; + for(var type in globalOrgTypes) { + var t =globalOrgTypes[type]; + if( t.id() == type_id || t.id() == parseInt(type_id) ) + return t; + } + return null; +} + + +/* returns an org unit by id. if an object is passed in as the id, + then the object is assumed to be an org unit and is returned */ +function findOrgUnit(org_id) { + return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id]; +} + + +/* builds a trail from the top of the org tree to the node provide. + basically fleshes out 'my orgs' + Returns an array of [org0, org1, ..., myorg] */ +function orgNodeTrail(node) { + var na = new Array(); + while( node ) { + na.push(node); + node = findOrgUnit(node.parent_ou()); + } + return na.reverse(); +} + + + +var orgArraySearcher = {}; +var globalOrgTree; +for (var i in _l) { + var x = new aou(); + x.id(_l[i][0]); + x.ou_type(_l[i][1]); + x.parent_ou(_l[i][2]); + x.name(_l[i][3]); + orgArraySearcher[x.id()] = x; +} +for (var i in orgArraySearcher) { + var x = orgArraySearcher[i]; + if (x.parent_ou() == null || x.parent_ou() == '') { + globalOrgTree = x; + continue; + } + + var parent = findOrgUnit(x.parent_ou()); + if (!parent.children()) parent.children(new Array()); + parent.children().push(x); +} + +function _tree_killer () { + for (var i in orgArraySearcher) { + x=orgArraySearcher[i]; + x.children(null); + x.parent_ou(null); + orgArraySearcher[i]=null; + } + globalOrgTree = null; + orgArraySearcher = null; + globalOrgTypes = null; +} -- 2.43.2