4 /* these are the types of resource provided my MODS - used in virtual records */
5 var resourceFormats = [
9 "software, multimedia",
14 "three dimensional object" ];
18 function findOrgDepth(type_id) {
20 if(type_id == null || globalOrgTypes == null)
23 var t = findOrgType(type_id);
30 function findOrgType(type_id) {
32 if(type_id == null || globalOrgTypes == null)
35 if(typeof type_id == 'object')
38 for(var type in globalOrgTypes) {
39 var t =globalOrgTypes[type];
40 if( t.id() == type_id || t.id() == parseInt(type_id) )
47 /* locates a specific org unit */
48 var orgArraySearcher = null;
50 /* flatten the org tree for faster searching */
51 function _flattenOrgs(node) {
55 orgArraySearcher = new Object();
58 orgArraySearcher[node.id()] = node;
59 for(var idx in node.children()) {
60 _flattenOrgs(node.children()[idx]);
64 var singleOrgCache = new Object();
65 function findOrgUnit(org_id, branch) {
67 if(org_id == null) return null;
68 if(typeof org_id == 'object') return org_id;
70 /* if we don't have the global org tree, grab the org unit from the server */
71 var tree_exists = false;
72 try{if(globalOrgTree != null) tree_exists = true;}catch(E){}
75 var org = singleOrgCache[org_id];
77 var r = new RemoteRequest(
79 "open-ils.actor.org_unit.retrieve", null, org_id);
81 return r.getResultObject();
84 if(orgArraySearcher == null)
87 return orgArraySearcher[org_id];
91 function getOrgById(id, node) {
92 if(node == null) node = globalOrgTree;
93 if( node.id() == id) return node;
94 for( var ind in node.children() ) {
95 var ret = getOrgById(id, node.children()[ind] );
104 function orgNodeTrail(node) {
105 var nodeArray = new Array();
107 nodeArray.push(node);
108 node = findOrgUnit(node.parent_ou());
110 nodeArray = nodeArray.reverse();
114 function findSiblingOrgs(node) {
115 return findOrgUnit(node.parent_ou()).children();
119 function grabCopyLocations() {
121 if(globalCopyLocations != null) return;
122 debug("Grabbing copy locations");
124 var req = new RemoteRequest(
126 "open-ils.search.config.copy_location.retrieve.all" );
129 globalCopyLocations = req.getResultObject();
130 return globalCopyLocations;
134 function findCopyLocation(id) {
137 if(typeof id == 'object') return id;
139 if(globalCopyLocations == null)
140 throw new EXLogic("globalCopyLocations is NULL");
142 for( var x = 0; x!= globalCopyLocations.length; x++) {
143 if(globalCopyLocations[x].id() == id)
144 return globalCopyLocations[x];
150 function modsFormatToMARC(format) {
156 case "sound recording":
158 case "sound recording-nonmusical":
160 case "sound recording-musical":
162 case "software, multimedia":
168 case "mixed material":
170 case "notated music":
172 case "three dimensional object":
177 //throw new EXLogic("Invalid format provided form modsFormatToMARC: " + format);
180 function MARCFormatToMods(format) {
188 return "moving image";
191 return "sound recording-nonmusical";
194 return "sound recording-musical";
197 return "software, multimedia";
200 return "still images";
204 return "cartographic";
208 return "mixed material";
212 return "notated music";
215 return "three dimensional object";
220 //throw new EXLogic("Invalid format provided for MARCFormatToMods: " + format);
225 /* if callback exists, call is asynchronous and
226 the returned item is passed to the callback... */
227 function fetchRecord(id, callback) {
229 var req = new RemoteRequest(
231 "open-ils.search.biblio.record.mods_slim.retrieve",
235 req.setCompleteCallback(
236 function(req) {callback(req.getResultObject())});
240 return req.getResultObject();
244 /* if callback exists, call is asynchronous and
245 the returned item is passed to the callback... */
246 function fetchMetaRecord(id, callback) {
247 var req = new RemoteRequest(
249 "open-ils.search.biblio.metarecord.mods_slim.retrieve",
253 req.setCompleteCallback(
254 function(req) {callback(req.getResultObject())});
258 return req.getResultObject();
262 /* if callback exists, call is asynchronous and
263 the returned item is passed to the callback... */
264 /* XXX no method yet... */
265 function fetchVolume(id, callback) {
266 var req = new RemoteRequest(
268 "open-ils.search.biblio.metarecord.mods_slim.retrieve",
272 req.setCompleteCallback(
273 function(req) {callback(req.getResultObject())});
277 return req.getResultObject();
281 /* if callback exists, call is asynchronous and
282 the returned item is passed to the callback... */
283 function fetchCopy(id, callback) {
284 var req = new RemoteRequest(
286 "open-ils.search.asset.copy.fleshed.retrieve",
290 req.setCompleteCallback(
291 function(req) {callback(req.getResultObject())});
295 return req.getResultObject();
299 function mkResourceImage(resource) {
300 var pic = elem("img");
301 pic.setAttribute("src", "/images/" + resource + ".jpg");
302 pic.setAttribute("width", "20");
303 pic.setAttribute("height", "20");
304 pic.setAttribute("title", resource);
310 function doLogout() {
312 /* remove cookie so browser know's we're logged out */
313 deleteCookie("ils_ses");
315 var user = UserSession.instance();
316 if( user.session_id ) {
317 var request = new RemoteRequest( "open-ils.auth",
318 "open-ils.auth.session.delete", user.session_id );
320 var response = request.getResultObject();
322 //alert("error logging out"); /* exception */
326 /* completely destroy this user object */
331 function cleanISBN(isbn) {
333 isbn = isbn.replace(/^\s+/,"");
334 var idx = isbn.indexOf(" ");
336 isbn = isbn.substring(0, idx);
345 function grabUserByBarcode(login, barcode) {
346 if(!barcode) return null;
347 var req = new RemoteRequest(
349 "open-ils.actor.user.fleshed.retrieve_by_barcode",
353 return req.getResultObject();