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":
175 throw new EXLogic("Invalid format provided form modsFormatToMARC: " + format);
178 function MARCFormatToMods(format) {
186 return "moving image";
189 return "sound recording-nonmusical";
192 return "sound recording-musical";
195 return "software, multimedia";
198 return "still images";
202 return "cartographic";
206 return "mixed material";
210 return "notated music";
213 return "three dimensional object";
215 throw new EXLogic("Invalid format provided for MARCFormatToMods: " + format);
220 /* if callback exists, call is asynchronous and
221 the returned item is passed to the callback... */
222 function fetchRecord(id, callback) {
224 var req = new RemoteRequest(
226 "open-ils.search.biblio.record.mods_slim.retrieve",
230 req.setCompleteCallback(
231 function(req) {callback(req.getResultObject())});
235 return req.getResultObject();
239 /* if callback exists, call is asynchronous and
240 the returned item is passed to the callback... */
241 function fetchMetaRecord(id, callback) {
242 var req = new RemoteRequest(
244 "open-ils.search.biblio.metarecord.mods_slim.retrieve",
248 req.setCompleteCallback(
249 function(req) {callback(req.getResultObject())});
253 return req.getResultObject();
257 /* if callback exists, call is asynchronous and
258 the returned item is passed to the callback... */
259 /* XXX no method yet... */
260 function fetchVolume(id, callback) {
261 var req = new RemoteRequest(
263 "open-ils.search.biblio.metarecord.mods_slim.retrieve",
267 req.setCompleteCallback(
268 function(req) {callback(req.getResultObject())});
272 return req.getResultObject();
276 /* if callback exists, call is asynchronous and
277 the returned item is passed to the callback... */
278 function fetchCopy(id, callback) {
279 var req = new RemoteRequest(
281 "open-ils.search.asset.copy.fleshed.retrieve",
285 req.setCompleteCallback(
286 function(req) {callback(req.getResultObject())});
290 return req.getResultObject();
294 function mkResourceImage(resource) {
295 var pic = elem("img");
296 pic.setAttribute("src", "/images/" + resource + ".jpg");
297 pic.setAttribute("width", "20");
298 pic.setAttribute("height", "20");
299 pic.setAttribute("title", resource);
305 function doLogout() {
307 /* remove cookie so browser know's we're logged out */
308 deleteCookie("ils_ses");
310 var user = UserSession.instance();
311 if( user.session_id ) {
312 var request = new RemoteRequest( "open-ils.auth",
313 "open-ils.auth.session.delete", user.session_id );
315 var response = request.getResultObject();
317 //alert("error logging out"); /* exception */
321 /* completely destroy this user object */
326 function cleanISBN(isbn) {
328 isbn = isbn.replace(/^\s+/,"");
329 var idx = isbn.indexOf(" ");
331 isbn = isbn.substring(0, idx);
340 function grabUserByBarcode(login, barcode) {
341 if(!barcode) return null;
342 var req = new RemoteRequest(
344 "open-ils.actor.user.fleshed.retrieve_by_barcode",
348 return req.getResultObject();