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 AUDIENCE = cgi.param(PARAM_AUDIENCE);
152 SEARCHES = cgi.param(PARAM_SEARCHES);
153 LANGUAGE = cgi.param(PARAM_LANGUAGE);
154 TFORM = cgi.param(PARAM_TFORM);
155 RDEPTH = cgi.param(PARAM_RDEPTH);
156 AVAIL = cgi.param(PARAM_AVAIL);
158 /* set up some sane defaults */
159 //if(isNaN(DEPTH)) DEPTH = 0;
160 if(isNaN(RDEPTH)) RDEPTH = 0;
161 if(isNaN(OFFSET)) OFFSET = 0;
162 if(isNaN(COUNT)) COUNT = 10;
163 if(isNaN(HITCOUNT)) HITCOUNT = 0;
164 if(isNaN(MRID)) MRID = 0;
165 if(isNaN(RID)) RID = 0;
166 if(isNaN(ORIGLOC)) ORIGLOC = 0; /* so we know it hasn't been set */
167 if(isNaN(AUTHTIME)) AUTHTIME = 0;
168 if(ADVTERM==null) ADVTERM = "";
169 if(isNaN(AVAIL)) AVAIL = 0;
172 function clearSearchParams() {
198 function initCookies() {
199 FONTSIZE = "regular";
200 var font = cookieManager.read(COOKIE_FONT);
202 if(font) FONTSIZE = font;
203 SKIN = cookieManager.read(COOKIE_SKIN);
204 if(findCurrentPage() == HOME)
205 cookieManager.remove(COOKIE_SEARCH);
210 /* URL param accessors */
211 function getTerm(){return TERM;}
212 function getStype(){return STYPE;}
213 function getLocation(){return LOCATION;}
214 function getDepth(){return DEPTH;}
215 function getForm(){return FORM;}
216 function getTform(){return TFORM;}
217 function getOffset(){return OFFSET;}
218 function getDisplayCount(){return COUNT;}
219 function getHitCount(){return HITCOUNT;}
220 function getMrid(){return MRID;};
221 function getRid(){return RID;};
222 function getOrigLocation(){return ORIGLOC;}
223 function getAuthtime() { return AUTHTIME; }
224 function getSearchBarExtras(){return SBEXTRAS;}
225 function getFontSize(){return FONTSIZE;};
226 function getSkin(){return SKIN;};
227 function getAdvTerm(){return ADVTERM;}
228 function getAdvType(){return ADVTYPE;}
229 function getRtype(){return RTYPE;}
230 function getSort(){return SORT;}
231 function getSortDir(){return SORT_DIR;}
232 function getDebug(){return DEBUG;}
233 function getCallnumber() { return CALLNUM; }
234 function getLitForm() { return LITFORM; }
235 function getItemForm() { return ITEMFORM; }
236 function getItemType() { return ITEMTYPE; }
237 function getAudience() { return AUDIENCE; }
238 function getSearches() { return SEARCHES; }
239 function getLanguage() { return LANGUAGE; }
240 function getRdepth() { return RDEPTH; }
241 function getAvail() { return AVAIL; }
244 function findBasePath() {
245 var path = location.pathname;
246 if(!path.match(/.*\.xml$/)) path += "index.xml";
247 var idx = path.indexOf(config.page[findCurrentPage()]);
248 return path.substring(0, idx);
251 function findBaseURL(ssl) {
252 var path = findBasePath();
253 var proto = (ssl) ? "https:" : "http:";
255 /* strip port numbers. This is necessary for browsers that
256 send an explicit <host>:80, 443 - explicit ports
257 break links that need to change ports (e.g. http -> https) */
258 var h = location.host.replace(/:.*/,'');
260 return proto + "//" + h + path;
264 function buildISBNSrc(isbn) {
265 return "http://" + location.host + "/jackets/" + isbn;
269 function buildImageLink(name, ssl) {
270 return findBaseURL(ssl) + "../../../../images/" + name;
273 function buildExtrasLink(name, ssl) {
274 return findBaseURL(ssl) + "../../../../extras/" + name;
278 function _debug(str) {
279 try { dump('dbg: ' + str + '\n'); } catch(e) {}
281 /* potentially useful, but usually just annoying */
284 if(!consoleService) {
286 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
287 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
288 .getService(Components.interfaces.nsIConsoleService);
294 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
295 consoleService.logStringMessage(str + '\n');
302 function buildOPACLink(args, slim, ssl) {
308 string = findBaseURL(ssl);
309 if(args.page) string += config.page[args.page];
310 else string += config.page[findCurrentPage()];
313 /* this may seem unnecessary.. safety precaution for now */
315 if( args[PARAM_DEPTH] == null )
316 args[PARAM_DEPTH] = getDepth();
321 for( var x in args ) {
323 if(x == "page" || v == null || v == undefined || v+'' == 'NaN' ) continue;
324 if(x == PARAM_OFFSET && v == 0) continue;
325 if(x == PARAM_COUNT && v == 10) continue;
326 if(x == PARAM_FORM && v == 'all' ) continue;
327 if( instanceOf(v, Array) && v.length ) {
328 for( var i = 0; i < v.length; i++ ) {
329 string += "&" + x + "=" + encodeURIComponent(v[i]);
332 string += "&" + x + "=" + encodeURIComponent(v);
337 string += _appendParam(DEBUG, PARAM_DEBUG, args, getDebug, string);
338 if(getOrigLocation() != 1)
339 string += _appendParam(ORIGLOC, PARAM_ORIGLOC, args, getOrigLocation, string);
341 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
343 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
344 if(getLocation() != 1)
345 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
346 if(getDepth() != null)
347 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
348 if(getForm() && (getForm() != 'all') )
349 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
350 if(getTform() && (getTform() != 'all') )
351 string += _appendParam(TFORM, PARAM_TFORM, args, getTform, string);
353 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
354 if(getDisplayCount() != 10)
355 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
357 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
359 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
361 string += _appendParam(RID, PARAM_RID, args, getRid, string);
363 string += _appendParam(AUTHTIME, PARAM_AUTHTIME, args, getAuthtime, string);
365 string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
367 string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
369 string += _appendParam(RTYPE, PARAM_RTYPE, args, getRtype, string);
371 string += _appendParam(ITEMFORM, PARAM_ITEMFORM, args, getItemForm, string);
373 string += _appendParam(ITEMTYPE, PARAM_ITEMTYPE, args, getItemType, string);
375 string += _appendParam(LITFORM, PARAM_LITFORM, args, getLitForm, string);
377 string += _appendParam(AUDIENCE, PARAM_AUDIENCE, args, getAudience, string);
379 string += _appendParam(SEARCHES, PARAM_SEARCHES, args, getSearches, string);
381 string += _appendParam(LANGUAGE, PARAM_LANGUAGE, args, getLanguage, string);
382 if(getRdepth() != null)
383 string += _appendParam(RDEPTH, PARAM_RDEPTH, args, getRdepth, string);
384 if(getSort() != null)
385 string += _appendParam(SORT, PARAM_SORT, args, getSort, string);
386 if(getSortDir() != null)
387 string += _appendParam(SORT_DIR, PARAM_SORT_DIR, args, getSortDir, string);
389 string += _appendParam(AVAIL, PARAM_AVAIL, args, getAvail, string);
391 return string.replace(/\&$/,'').replace(/\?\&/,"?");
395 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
399 if( fieldVar != null &&
400 (fieldVar +'' != 'NaN') &&
401 overrideArgs[fieldName] == null &&
403 getFunc()+'' != '' ) {
405 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
411 /* ----------------------------------------------------------------------- */
412 function cleanISBN(isbn) {
414 isbn = isbn.toString().replace(/^\s+/,"");
415 var idx = isbn.indexOf(" ");
416 if(idx > -1) { isbn = isbn.substring(0, idx); }
422 /* builds a link that goes to the title listings for a metarecord */
423 function buildTitleLink(rec, link) {
425 link.appendChild(text(normalize(truncate(rec.title(), 65))));
428 args[PARAM_OFFSET] = 0;
429 args[PARAM_MRID] = rec.doc_id();
430 args[PARAM_RTYPE] = RTYPE_MRID;
431 link.setAttribute("href", buildOPACLink(args));
434 function buildTitleDetailLink(rec, link) {
436 link.appendChild(text(normalize(truncate(rec.title(), 65))));
439 //args[PARAM_OFFSET] = 0;
440 args[PARAM_RID] = rec.doc_id();
441 link.setAttribute("href", buildOPACLink(args));
444 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
445 'trunc' is the number of characters to show in the string, defaults to 65 */
446 function buildSearchLink(type, string, linknode, trunc) {
447 if(!trunc) trunc = 65;
449 if( SHOW_MR_DEFAULT) {
453 args[PARAM_RTYPE] = type;
455 args[PARAM_OFFSET] = 0;
456 args[PARAM_TERM] = string;
457 args[PARAM_STYPE] = type;
458 linknode.appendChild(text(normalize(truncate(string, trunc))));
459 linknode.setAttribute("href", buildOPACLink(args));
462 function setSessionCookie(ses) {
463 cookieManager.write(COOKIE_SES, ses, -1);
468 /* ----------------------------------------------------------------------- */
469 /* user session handling */
470 /* ----------------------------------------------------------------------- */
471 /* session is the login session. If no session is provided, we attempt
472 to find one in the cookies. If 'force' is true we retrieve the
473 user from the server even if there is already a global user present.
474 if ses != G.user.session, we also force a grab */
475 function grabUser(ses, force) {
477 if(!ses && isXUL()) {
478 stash = fetchXULStash();
479 ses = stash.session.key
480 _debug("stash auth token = " + ses);
484 ses = cookieManager.read(COOKIE_SES);
485 /* https cookies don't show up in http servers.. */
488 if(!ses) return false;
491 if(G.user && G.user.session == ses)
494 /* first make sure the session is valid */
495 var request = new Request(FETCH_SESSION, ses, 1 );
496 request.request.alertEvent = false;
498 var user = request.result();
502 return false; /* unable to grab the session */
505 if( !(typeof user == 'object' && user._isfieldmapper) ) {
511 G.user.fleshed = false;
512 G.user.session = ses;
513 setSessionCookie(ses);
516 if(G.user.prefs['opac.hits_per_page'])
517 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
519 if(G.user.prefs[PREF_DEF_FONT])
520 setFontSize(G.user.prefs[PREF_DEF_FONT]);
522 var at = getAuthtime();
523 //if(isXUL()) at = xulG['authtime'];
525 if(at && !isXUL()) new AuthTimer(at).run();
530 /* sets the 'prefs' field of the user object to their preferences
531 and returns the preferences */
532 function grabUserPrefs(user, force) {
533 if(user == null) user = G.user;
534 if(!force && user.prefs) return user.prefs;
535 var req = new Request(FETCH_USER_PREFS, user.session, user.id());
537 user.prefs = req.result();
541 function grabFleshedUser() {
543 if(!G.user || !G.user.session) {
545 if(!G.user || !G.user.session) return null;
548 if(G.user.fleshed) return G.user;
550 var req = new Request(FETCH_FLESHED_USER, G.user.session);
553 G.user = req.result();
555 if(!G.user || G.user.length == 0) {
556 G.user = null; return false;
557 cookieManager.write(COOKIE_SES,"");
560 G.user.session = ses;
561 G.user.fleshed = true;
563 setSessionCookie(ses);
567 function checkUserSkin(new_skin) {
569 return; /* XXX do some debugging with this... */
571 var user_skin = getSkin();
572 var cur_skin = grabSkinFromURL();
574 if(new_skin) user_skin = new_skin;
579 if(grabUserPrefs()) {
580 user_skin = G.user.prefs["opac.skin"];
581 cookieManager.write( COOKIE_SKIN, user_skin, '+1y' );
586 if(!user_skin) return;
588 if( cur_skin != user_skin ) {
589 var url = buildOPACLink();
590 goTo(url.replace(cur_skin, user_skin));
594 function updateUserSetting(setting, value, user) {
595 if(user == null) user = G.user;
598 var req = new Request( UPDATE_USER_PREFS, user.session, a );
603 function commitUserPrefs() {
604 var req = new Request(
605 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
610 function grabSkinFromURL() {
611 var path = findBasePath();
612 path = path.replace("/xml/", "");
614 for( var i = path.length - 1; i >= 0; i-- ) {
615 var ch = path.charAt(i);
621 for( i = skin.length - 1; i >= 0; i--)
622 skin2 += skin.charAt(i);
628 /* returns a fleshed G.user on success, false on failure */
629 function doLogin(suppressEvents) {
633 var uname = G.ui.login.username.value;
634 var passwd = G.ui.login.password.value;
636 var init_request = new Request( LOGIN_INIT, uname );
637 init_request.send(true);
638 var seed = init_request.result();
640 if( ! seed || seed == '0') {
641 alert( "Error Communicating with Authentication Server" );
646 password : hex_md5(seed + hex_md5(passwd)),
648 org : getOrigLocation()
651 r = fetchOrgSettingDefault(globalOrgTree.id(), 'opac.barcode_regex');
652 if(r) REGEX_BARCODE = new RegExp(r);
654 if( uname.match(REGEX_BARCODE) ) args.barcode = uname;
655 else args.username = uname;
657 var auth_request = new Request( LOGIN_COMPLETE, args );
659 auth_request.request.alertEvent = false;
660 auth_request.send(true);
661 var auth_result = auth_request.result();
664 alertId('patron_login_failed');
668 if( checkILSEvent(auth_result) ) {
670 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
671 alertId('patron_inactive_alert');
675 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
676 alertId('patron_card_inactive_alert');
680 if( auth_result.textcode == 'LOGIN_FAILED' ||
681 auth_result.textcode == 'PERM_FAILURE' ) {
682 alertId('patron_login_failed');
688 AUTHTIME = parseInt(auth_result.payload.authtime);
689 var u = grabUser(auth_result.payload.authtoken, true);
690 if(u && ! suppressEvents)
691 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
698 function doLogout(noredirect) {
700 /* cancel everything else */
703 /* be nice and delete the session from the server */
704 if(G.user && G.user.session) {
705 var req = new Request(LOGIN_DELETE, G.user.session);
707 try { req.result(); } catch(E){}
712 /* remove any cached data */
713 //cookieManager.remove(COOKIE_IDS);
714 //cookieManager.remove(COOKIE_SRIDS);
715 cookieManager.remove(COOKIE_RIDS);
716 cookieManager.remove(COOKIE_SES);
717 cookieManager.remove(COOKIE_SKIN);
718 cookieManager.remove(COOKIE_SEARCH);
720 checkUserSkin("default");
725 args[PARAM_TERM] = "";
726 args[PARAM_LOCATION] = getOrigLocation();
727 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation());
732 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
733 if(!nored) goTo(buildOPACLink(args));
737 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
738 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
741 /* ----------------------------------------------------------------------- */
742 /* build the org tree */
743 /* ----------------------------------------------------------------------- */
744 function drawOrgTree() {
745 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
746 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
750 function buildOrgSelector(node) {
751 var tree = new SlimTree(node,'orgTreeSelector');
752 orgTreeSelector = tree;
753 for( var i in orgArraySearcher ) {
754 var node = orgArraySearcher[i];
755 if( node == null ) continue;
756 if(!isXUL() && !isTrue(node.opac_visible())) continue;
757 if(node.parent_ou() == null)
758 tree.addNode(node.id(), -1, node.name(),
759 "javascript:orgSelect(" + node.id() + ");", node.name());
761 tree.addNode(node.id(), node.parent_ou(), node.name(),
762 "javascript:orgSelect(" + node.id() + ");", node.name());
765 hideMe($('org_loading_div'));
766 unHideMe($('org_selector_tip'));
770 function orgSelect(id) {
772 runEvt("common", "locationChanged", id, findOrgDepth(id) );
774 removeChildren(G.ui.common.now_searching);
775 G.ui.common.now_searching.appendChild(text(findOrgUnit(id).name()));
778 function setFontSize(size) {
780 cookieManager.write(COOKIE_FONT, size, '+1y');
783 var resourceFormats = [
786 "sound recording", "software, multimedia",
791 "three dimensional object" ];
794 function modsFormatToMARC(format) {
800 case "sound recording":
802 case "sound recording-nonmusical":
804 case "sound recording-musical":
806 case "software, multimedia":
812 case "mixed material":
814 case "notated music":
816 case "three dimensional object":
823 function MARCFormatToMods(format) {
829 return "moving image";
831 return "sound recording-nonmusical";
833 return "sound recording-musical";
835 return "software, multimedia";
837 return "still image";
840 return "cartographic";
843 return "mixed material";
846 return "notated music";
848 return "three dimensional object";
853 function MARCTypeToFriendly(format) {
854 var words = $('format_words');
857 case 't' : return $n(words, 'at').innerHTML;
859 var node = $n(words,format);
860 if( node ) return node.innerHTML;
865 function setResourcePic( img, resource ) {
866 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
867 img.title = resource;
872 function msg( text ) {
873 try { alert( text ); } catch(e) {}
876 function findRecord(id,type) {
878 for( var i = 0; i != recordsCache.length; i++ ) {
879 var rec = recordsCache[i];
880 if( rec && rec.doc_id() == id ) return rec;
883 var meth = FETCH_RMODS
884 if(type == 'M') meth = FETCH_MRMODS;
885 var req = new Request(meth, id);
886 req.request.alertEvent = false;
888 var res = req.result();
889 if( checkILSEvent(res) ) return null;
893 function Timer(name, node){
898 Timer.prototype.start =
899 function(){_timerRun(this.name);}
900 Timer.prototype.stop =
901 function(){this.done = true;}
902 function _timerRun(tname) {
906 if(_t.count > 100) return;
908 if( (_t.count % 5) == 0 )
910 _t.node.appendChild(text(str));
911 setTimeout("_timerRun('"+tname+"');", 200);
915 function checkILSEvent(obj) {
916 if( obj && obj.ilsevent != null && obj.ilsevent != 0 )
917 return parseInt(obj.ilsevent);
922 function alertILSEvent(evt, msg) {
925 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
927 alert(evt.textcode + '\n' + evt.desc );
932 function AuthTimer(time) {
933 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
935 try {clearTimeout(__authTimer.id)} catch(e){}
939 AuthTimer.prototype.run = function() {
940 this.id = setTimeout('_authTimerAlert()', this.time);
943 function _authTimerAlert() {
944 alert( $('auth_session_expiring').innerHTML );
945 if(!grabUser(null, true)) doLogout();
949 function grabUserByBarcode( authtoken, barcode ) {
950 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
957 goTo(buildOPACLink({page:HOME}));
961 function buildOrgSel(selector, org, offset) {
962 insertSelectorVal( selector, -1,
963 org.name(), org.id(), null, findOrgDepth(org) - offset );
964 for( var c in org.children() )
965 buildOrgSel( selector, org.children()[c], offset);
969 function parseForm(form) {
972 var it = form.replace(/-\w+$/,"");
977 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
981 for( var i = 0; i < it.length; i++ )
982 item_type.push( it.charAt(i) );
987 for( var i = 0; i < itf.length; i++ )
988 item_form.push( itf.charAt(i) );
991 return {item_type: item_type, item_form:item_form};
995 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
997 function fetchPermOrgs() {
998 var a = []; /* why does arguments come accross as an object and not an array? */
999 for( var i = 0; i < arguments.length; i++ )
1000 a.push(arguments[i])
1002 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
1003 G.user.session, G.user.id(), a );
1005 return preq.result();
1009 function print_tabs(t) {
1011 for (var j = 0; j < t; j++ ) { r = r + " "; }
1014 function formatJSON(s) {
1015 var r = ''; var t = 0;
1017 if (s[i] == '{' || s[i] == '[' ) {
1018 r = r + s[i] + "\n" + print_tabs(++t);
1019 } else if (s[i] == '}' || s[i] == ']') {
1020 t--; r = r + "\n" + print_tabs(t) + s[i];
1021 } else if (s[i] == ',') {
1022 r = r + s[i] + "\n" + print_tabs(t);