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);
206 /* URL param accessors */
207 function getTerm(){return TERM;}
208 function getStype(){return STYPE;}
209 function getLocation(){return LOCATION;}
210 function getDepth(){return DEPTH;}
211 function getForm(){return FORM;}
212 function getTform(){return TFORM;}
213 function getOffset(){return OFFSET;}
214 function getDisplayCount(){return COUNT;}
215 function getHitCount(){return HITCOUNT;}
216 function getMrid(){return MRID;};
217 function getRid(){return RID;};
218 function getOrigLocation(){return ORIGLOC;}
219 function getAuthtime() { return AUTHTIME; }
220 function getSearchBarExtras(){return SBEXTRAS;}
221 function getFontSize(){return FONTSIZE;};
222 function getSkin(){return SKIN;};
223 function getAdvTerm(){return ADVTERM;}
224 function getAdvType(){return ADVTYPE;}
225 function getRtype(){return RTYPE;}
226 function getSort(){return SORT;}
227 function getSortDir(){return SORT_DIR;}
228 function getDebug(){return DEBUG;}
229 function getCallnumber() { return CALLNUM; }
230 function getLitForm() { return LITFORM; }
231 function getItemForm() { return ITEMFORM; }
232 function getItemType() { return ITEMTYPE; }
233 function getAudience() { return AUDIENCE; }
234 function getSearches() { return SEARCHES; }
235 function getLanguage() { return LANGUAGE; }
236 function getRdepth() { return RDEPTH; }
237 function getAvail() { return AVAIL; }
240 function findBasePath() {
241 var path = location.pathname;
242 if(!path.match(/.*\.xml$/)) path += "index.xml";
243 var idx = path.indexOf(config.page[findCurrentPage()]);
244 return path.substring(0, idx);
247 function findBaseURL(ssl) {
248 var path = findBasePath();
249 var proto = (ssl) ? "https:" : "http:";
251 /* strip port numbers. This is necessary for browsers that
252 send an explicit <host>:80, 443 - explicit ports
253 break links that need to change ports (e.g. http -> https) */
254 var h = location.host.replace(/:.*/,'');
256 return proto + "//" + h + path;
260 function buildISBNSrc(isbn) {
261 return "http://" + location.host + "/jackets/" + isbn;
265 function buildImageLink(name, ssl) {
266 return findBaseURL(ssl) + "../../../../images/" + name;
269 function buildExtrasLink(name, ssl) {
270 return findBaseURL(ssl) + "../../../../extras/" + name;
274 function _debug(str) {
275 try { dump('dbg: ' + str + '\n'); } catch(e) {}
277 /* potentially useful, but usually just annoying */
280 if(!consoleService) {
282 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
283 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
284 .getService(Components.interfaces.nsIConsoleService);
290 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
291 consoleService.logStringMessage(str + '\n');
298 function buildOPACLink(args, slim, ssl) {
304 string = findBaseURL(ssl);
305 if(args.page) string += config.page[args.page];
306 else string += config.page[findCurrentPage()];
309 /* this may seem unnecessary.. safety precaution for now */
311 if( args[PARAM_DEPTH] == null )
312 args[PARAM_DEPTH] = getDepth();
317 for( var x in args ) {
319 if(x == "page" || v == null || v == undefined || v+'' == 'NaN' ) continue;
320 if(x == PARAM_OFFSET && v == 0) continue;
321 if(x == PARAM_COUNT && v == 10) continue;
322 if(x == PARAM_FORM && v == 'all' ) continue;
323 if( instanceOf(v, Array) && v.length ) {
324 for( var i = 0; i < v.length; i++ ) {
325 string += "&" + x + "=" + encodeURIComponent(v[i]);
328 string += "&" + x + "=" + encodeURIComponent(v);
333 string += _appendParam(DEBUG, PARAM_DEBUG, args, getDebug, string);
334 if(getOrigLocation() != 1)
335 string += _appendParam(ORIGLOC, PARAM_ORIGLOC, args, getOrigLocation, string);
337 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
339 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
340 if(getLocation() != 1)
341 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
342 if(getDepth() != null)
343 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
344 if(getForm() && (getForm() != 'all') )
345 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
346 if(getTform() && (getTform() != 'all') )
347 string += _appendParam(TFORM, PARAM_TFORM, args, getTform, string);
349 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
350 if(getDisplayCount() != 10)
351 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
353 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
355 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
357 string += _appendParam(RID, PARAM_RID, args, getRid, string);
359 string += _appendParam(AUTHTIME, PARAM_AUTHTIME, args, getAuthtime, string);
361 string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
363 string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
365 string += _appendParam(RTYPE, PARAM_RTYPE, args, getRtype, string);
367 string += _appendParam(ITEMFORM, PARAM_ITEMFORM, args, getItemForm, string);
369 string += _appendParam(ITEMTYPE, PARAM_ITEMTYPE, args, getItemType, string);
371 string += _appendParam(LITFORM, PARAM_LITFORM, args, getLitForm, string);
373 string += _appendParam(AUDIENCE, PARAM_AUDIENCE, args, getAudience, string);
375 string += _appendParam(SEARCHES, PARAM_SEARCHES, args, getSearches, string);
377 string += _appendParam(LANGUAGE, PARAM_LANGUAGE, args, getLanguage, string);
378 if(getRdepth() != null)
379 string += _appendParam(RDEPTH, PARAM_RDEPTH, args, getRdepth, string);
380 if(getSort() != null)
381 string += _appendParam(SORT, PARAM_SORT, args, getSort, string);
382 if(getSortDir() != null)
383 string += _appendParam(SORT_DIR, PARAM_SORT_DIR, args, getSortDir, string);
385 string += _appendParam(AVAIL, PARAM_AVAIL, args, getAvail, string);
387 return string.replace(/\&$/,'').replace(/\?\&/,"?");
391 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
395 if( fieldVar != null &&
396 (fieldVar +'' != 'NaN') &&
397 overrideArgs[fieldName] == null &&
399 getFunc()+'' != '' ) {
401 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
407 /* ----------------------------------------------------------------------- */
408 function cleanISBN(isbn) {
410 isbn = isbn.toString().replace(/^\s+/,"");
411 var idx = isbn.indexOf(" ");
412 if(idx > -1) { isbn = isbn.substring(0, idx); }
418 /* builds a link that goes to the title listings for a metarecord */
419 function buildTitleLink(rec, link) {
421 link.appendChild(text(normalize(truncate(rec.title(), 65))));
424 args[PARAM_OFFSET] = 0;
425 args[PARAM_MRID] = rec.doc_id();
426 args[PARAM_RTYPE] = RTYPE_MRID;
427 link.setAttribute("href", buildOPACLink(args));
430 function buildTitleDetailLink(rec, link) {
432 link.appendChild(text(normalize(truncate(rec.title(), 65))));
435 //args[PARAM_OFFSET] = 0;
436 args[PARAM_RID] = rec.doc_id();
437 link.setAttribute("href", buildOPACLink(args));
440 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
441 'trunc' is the number of characters to show in the string, defaults to 65 */
442 function buildSearchLink(type, string, linknode, trunc) {
443 if(!trunc) trunc = 65;
445 if( SHOW_MR_DEFAULT) {
449 args[PARAM_RTYPE] = type;
451 args[PARAM_OFFSET] = 0;
452 args[PARAM_TERM] = string;
453 args[PARAM_STYPE] = type;
454 linknode.appendChild(text(normalize(truncate(string, trunc))));
455 linknode.setAttribute("href", buildOPACLink(args));
458 function setSessionCookie(ses) {
459 cookieManager.write(COOKIE_SES, ses, -1);
464 /* ----------------------------------------------------------------------- */
465 /* user session handling */
466 /* ----------------------------------------------------------------------- */
467 /* session is the login session. If no session is provided, we attempt
468 to find one in the cookies. If 'force' is true we retrieve the
469 user from the server even if there is already a global user present.
470 if ses != G.user.session, we also force a grab */
471 function grabUser(ses, force) {
473 if(!ses && isXUL()) {
474 stash = fetchXULStash();
475 ses = stash.session.key
476 _debug("stash auth token = " + ses);
480 ses = cookieManager.read(COOKIE_SES);
481 /* https cookies don't show up in http servers.. */
484 if(!ses) return false;
487 if(G.user && G.user.session == ses)
490 /* first make sure the session is valid */
491 var request = new Request(FETCH_SESSION, ses, 1 );
492 request.request.alertEvent = false;
494 var user = request.result();
498 return false; /* unable to grab the session */
501 if( !(typeof user == 'object' && user._isfieldmapper) ) {
507 G.user.fleshed = false;
508 G.user.session = ses;
509 setSessionCookie(ses);
512 if(G.user.prefs['opac.hits_per_page'])
513 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
515 if(G.user.prefs[PREF_DEF_FONT])
516 setFontSize(G.user.prefs[PREF_DEF_FONT]);
518 var at = getAuthtime();
519 //if(isXUL()) at = xulG['authtime'];
521 if(at && !isXUL()) new AuthTimer(at).run();
526 /* sets the 'prefs' field of the user object to their preferences
527 and returns the preferences */
528 function grabUserPrefs(user, force) {
529 if(user == null) user = G.user;
530 if(!force && user.prefs) return user.prefs;
531 var req = new Request(FETCH_USER_PREFS, user.session, user.id());
533 user.prefs = req.result();
537 function grabFleshedUser() {
539 if(!G.user || !G.user.session) {
541 if(!G.user || !G.user.session) return null;
544 if(G.user.fleshed) return G.user;
546 var req = new Request(FETCH_FLESHED_USER, G.user.session);
549 G.user = req.result();
551 if(!G.user || G.user.length == 0) {
552 G.user = null; return false;
553 cookieManager.write(COOKIE_SES,"");
556 G.user.session = ses;
557 G.user.fleshed = true;
559 setSessionCookie(ses);
563 function checkUserSkin(new_skin) {
565 return; /* XXX do some debugging with this... */
567 var user_skin = getSkin();
568 var cur_skin = grabSkinFromURL();
570 if(new_skin) user_skin = new_skin;
575 if(grabUserPrefs()) {
576 user_skin = G.user.prefs["opac.skin"];
577 cookieManager.write( COOKIE_SKIN, user_skin, '+1y' );
582 if(!user_skin) return;
584 if( cur_skin != user_skin ) {
585 var url = buildOPACLink();
586 goTo(url.replace(cur_skin, user_skin));
590 function updateUserSetting(setting, value, user) {
591 if(user == null) user = G.user;
594 var req = new Request( UPDATE_USER_PREFS, user.session, a );
599 function commitUserPrefs() {
600 var req = new Request(
601 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
606 function grabSkinFromURL() {
607 var path = findBasePath();
608 path = path.replace("/xml/", "");
610 for( var i = path.length - 1; i >= 0; i-- ) {
611 var ch = path.charAt(i);
617 for( i = skin.length - 1; i >= 0; i--)
618 skin2 += skin.charAt(i);
624 /* returns a fleshed G.user on success, false on failure */
625 function doLogin(suppressEvents) {
629 var uname = G.ui.login.username.value;
630 var passwd = G.ui.login.password.value;
632 var init_request = new Request( LOGIN_INIT, uname );
633 init_request.send(true);
634 var seed = init_request.result();
636 if( ! seed || seed == '0') {
637 alert( "Error Communicating with Authentication Server" );
642 password : hex_md5(seed + hex_md5(passwd)),
644 org : getOrigLocation()
647 if( uname.match(REGEX_BARCODE) ) args.barcode = uname; /* make this better */
648 else args.username = uname;
650 var auth_request = new Request( LOGIN_COMPLETE, args );
652 auth_request.request.alertEvent = false;
653 auth_request.send(true);
654 var auth_result = auth_request.result();
657 alertId('patron_login_failed');
661 if( checkILSEvent(auth_result) ) {
663 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
664 alertId('patron_inactive_alert');
668 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
669 alertId('patron_card_inactive_alert');
673 if( auth_result.textcode == 'LOGIN_FAILED' ||
674 auth_result.textcode == 'PERM_FAILURE' ) {
675 alertId('patron_login_failed');
681 AUTHTIME = parseInt(auth_result.payload.authtime);
682 var u = grabUser(auth_result.payload.authtoken, true);
683 if(u && ! suppressEvents)
684 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
691 function doLogout(noredirect) {
693 /* cancel everything else */
696 /* be nice and delete the session from the server */
697 if(G.user && G.user.session) {
698 var req = new Request(LOGIN_DELETE, G.user.session);
700 try { req.result(); } catch(E){}
705 /* remove any cached data */
706 //cookieManager.remove(COOKIE_IDS);
707 //cookieManager.remove(COOKIE_SRIDS);
708 cookieManager.remove(COOKIE_RIDS);
709 cookieManager.remove(COOKIE_SES);
710 cookieManager.remove(COOKIE_SKIN);
712 checkUserSkin("default");
717 args[PARAM_TERM] = "";
718 args[PARAM_LOCATION] = getOrigLocation();
719 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation());
724 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
725 if(!nored) goTo(buildOPACLink(args));
729 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
730 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
733 /* ----------------------------------------------------------------------- */
734 /* build the org tree */
735 /* ----------------------------------------------------------------------- */
736 function drawOrgTree() {
737 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
738 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
742 function buildOrgSelector(node) {
743 var tree = new SlimTree(node,'orgTreeSelector');
744 orgTreeSelector = tree;
745 for( var i in orgArraySearcher ) {
746 var node = orgArraySearcher[i];
747 if( node == null ) continue;
748 if(!isXUL() && !isTrue(node.opac_visible())) continue;
749 if(node.parent_ou() == null)
750 tree.addNode(node.id(), -1, node.name(),
751 "javascript:orgSelect(" + node.id() + ");", node.name());
753 tree.addNode(node.id(), node.parent_ou(), node.name(),
754 "javascript:orgSelect(" + node.id() + ");", node.name());
757 hideMe($('org_loading_div'));
758 unHideMe($('org_selector_tip'));
762 function orgSelect(id) {
764 runEvt("common", "locationChanged", id, findOrgDepth(id) );
766 removeChildren(G.ui.common.now_searching);
767 G.ui.common.now_searching.appendChild(text(findOrgUnit(id).name()));
770 function setFontSize(size) {
772 cookieManager.write(COOKIE_FONT, size, '+1y');
775 var resourceFormats = [
778 "sound recording", "software, multimedia",
783 "three dimensional object" ];
786 function modsFormatToMARC(format) {
792 case "sound recording":
794 case "sound recording-nonmusical":
796 case "sound recording-musical":
798 case "software, multimedia":
804 case "mixed material":
806 case "notated music":
808 case "three dimensional object":
815 function MARCFormatToMods(format) {
821 return "moving image";
823 return "sound recording-nonmusical";
825 return "sound recording-musical";
827 return "software, multimedia";
829 return "still image";
832 return "cartographic";
835 return "mixed material";
838 return "notated music";
840 return "three dimensional object";
845 function MARCTypeToFriendly(format) {
846 var words = $('format_words');
849 case 't' : return $n(words, 'at').innerHTML;
851 var node = $n(words,format);
852 if( node ) return node.innerHTML;
857 function setResourcePic( img, resource ) {
858 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
859 img.title = resource;
864 function msg( text ) {
865 try { alert( text ); } catch(e) {}
868 function findRecord(id,type) {
870 for( var i = 0; i != recordsCache.length; i++ ) {
871 var rec = recordsCache[i];
872 if( rec && rec.doc_id() == id ) return rec;
875 var meth = FETCH_RMODS
876 if(type == 'M') meth = FETCH_MRMODS;
877 var req = new Request(meth, id);
878 req.request.alertEvent = false;
880 var res = req.result();
881 if( checkILSEvent(res) ) return null;
885 function Timer(name, node){
890 Timer.prototype.start =
891 function(){_timerRun(this.name);}
892 Timer.prototype.stop =
893 function(){this.done = true;}
894 function _timerRun(tname) {
898 if(_t.count > 100) return;
900 if( (_t.count % 5) == 0 )
902 _t.node.appendChild(text(str));
903 setTimeout("_timerRun('"+tname+"');", 200);
907 function checkILSEvent(obj) {
908 if( obj && obj.ilsevent != null && obj.ilsevent != 0 )
909 return parseInt(obj.ilsevent);
914 function alertILSEvent(evt, msg) {
917 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
919 alert(evt.textcode + '\n' + evt.desc );
924 function AuthTimer(time) {
925 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
927 try {clearTimeout(__authTimer.id)} catch(e){}
931 AuthTimer.prototype.run = function() {
932 this.id = setTimeout('_authTimerAlert()', this.time);
935 function _authTimerAlert() {
936 alert( $('auth_session_expiring').innerHTML );
937 if(!grabUser(null, true)) doLogout();
941 function grabUserByBarcode( authtoken, barcode ) {
942 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
949 goTo(buildOPACLink({page:HOME}));
953 function buildOrgSel(selector, org, offset) {
954 insertSelectorVal( selector, -1,
955 org.name(), org.id(), null, findOrgDepth(org) - offset );
956 for( var c in org.children() )
957 buildOrgSel( selector, org.children()[c], offset);
961 function parseForm(form) {
964 var it = form.replace(/-\w+$/,"");
969 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
973 for( var i = 0; i < it.length; i++ )
974 item_type.push( it.charAt(i) );
979 for( var i = 0; i < itf.length; i++ )
980 item_form.push( itf.charAt(i) );
983 return {item_type: item_type, item_form:item_form};
987 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
989 function fetchPermOrgs() {
990 var a = []; /* why does arguments come accross as an object and not an array? */
991 for( var i = 0; i < arguments.length; i++ )
994 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
995 G.user.session, G.user.id(), a );
997 return preq.result();
1001 function print_tabs(t) {
1003 for (var j = 0; j < t; j++ ) { r = r + " "; }
1006 function formatJSON(s) {
1007 var r = ''; var t = 0;
1009 if (s[i] == '{' || s[i] == '[' ) {
1010 r = r + s[i] + "\n" + print_tabs(++t);
1011 } else if (s[i] == '}' || s[i] == ']') {
1012 t--; r = r + "\n" + print_tabs(t) + s[i];
1013 } else if (s[i] == ',') {
1014 r = r + s[i] + "\n" + print_tabs(t);