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;
12 function fetchBatchOrgSetting(orgId, nameList, onload) {
13 var req = new Request(
14 'open-ils.actor:open-ils.actor.ou_setting.ancestor_default.batch', orgId, nameList);
16 req.callback(function(r) { onload(r.getResultObject()); });
25 /* takes an org unit or id and return the numeric depth */
26 function findOrgDepth(org_id_or_node) {
27 var org = findOrgUnit(org_id_or_node);
29 var type = findOrgType(org.ou_type());
30 if(type) return type.depth();
34 function findOrgTypeFromDepth(depth) {
35 if( depth == null ) return null;
36 for( var type in globalOrgTypes ) {
37 var t = globalOrgTypes[type];
38 if( t.depth() == depth ) return t;
42 /* takes the org type id from orgunit.ou_type() field and returns
43 the org type object */
44 function findOrgType(type_id) {
45 if(typeof type_id == 'object') return type_id;
46 for(var type in globalOrgTypes) {
47 var t =globalOrgTypes[type];
48 if( t.id() == type_id || t.id() == parseInt(type_id) )
55 /* returns an org unit by id. if an object is passed in as the id,
56 then the object is assumed to be an org unit and is returned */
57 function findOrgUnit(org_id) {
58 return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id];
61 function findOrgLasso(lasso_id) {
62 if (typeof lasso_id == 'object') return lasso_id;
63 for (var i in _lasso) {
64 if (_lasso[i].id() == lasso_id) return _lasso[i];
69 var orgArraySearcherSN = {};
70 function findOrgUnitSN(shortname) {
71 if (typeof shortname == 'object') return shortname;
72 if( orgArraySearcherSN[shortname] ) return orgArraySearcherSN[shortname];
73 _debug("fetching org by shortname "+shortname);
74 var req = new Request(FETCH_ORG_BY_SHORTNAME, shortname);
75 req.request.alertEvent = false;
81 /* builds a trail from the top of the org tree to the node provide.
82 basically fleshes out 'my orgs'
83 Returns an array of [org0, org1, ..., myorg] */
84 function orgNodeTrail(node) {
88 node = findOrgUnit(node.parent_ou());
93 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
95 /* true if 'org' is 'me' or a child of mine */
96 function orgIsMine(me, org) {
97 if(!me || !org) return false;
98 if(me.id() == org.id()) return true;
99 for( var i in me.children() ) {
100 if(orgIsMine(me.children()[i], org))
106 function orgIsMineFromSet(meList, org) {
107 org = findOrgUnit(org);
108 for(var i = 0; i < meList.length; i++) {
109 if(orgIsMine(findOrgUnit(meList[i]), org))
115 var orgArraySearcher = {};
121 x.parent_ou(_l[i][2]);
123 x.opac_visible(_l[i][4]);
124 x.shortname(_l[i][5]);
125 orgArraySearcher[x.id()] = x;
127 for (var i in orgArraySearcher) {
128 var x = orgArraySearcher[i];
129 if (x.parent_ou() == null || x.parent_ou() == '') {
134 var par = findOrgUnit(x.parent_ou());
135 if (!par.children()) par.children(new Array());
136 par.children().push(x);
139 function _tree_killer () {
140 for (var i in orgArraySearcher) {
141 x=orgArraySearcher[i];
144 orgArraySearcher[i]=null;
146 globalOrgTree = null;
147 orgArraySearcher = null;
148 globalOrgTypes = null;