2 # ---------------------------------------------------------------------------
3 # Copyright (C) 2008 Georgia Public Library Service / Equinox Software, Inc
4 # Mike Rylander <miker@esilibrary.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 # ---------------------------------------------------------------------------
18 if(!dojo._hasResource["fieldmapper.OrgUtils"]){
20 dojo._hasResource["fieldmapper.OrgUtils"] = true;
21 dojo.provide("fieldmapper.OrgUtils");
22 dojo.require("fieldmapper.Fieldmapper");
23 dojo.require("fieldmapper.hash");
24 dojo.require("fieldmapper.OrgTree", true);
25 dojo.require("fieldmapper.OrgLasso", true);
27 fieldmapper.aou.globalOrgTree = {};
28 fieldmapper.aou.OrgCache = {};
29 fieldmapper.aou.OrgCacheSN = {};
30 fieldmapper.aout.OrgTypeCache = {};
32 fieldmapper.aout.LoadOrgTypes = function () {
33 for (var i in fieldmapper.aout.OrgTypeCache) {
37 var types = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_types.retrieve']);
39 for (var i in types) {
40 fieldmapper.aout.OrgTypeCache[types[i].id()] = {
47 fieldmapper.aou.LoadOrg = function (id, slim_ok) {
48 var slim_o = fieldmapper.aou.OrgCache[id];
50 if (slim_o && (slim_ok || slim_o.loaded))
51 return fieldmapper.aou.OrgCache[id].org;
53 var o = fieldmapper.standardRequest(['open-ils.actor','open-ils.actor.org_unit.retrieve'],[null,id]);
54 fieldmapper.aou.OrgCache[o.id()] = { loaded : true, org : o };
57 fieldmapper.aou.findOrgUnit = fieldmapper.aou.LoadOrg;
61 fieldmapper.aou.OrgCache[_l[i][0]] = {
63 org : new fieldmapper.aou().fromHash({
68 opac_visible : _l[i][4],
75 for (var i in fieldmapper.aou.OrgCache) {
76 var x = fieldmapper.aou.OrgCache[i].org;
77 if (x.parent_ou() == null || x.parent_ou() == '') {
78 fieldmapper.aou.globalOrgTree = x;
82 var parent = fieldmapper.aou.findOrgUnit(x.parent_ou(),true);
83 if (!parent.children()) parent.children([]);
84 parent.children().push(x);
85 fieldmapper.aou.OrgCache[x.id()].treePtr = x;
88 for (var i in globalOrgTypes) {
89 fieldmapper.aout.OrgTypeCache[globalOrgTypes[i].id()] = {
91 type : globalOrgTypes[i]
97 /* ---------------------------------------------------------------------- */
99 fieldmapper.aou.prototype.fetchOrgSettingDefault = function (name) {
100 return this.standardRequest( fieldmapper.OpenSRF.methods.FETCH_ORG_SETTING, name );
103 fieldmapper.aout.findOrgType = function (id) {
104 fieldmapper.aout.LoadOrgTypes();
105 return fieldmapper.aout.OrgTypeCache[id].type;
108 fieldmapper.aou.prototype.findOrgDepth = function (id) {
109 if (!id) id = this.id;
110 if (!id) return null;
112 var org = fieldmapper.aou.findOrgUnit(id);
113 return fieldmapper.aout.findOrgType(
114 fieldmapper.aou.findOrgUnit(id).ou_type()
117 fieldmapper.aou.findOrgDepth = fieldmapper.aou.prototype.findOrgDepth;
119 fieldmapper.aout.findOrgTypeFromDepth = function (depth) {
120 if( depth == null ) return null;
121 fieldmapper.aout.LoadOrgTypes();
122 for( var i in fieldmapper.aout.OrgTypeCache ) {
123 var t = fieldmapper.aout.OrgTypeCache[i].type;
124 if( t.depth() == depth ) return t;
129 fieldmapper.aou.findOrgUnitSN = function (sn) {
130 var org = fieldmapper.aou.OrgCacheSN[sn];
132 for (var i in fieldmapper.aou.OrgCache) {
133 var o = fieldmapper.aou.OrgCache[i];
134 if (o.loaded && o.org.shortname() == sn) {
135 fieldmapper.aou.OrgCacheSN[o.org.shortname()] = o;
140 org = fieldmapper.standardRequest(fieldmapper.OpenSRF.methods.FETCH_ORG_BY_SHORTNAME, sn);
142 fieldmapper.aou.OrgCache[org.id()] = { loaded : true, org : org };
143 fieldmapper.aou.OrgCacheSN[org.shortname()] = { loaded : true, org : org };
150 fieldmapper.aou.prototype.orgNodeTrail = function (node) {
151 if (!node) node = this;
152 if (!node) return [];
158 node = fieldmapper.aou.findOrgUnit(node.parent_ou());
163 fieldmapper.aou.orgNodeTrail = fieldmapper.aou.prototype.orgNodeTrail;
165 fieldmapper.aou.prototype.orgIsMine = function (me, org) {
166 if (this._isfieldmapper) {
171 if(!me || !org) return false;
173 if(me.id() == org.id()) return true;
175 for( var i in me.children() ) {
176 if(me.children()[i].orgIsMine(org)) return true;
181 dojo.addOnUnload( function () {
182 for (var i in fieldmapper.aou.OrgCache) {
183 x=fieldmapper.aou.OrgCache[i].treePtr;
188 fieldmapper.aou.OrgCache[i]=null;
190 fieldmapper.aou.globalOrgTree = null;
191 fieldmapper.aou.OrgCache = null;
192 fieldmapper.aou.OrgCacheSN = null;
193 fieldmapper.aout.OrgTypeCache = null;