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 "software, multimedia":
164 case "mixed material":
166 case "notated music":
168 case "three dimensional object":
171 throw new EXLogic("Invalid format provided form modsFormatToMARC: " + format);
174 function MARCFormatToMods(format) {
182 return "moving image";
186 return "sound recording";
189 return "software, multimedia";
192 return "still images";
196 return "cartographic";
200 return "mixed material";
204 return "notated music";
207 return "three dimensional object";
209 throw new EXLogic("Invalid format provided for MARCFormatToMods: " + format);
214 /* if callback exists, call is asynchronous and
215 the returned item is passed to the callback... */
216 function fetchRecord(id, callback) {
218 var req = new RemoteRequest(
220 "open-ils.search.biblio.record.mods_slim.retrieve",
224 req.setCompleteCallback(
225 function(req) {callback(req.getResultObject())});
229 return req.getResultObject();
233 /* if callback exists, call is asynchronous and
234 the returned item is passed to the callback... */
235 function fetchMetaRecord(id, callback) {
236 var req = new RemoteRequest(
238 "open-ils.search.biblio.metarecord.mods_slim.retrieve",
242 req.setCompleteCallback(
243 function(req) {callback(req.getResultObject())});
247 return req.getResultObject();
251 /* if callback exists, call is asynchronous and
252 the returned item is passed to the callback... */
253 /* XXX no method yet... */
254 function fetchVolume(id, callback) {
255 var req = new RemoteRequest(
257 "open-ils.search.biblio.metarecord.mods_slim.retrieve",
261 req.setCompleteCallback(
262 function(req) {callback(req.getResultObject())});
266 return req.getResultObject();
270 /* if callback exists, call is asynchronous and
271 the returned item is passed to the callback... */
272 function fetchCopy(id, callback) {
273 var req = new RemoteRequest(
275 "open-ils.search.asset.copy.fleshed.retrieve",
279 req.setCompleteCallback(
280 function(req) {callback(req.getResultObject())});
284 return req.getResultObject();
288 function mkResourceImage(resource) {
289 var pic = elem("img");
290 pic.setAttribute("src", "/images/" + resource + ".jpg");
291 pic.setAttribute("width", "20");
292 pic.setAttribute("height", "20");
293 pic.setAttribute("title", resource);
299 function doLogout() {
301 /* remove cookie so browser know's we're logged out */
302 deleteCookie("ils_ses");
304 var user = UserSession.instance();
305 if( user.session_id ) {
306 var request = new RemoteRequest( "open-ils.auth",
307 "open-ils.auth.session.delete", user.session_id );
309 var response = request.getResultObject();
311 //alert("error logging out"); /* exception */
315 /* completely destroy this user object */
320 function cleanISBN(isbn) {
322 isbn = isbn.replace(/^\s+/,"");
323 var idx = isbn.indexOf(" ");
325 isbn = isbn.substring(0, idx);
334 function grabUserByBarcode(barcode) {
335 if(!barcode) return null;
336 var req = new RemoteRequest(
338 "open-ils.actor.user.fleshed.retrieve_by_barcode",
341 return req.send(true).getResultObject();