1 /* - Request ------------------------------------------------------------- */
3 /* define it again here for pages that don't load RemoteRequest */
4 function isXUL() { try { if(IAMXUL) return true;}catch(e){return false;}; }
7 var cookieManager = new HTTP.Cookies();
9 var __ilsEvent; /* the last event the occurred */
12 function Request(type) {
14 var s = type.split(":");
15 if(s[2] == "1" && isXUL()) s[1] += ".staff";
16 this.request = new RemoteRequest(s[0], s[1]);
20 if(!location.href.match(/^https:/))
21 this.request.setSecure(false);
25 if( G.user && G.user.session ) {
26 /* if the user is logged in, all activity resets the timeout
27 This is not entirely accurate in the sense that not all
28 requests will reset the server timeout - this should
29 get close enough, however.
31 var at = getAuthtime();
32 if(at) new AuthTimer(at).run();
36 for( var x = 1; x!= arguments.length; x++ ) {
38 this.request.addParam(arguments[x]);
43 for( var i = 0; i != p.length; i++ ) {
44 if( i > 0 ) str += ", "
47 _debug('request ' + s[0] + ' ' + s[1] + ' ' + str );
49 } else if( DEBUGSLIM ) {
50 _debug('request ' + s[1]);
54 Request.prototype.callback = function(cal) {this.request.setCompleteCallback(cal);}
55 Request.prototype.send = function(block){this.request.send(block);}
56 Request.prototype.result = function(){return this.request.getResultObject();}
58 function showCanvas() {
59 for( var x in G.ui.altcanvas ) {
60 hideMe(G.ui.altcanvas[x]);
62 hideMe(G.ui.common.loading);
63 unHideMe(G.ui.common.canvas_main);
64 try{G.ui.searchbar.text.focus();}catch(e){}
67 function swapCanvas(newNode) {
68 for( var x in G.ui.altcanvas )
69 hideMe(G.ui.altcanvas[x]);
71 hideMe(G.ui.common.loading);
72 hideMe(G.ui.common.canvas_main);
76 /* finds the name of the current page */
77 var currentPage = null;
78 function findCurrentPage() {
79 if(currentPage) return currentPage;
82 for( var p in config.page ) pages.push(config.page[p]);
83 pages = pages.sort( function(a,b){ return - (a.length - b.length); } );
85 var path = location.pathname;
86 if(!path.match(/.*\.xml$/))
87 path += "index.xml"; /* in case they go to / */
90 for( var p in pages ) {
91 if( path.indexOf(pages[p]) != -1)
95 for( var p in config.page ) {
96 if(config.page[p] == page) {
105 /* sets all of the params values ----------------------------- */
106 function initParams() {
109 /* handle the location var */
111 var loc = cgi.param(PARAM_LOCATION);
113 org = findOrgUnit(loc);
114 if(!org) org = findOrgUnitSN(loc);
116 LOCATION = (org) ? org.id() : null;
119 loc = cgi.param(PARAM_ORIGLOC);
121 org = findOrgUnit(loc);
122 if(!org) org = findOrgUnitSN(loc);
124 ORIGLOC = (org) ? org.id() : null;
127 DEPTH = parseInt(cgi.param(PARAM_DEPTH));
128 if(isNaN(DEPTH)) DEPTH = null;
131 TERM = cgi.param(PARAM_TERM);
132 STYPE = cgi.param(PARAM_STYPE);
133 FORM = cgi.param(PARAM_FORM);
134 //DEPTH = parseInt(cgi.param(PARAM_DEPTH));
135 OFFSET = parseInt(cgi.param(PARAM_OFFSET));
136 COUNT = parseInt(cgi.param(PARAM_COUNT));
137 HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT));
138 MRID = parseInt(cgi.param(PARAM_MRID));
139 RID = parseInt(cgi.param(PARAM_RID));
140 AUTHTIME = parseInt(cgi.param(PARAM_AUTHTIME));
141 ADVTERM = cgi.param(PARAM_ADVTERM);
142 ADVTYPE = cgi.param(PARAM_ADVTYPE);
143 RTYPE = cgi.param(PARAM_RTYPE);
144 SORT = cgi.param(PARAM_SORT);
145 SORT_DIR = cgi.param(PARAM_SORT_DIR);
146 DEBUG = cgi.param(PARAM_DEBUG);
147 CALLNUM = cgi.param(PARAM_CN);
148 LITFORM = cgi.param(PARAM_LITFORM);
149 ITEMFORM = cgi.param(PARAM_ITEMFORM);
150 ITEMTYPE = cgi.param(PARAM_ITEMTYPE);
151 BIBLEVEL = cgi.param(PARAM_BIBLEVEL);
152 AUDIENCE = cgi.param(PARAM_AUDIENCE);
153 SEARCHES = cgi.param(PARAM_SEARCHES);
154 LANGUAGE = cgi.param(PARAM_LANGUAGE);
155 TFORM = cgi.param(PARAM_TFORM);
156 RDEPTH = cgi.param(PARAM_RDEPTH);
157 AVAIL = cgi.param(PARAM_AVAIL);
159 /* set up some sane defaults */
160 //if(isNaN(DEPTH)) DEPTH = 0;
161 if(isNaN(RDEPTH)) RDEPTH = 0;
162 if(isNaN(OFFSET)) OFFSET = 0;
163 if(isNaN(COUNT)) COUNT = 10;
164 if(isNaN(HITCOUNT)) HITCOUNT = 0;
165 if(isNaN(MRID)) MRID = 0;
166 if(isNaN(RID)) RID = 0;
167 if(isNaN(ORIGLOC)) ORIGLOC = 0; /* so we know it hasn't been set */
168 if(isNaN(AUTHTIME)) AUTHTIME = 0;
169 if(ADVTERM==null) ADVTERM = "";
170 if(isNaN(AVAIL)) AVAIL = 0;
173 function clearSearchParams() {
200 function initCookies() {
201 FONTSIZE = "regular";
202 var font = cookieManager.read(COOKIE_FONT);
204 if(font) FONTSIZE = font;
205 SKIN = cookieManager.read(COOKIE_SKIN);
206 if(findCurrentPage() == HOME)
207 cookieManager.remove(COOKIE_SEARCH);
212 /* URL param accessors */
213 function getTerm(){return TERM;}
214 function getStype(){return STYPE;}
215 function getLocation(){return LOCATION;}
216 function getDepth(){return DEPTH;}
217 function getForm(){return FORM;}
218 function getTform(){return TFORM;}
219 function getOffset(){return OFFSET;}
220 function getDisplayCount(){return COUNT;}
221 function getHitCount(){return HITCOUNT;}
222 function getMrid(){return MRID;};
223 function getRid(){return RID;};
224 function getOrigLocation(){return ORIGLOC;}
225 function getAuthtime() { return AUTHTIME; }
226 function getSearchBarExtras(){return SBEXTRAS;}
227 function getFontSize(){return FONTSIZE;};
228 function getSkin(){return SKIN;};
229 function getAdvTerm(){return ADVTERM;}
230 function getAdvType(){return ADVTYPE;}
231 function getRtype(){return RTYPE;}
232 function getSort(){return SORT;}
233 function getSortDir(){return SORT_DIR;}
234 function getDebug(){return DEBUG;}
235 function getCallnumber() { return CALLNUM; }
236 function getLitForm() { return LITFORM; }
237 function getItemForm() { return ITEMFORM; }
238 function getItemType() { return ITEMTYPE; }
239 function getBibLevel() { return BIBLEVEL; }
240 function getAudience() { return AUDIENCE; }
241 function getSearches() { return SEARCHES; }
242 function getLanguage() { return LANGUAGE; }
243 function getRdepth() { return RDEPTH; }
244 function getAvail() { return AVAIL; }
247 function findBasePath() {
248 var path = location.pathname;
249 if(!path.match(/.*\.xml$/)) path += "index.xml";
250 var idx = path.indexOf(config.page[findCurrentPage()]);
251 return path.substring(0, idx);
254 function findBaseURL(ssl) {
255 var path = findBasePath();
256 var proto = (ssl) ? "https:" : "http:";
258 /* strip port numbers. This is necessary for browsers that
259 send an explicit <host>:80, 443 - explicit ports
260 break links that need to change ports (e.g. http -> https) */
261 var h = location.host.replace(/:.*/,'');
263 return proto + "//" + h + path;
267 function buildISBNSrc(isbn) {
268 return "http://" + location.host + "/jackets/" + isbn;
272 function buildImageLink(name, ssl) {
273 return findBaseURL(ssl) + "../../../../images/" + name;
276 function buildExtrasLink(name, ssl) {
277 return findBaseURL(ssl) + "../../../../extras/" + name;
281 function _debug(str) {
282 try { dump('dbg: ' + str + '\n'); } catch(e) {}
284 /* potentially useful, but usually just annoying */
287 if(!consoleService) {
289 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
290 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
291 .getService(Components.interfaces.nsIConsoleService);
297 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
298 consoleService.logStringMessage(str + '\n');
305 function buildOPACLink(args, slim, ssl) {
311 string = findBaseURL(ssl);
312 if(args.page) string += config.page[args.page];
313 else string += config.page[findCurrentPage()];
316 /* this may seem unnecessary.. safety precaution for now */
318 if( args[PARAM_DEPTH] == null )
319 args[PARAM_DEPTH] = getDepth();
324 for( var x in args ) {
326 if(x == "page" || v == null || v == undefined || v+'' == 'NaN' ) continue;
327 if(x == PARAM_OFFSET && v == 0) continue;
328 if(x == PARAM_COUNT && v == 10) continue;
329 if(x == PARAM_FORM && v == 'all' ) continue;
330 if( instanceOf(v, Array) && v.length ) {
331 for( var i = 0; i < v.length; i++ ) {
332 string += "&" + x + "=" + encodeURIComponent(v[i]);
335 string += "&" + x + "=" + encodeURIComponent(v);
340 string += _appendParam(DEBUG, PARAM_DEBUG, args, getDebug, string);
341 if(getOrigLocation() != 1)
342 string += _appendParam(ORIGLOC, PARAM_ORIGLOC, args, getOrigLocation, string);
344 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
346 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
347 if(getLocation() != 1)
348 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
349 if(getDepth() != null)
350 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
351 if(getForm() && (getForm() != 'all') )
352 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
353 if(getTform() && (getTform() != 'all') )
354 string += _appendParam(TFORM, PARAM_TFORM, args, getTform, string);
356 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
357 if(getDisplayCount() != 10)
358 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
360 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
362 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
364 string += _appendParam(RID, PARAM_RID, args, getRid, string);
366 string += _appendParam(AUTHTIME, PARAM_AUTHTIME, args, getAuthtime, string);
368 string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
370 string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
372 string += _appendParam(RTYPE, PARAM_RTYPE, args, getRtype, string);
374 string += _appendParam(ITEMFORM, PARAM_ITEMFORM, args, getItemForm, string);
376 string += _appendParam(ITEMTYPE, PARAM_ITEMTYPE, args, getItemType, string);
378 string += _appendParam(BIBLEVEL, PARAM_BIBLEVEL, args, getBibLevel, string);
380 string += _appendParam(LITFORM, PARAM_LITFORM, args, getLitForm, string);
382 string += _appendParam(AUDIENCE, PARAM_AUDIENCE, args, getAudience, string);
384 string += _appendParam(SEARCHES, PARAM_SEARCHES, args, getSearches, string);
386 string += _appendParam(LANGUAGE, PARAM_LANGUAGE, args, getLanguage, string);
387 if(getRdepth() != null)
388 string += _appendParam(RDEPTH, PARAM_RDEPTH, args, getRdepth, string);
389 if(getSort() != null)
390 string += _appendParam(SORT, PARAM_SORT, args, getSort, string);
391 if(getSortDir() != null)
392 string += _appendParam(SORT_DIR, PARAM_SORT_DIR, args, getSortDir, string);
394 string += _appendParam(AVAIL, PARAM_AVAIL, args, getAvail, string);
396 return string.replace(/\&$/,'').replace(/\?\&/,"?");
400 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
404 if( fieldVar != null &&
405 (fieldVar +'' != 'NaN') &&
406 overrideArgs[fieldName] == null &&
408 getFunc()+'' != '' ) {
410 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
416 /* ----------------------------------------------------------------------- */
417 function cleanISBN(isbn) {
419 isbn = isbn.toString().replace(/^\s+/,"");
420 var idx = isbn.indexOf(" ");
421 if(idx > -1) { isbn = isbn.substring(0, idx); }
427 /* builds a link that goes to the title listings for a metarecord */
428 function buildTitleLink(rec, link) {
430 link.appendChild(text(normalize(truncate(rec.title(), 65))));
433 args[PARAM_OFFSET] = 0;
434 args[PARAM_MRID] = rec.doc_id();
435 args[PARAM_RTYPE] = RTYPE_MRID;
436 link.setAttribute("href", buildOPACLink(args));
439 function buildTitleDetailLink(rec, link) {
441 link.appendChild(text(normalize(truncate(rec.title(), 65))));
444 //args[PARAM_OFFSET] = 0;
445 args[PARAM_RID] = rec.doc_id();
446 link.setAttribute("href", buildOPACLink(args));
449 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
450 'trunc' is the number of characters to show in the string, defaults to 65 */
451 function buildSearchLink(type, string, linknode, trunc) {
452 if(!trunc) trunc = 65;
454 if( SHOW_MR_DEFAULT) {
458 args[PARAM_RTYPE] = type;
460 args[PARAM_OFFSET] = 0;
461 args[PARAM_TERM] = string;
462 args[PARAM_STYPE] = type;
463 linknode.appendChild(text(normalize(truncate(string, trunc))));
464 linknode.setAttribute("href", buildOPACLink(args));
467 function setSessionCookie(ses) {
468 cookieManager.write(COOKIE_SES, ses, -1);
473 /* ----------------------------------------------------------------------- */
474 /* user session handling */
475 /* ----------------------------------------------------------------------- */
476 /* session is the login session. If no session is provided, we attempt
477 to find one in the cookies. If 'force' is true we retrieve the
478 user from the server even if there is already a global user present.
479 if ses != G.user.session, we also force a grab */
480 function grabUser(ses, force) {
482 if(!ses && isXUL()) {
483 stash = fetchXULStash();
484 ses = stash.session.key
485 _debug("stash auth token = " + ses);
489 ses = cookieManager.read(COOKIE_SES);
490 /* https cookies don't show up in http servers.. */
493 if(!ses) return false;
496 if(G.user && G.user.session == ses)
499 /* first make sure the session is valid */
500 var request = new Request(FETCH_SESSION, ses, 1 );
501 request.request.alertEvent = false;
503 var user = request.result();
507 return false; /* unable to grab the session */
510 if( !(typeof user == 'object' && user._isfieldmapper) ) {
516 G.user.fleshed = false;
517 G.user.session = ses;
518 setSessionCookie(ses);
521 if(G.user.prefs['opac.hits_per_page'])
522 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
524 if(G.user.prefs[PREF_DEF_FONT])
525 setFontSize(G.user.prefs[PREF_DEF_FONT]);
527 var at = getAuthtime();
528 //if(isXUL()) at = xulG['authtime'];
530 if(at && !isXUL()) new AuthTimer(at).run();
535 /* sets the 'prefs' field of the user object to their preferences
536 and returns the preferences */
537 function grabUserPrefs(user, force) {
538 if(user == null) user = G.user;
539 if(!force && user.prefs) return user.prefs;
540 var req = new Request(FETCH_USER_PREFS, user.session, user.id());
542 user.prefs = req.result();
546 function grabFleshedUser() {
548 if(!G.user || !G.user.session) {
550 if(!G.user || !G.user.session) return null;
553 if(G.user.fleshed) return G.user;
555 var req = new Request(FETCH_FLESHED_USER, G.user.session);
558 G.user = req.result();
560 if(!G.user || G.user.length == 0) {
561 G.user = null; return false;
562 cookieManager.write(COOKIE_SES,"");
565 G.user.session = ses;
566 G.user.fleshed = true;
568 setSessionCookie(ses);
572 function checkUserSkin(new_skin) {
574 return; /* XXX do some debugging with this... */
576 var user_skin = getSkin();
577 var cur_skin = grabSkinFromURL();
579 if(new_skin) user_skin = new_skin;
584 if(grabUserPrefs()) {
585 user_skin = G.user.prefs["opac.skin"];
586 cookieManager.write( COOKIE_SKIN, user_skin, '+1y' );
591 if(!user_skin) return;
593 if( cur_skin != user_skin ) {
594 var url = buildOPACLink();
595 goTo(url.replace(cur_skin, user_skin));
599 function updateUserSetting(setting, value, user) {
600 if(user == null) user = G.user;
603 var req = new Request( UPDATE_USER_PREFS, user.session, a );
608 function commitUserPrefs() {
609 var req = new Request(
610 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
615 function grabSkinFromURL() {
616 var path = findBasePath();
617 path = path.replace("/xml/", "");
619 for( var i = path.length - 1; i >= 0; i-- ) {
620 var ch = path.charAt(i);
626 for( i = skin.length - 1; i >= 0; i--)
627 skin2 += skin.charAt(i);
633 /* returns a fleshed G.user on success, false on failure */
634 function doLogin(suppressEvents) {
638 var uname = G.ui.login.username.value;
639 var passwd = G.ui.login.password.value;
641 var init_request = new Request( LOGIN_INIT, uname );
642 init_request.send(true);
643 var seed = init_request.result();
645 if( ! seed || seed == '0') {
646 alert( "Error Communicating with Authentication Server" );
651 password : hex_md5(seed + hex_md5(passwd)),
653 org : getOrigLocation()
656 r = fetchOrgSettingDefault(globalOrgTree.id(), 'opac.barcode_regex');
657 if(r) REGEX_BARCODE = new RegExp(r);
659 if( uname.match(REGEX_BARCODE) ) args.barcode = uname;
660 else args.username = uname;
662 var auth_request = new Request( LOGIN_COMPLETE, args );
664 auth_request.request.alertEvent = false;
665 auth_request.send(true);
666 var auth_result = auth_request.result();
669 alertId('patron_login_failed');
673 if( checkILSEvent(auth_result) ) {
675 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
676 alertId('patron_inactive_alert');
680 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
681 alertId('patron_card_inactive_alert');
685 if( auth_result.textcode == 'LOGIN_FAILED' ||
686 auth_result.textcode == 'PERM_FAILURE' ) {
687 alertId('patron_login_failed');
693 AUTHTIME = parseInt(auth_result.payload.authtime);
694 var u = grabUser(auth_result.payload.authtoken, true);
695 if(u && ! suppressEvents)
696 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
703 function doLogout(noredirect) {
705 /* cancel everything else */
708 /* be nice and delete the session from the server */
709 if(G.user && G.user.session) {
710 var req = new Request(LOGIN_DELETE, G.user.session);
712 try { req.result(); } catch(E){}
717 /* remove any cached data */
718 //cookieManager.remove(COOKIE_IDS);
719 //cookieManager.remove(COOKIE_SRIDS);
720 cookieManager.remove(COOKIE_RIDS);
721 cookieManager.remove(COOKIE_SES);
722 cookieManager.remove(COOKIE_SKIN);
723 cookieManager.remove(COOKIE_SEARCH);
725 checkUserSkin("default");
730 args[PARAM_TERM] = "";
731 args[PARAM_LOCATION] = getOrigLocation();
732 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation());
737 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
738 if(!nored) goTo(buildOPACLink(args));
742 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
743 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
746 /* ----------------------------------------------------------------------- */
747 /* build the org tree */
748 /* ----------------------------------------------------------------------- */
749 function drawOrgTree() {
750 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
751 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
755 function buildOrgSelector(node) {
756 var tree = new SlimTree(node,'orgTreeSelector');
757 orgTreeSelector = tree;
758 for( var i in orgArraySearcher ) {
759 var node = orgArraySearcher[i];
760 if( node == null ) continue;
761 if(!isXUL() && !isTrue(node.opac_visible())) continue;
762 if(node.parent_ou() == null)
763 tree.addNode(node.id(), -1, node.name(),
764 "javascript:orgSelect(" + node.id() + ");", node.name());
766 tree.addNode(node.id(), node.parent_ou(), node.name(),
767 "javascript:orgSelect(" + node.id() + ");", node.name());
770 hideMe($('org_loading_div'));
771 unHideMe($('org_selector_tip'));
775 function orgSelect(id) {
777 runEvt("common", "locationChanged", id, findOrgDepth(id) );
779 removeChildren(G.ui.common.now_searching);
780 G.ui.common.now_searching.appendChild(text(findOrgUnit(id).name()));
783 function setFontSize(size) {
785 cookieManager.write(COOKIE_FONT, size, '+1y');
788 var resourceFormats = [
791 "sound recording", "software, multimedia",
796 "three dimensional object" ];
799 function modsFormatToMARC(format) {
805 case "sound recording":
807 case "sound recording-nonmusical":
809 case "sound recording-musical":
811 case "software, multimedia":
817 case "mixed material":
819 case "notated music":
821 case "three dimensional object":
828 function MARCFormatToMods(format) {
834 return "moving image";
836 return "sound recording-nonmusical";
838 return "sound recording-musical";
840 return "software, multimedia";
842 return "still image";
845 return "cartographic";
848 return "mixed material";
851 return "notated music";
853 return "three dimensional object";
858 function MARCTypeToFriendly(format) {
859 var words = $('format_words');
862 case 't' : return $n(words, 'at').innerHTML;
864 var node = $n(words,format);
865 if( node ) return node.innerHTML;
870 function setResourcePic( img, resource ) {
871 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
872 img.title = resource;
877 function msg( text ) {
878 try { alert( text ); } catch(e) {}
881 function findRecord(id,type) {
883 for( var i = 0; i != recordsCache.length; i++ ) {
884 var rec = recordsCache[i];
885 if( rec && rec.doc_id() == id ) return rec;
888 var meth = FETCH_RMODS
889 if(type == 'M') meth = FETCH_MRMODS;
890 var req = new Request(meth, id);
891 req.request.alertEvent = false;
893 var res = req.result();
894 if( checkILSEvent(res) ) return null;
898 function Timer(name, node){
903 Timer.prototype.start =
904 function(){_timerRun(this.name);}
905 Timer.prototype.stop =
906 function(){this.done = true;}
907 function _timerRun(tname) {
911 if(_t.count > 100) return;
913 if( (_t.count % 5) == 0 )
915 _t.node.appendChild(text(str));
916 setTimeout("_timerRun('"+tname+"');", 200);
920 function checkILSEvent(obj) {
921 if( obj && obj.ilsevent != null && obj.ilsevent != 0 )
922 return parseInt(obj.ilsevent);
927 function alertILSEvent(evt, msg) {
930 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
932 alert(evt.textcode + '\n' + evt.desc );
937 function AuthTimer(time) {
938 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
940 try {clearTimeout(__authTimer.id)} catch(e){}
944 AuthTimer.prototype.run = function() {
945 this.id = setTimeout('_authTimerAlert()', this.time);
948 function _authTimerAlert() {
949 alert( $('auth_session_expiring').innerHTML );
950 if(!grabUser(null, true)) doLogout();
954 function grabUserByBarcode( authtoken, barcode ) {
955 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
962 goTo(buildOPACLink({page:HOME}));
966 function buildOrgSel(selector, org, offset) {
967 insertSelectorVal( selector, -1,
968 org.name(), org.id(), null, findOrgDepth(org) - offset );
969 for( var c in org.children() )
970 buildOrgSel( selector, org.children()[c], offset);
974 function parseForm(form) {
977 var it = form.replace(/-\w+$/,"");
982 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
986 for( var i = 0; i < it.length; i++ )
987 item_type.push( it.charAt(i) );
992 for( var i = 0; i < itf.length; i++ )
993 item_form.push( itf.charAt(i) );
996 return {item_type: item_type, item_form:item_form};
1000 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
1002 function fetchPermOrgs() {
1003 var a = []; /* why does arguments come accross as an object and not an array? */
1004 for( var i = 0; i < arguments.length; i++ )
1005 a.push(arguments[i])
1007 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
1008 G.user.session, G.user.id(), a );
1010 return preq.result();
1014 function print_tabs(t) {
1016 for (var j = 0; j < t; j++ ) { r = r + " "; }
1019 function formatJSON(s) {
1020 var r = ''; var t = 0;
1022 if (s[i] == '{' || s[i] == '[' ) {
1023 r = r + s[i] + "\n" + print_tabs(++t);
1024 } else if (s[i] == '}' || s[i] == ']') {
1025 t--; r = r + "\n" + print_tabs(t) + s[i];
1026 } else if (s[i] == ',') {
1027 r = r + s[i] + "\n" + print_tabs(t);