1 /* - Request ------------------------------------------------------------- */
4 /* define it again here for pages that don't load RemoteRequest */
6 if(location.protocol == 'chrome:' || location.protocol == 'oils:') return true;
7 try { if(IAMXUL) return true;}catch(e){return false;};
11 var __ilsEvent; /* the last event the occurred */
14 function Request(type) {
16 var s = type.split(":");
17 if(s[2] == "1" && isXUL()) s[1] += ".staff";
18 this.request = new RemoteRequest(s[0], s[1]);
22 if(!location.href.match(/^https:/) && !location.href.match(/^oils:/))
23 this.request.setSecure(false);
27 if( G.user && G.user.session ) {
28 /* if the user is logged in, all activity resets the timeout
29 This is not entirely accurate in the sense that not all
30 requests will reset the server timeout - this should
31 get close enough, however.
33 var at = getAuthtime();
34 if(at) new AuthTimer(at).run();
38 for( var x = 1; x!= arguments.length; x++ ) {
40 this.request.addParam(arguments[x]);
45 for( var i = 0; i != p.length; i++ ) {
46 if( i > 0 ) str += ", "
49 _debug('request ' + s[0] + ' ' + s[1] + ' ' + str );
51 } else if( DEBUGSLIM ) {
52 _debug('request ' + s[1]);
56 Request.prototype.callback = function(cal) {this.request.setCompleteCallback(cal);}
57 Request.prototype.send = function(block){this.request.send(block);}
58 Request.prototype.result = function(){return this.request.getResultObject();}
60 function showCanvas() {
61 for( var x in G.ui.altcanvas ) {
62 hideMe(G.ui.altcanvas[x]);
64 hideMe(G.ui.common.loading);
65 unHideMe(G.ui.common.canvas_main);
66 try{G.ui.searchbar.text.focus();}catch(e){}
69 function swapCanvas(newNode) {
70 for( var x in G.ui.altcanvas )
71 hideMe(G.ui.altcanvas[x]);
73 hideMe(G.ui.common.loading);
74 hideMe(G.ui.common.canvas_main);
78 /* finds the name of the current page */
79 var currentPage = null;
80 function findCurrentPage() {
81 if(currentPage) return currentPage;
84 for( var p in config.page ) pages.push(config.page[p]);
85 pages = pages.sort( function(a,b){ return - (a.length - b.length); } );
87 var path = location.pathname;
88 if(!path.match(/.*\.xml$/))
89 path += "index.xml"; /* in case they go to / */
92 for( var p = 0; p < pages.length; p++ ) {
93 if( path.indexOf(pages[p]) != -1)
97 for( var p in config.page ) {
98 if(config.page[p] == page) {
107 /* sets all of the params values ----------------------------- */
108 function initParams() {
111 /* handle the location var */
113 var loc = cgi.param(PARAM_LOCATION);
114 var lasso = cgi.param(PARAM_LASSO);
117 lasso = findOrgLasso( lasso );
118 LASSO = lasso ? lasso.id() : null;
122 org = findOrgUnit(loc);
123 LOCATION = org ? org.id() : null;
126 org = findOrgUnit(loc);
127 LOCATION = org ? org.id() : null;
132 loc = cgi.param(PARAM_ORIGLOC);
134 org = findOrgUnit(loc);
135 if(!org) org = findOrgUnitSN(loc);
137 ORIGLOC = (org) ? org.id() : null;
140 DEPTH = parseInt(cgi.param(PARAM_DEPTH));
141 if(isNaN(DEPTH)) DEPTH = null;
144 FACET = cgi.param(PARAM_FACET);
145 TERM = cgi.param(PARAM_TERM);
146 STYPE = cgi.param(PARAM_STYPE);
147 FORM = cgi.param(PARAM_FORM);
148 //DEPTH = parseInt(cgi.param(PARAM_DEPTH));
149 OFFSET = parseInt(cgi.param(PARAM_OFFSET));
150 COUNT = parseInt(cgi.param(PARAM_COUNT));
151 HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT));
152 MRID = parseInt(cgi.param(PARAM_MRID));
153 RID = parseInt(cgi.param(PARAM_RID));
154 AUTHTIME = parseInt(cgi.param(PARAM_AUTHTIME));
155 ADVTERM = cgi.param(PARAM_ADVTERM);
156 ADVTYPE = cgi.param(PARAM_ADVTYPE);
157 RTYPE = cgi.param(PARAM_RTYPE);
158 SORT = cgi.param(PARAM_SORT);
159 SORT_DIR = cgi.param(PARAM_SORT_DIR);
160 DEBUG = cgi.param(PARAM_DEBUG);
161 CALLNUM = cgi.param(PARAM_CN);
162 LITFORM = cgi.param(PARAM_LITFORM);
163 ITEMFORM = cgi.param(PARAM_ITEMFORM);
164 ITEMTYPE = cgi.param(PARAM_ITEMTYPE);
165 BIBLEVEL = cgi.param(PARAM_BIBLEVEL);
166 AUDIENCE = cgi.param(PARAM_AUDIENCE);
167 SEARCHES = cgi.param(PARAM_SEARCHES);
168 LANGUAGE = cgi.param(PARAM_LANGUAGE);
169 TFORM = cgi.param(PARAM_TFORM);
170 RDEPTH = cgi.param(PARAM_RDEPTH);
171 AVAIL = cgi.param(PARAM_AVAIL);
172 COPYLOCS = cgi.param(PARAM_COPYLOCS);
173 PUBD_BEFORE = cgi.param(PARAM_PUBD_BEFORE);
174 PUBD_AFTER = cgi.param(PARAM_PUBD_AFTER);
175 PUBD_BETWEEN = cgi.param(PARAM_PUBD_BETWEEN);
176 PUBD_DURING = cgi.param(PARAM_PUBD_DURING);
179 /* set up some sane defaults */
180 //if(isNaN(DEPTH)) DEPTH = 0;
181 if(isNaN(RDEPTH)) RDEPTH = 0;
182 if(isNaN(OFFSET)) OFFSET = 0;
183 if(isNaN(COUNT)) COUNT = 10;
184 if(isNaN(HITCOUNT)) HITCOUNT = 0;
185 if(isNaN(MRID)) MRID = 0;
186 if(isNaN(RID)) RID = 0;
187 if(isNaN(ORIGLOC)) ORIGLOC = 0; /* so we know it hasn't been set */
188 if(isNaN(AUTHTIME)) AUTHTIME = 0;
189 if(ADVTERM==null) ADVTERM = "";
190 if(isNaN(AVAIL)) AVAIL = 0;
193 function clearSearchParams() {
225 function initCookies() {
226 dojo.require('dojo.cookie');
227 FONTSIZE = "regular";
228 var font = dojo.cookie(COOKIE_FONT);
230 if(font) FONTSIZE = font;
231 SKIN = dojo.cookie(COOKIE_SKIN);
232 if(findCurrentPage() == HOME)
233 dojo.cookie(COOKIE_SEARCH,null,{'expires':-1});
236 /* URL param accessors */
237 function getTerm(){return TERM;}
238 function getFacet(){return FACET;}
239 function getStype(){return STYPE;}
240 function getLocation(){return LOCATION;}
241 function getLasso(){return LASSO;}
242 function getDepth(){return DEPTH;}
243 function getForm(){return FORM;}
244 function getTform(){return TFORM;}
245 function getOffset(){return OFFSET;}
246 function getDisplayCount(){return COUNT;}
247 function getHitCount(){return HITCOUNT;}
248 function getMrid(){return MRID;};
249 function getRid(){return RID;};
250 function getOrigLocation(){return ORIGLOC;}
251 function getAuthtime() { return AUTHTIME; }
252 function getSearchBarExtras(){return SBEXTRAS;}
253 function getFontSize(){return FONTSIZE;};
254 function getSkin(){return SKIN;};
255 function getAdvTerm(){return ADVTERM;}
256 function getAdvType(){return ADVTYPE;}
257 function getRtype(){return RTYPE;}
258 function getSort(){return SORT;}
259 function getSortDir(){return SORT_DIR;}
260 function getDebug(){return DEBUG;}
261 function getCallnumber() { return CALLNUM; }
262 function getLitForm() { return LITFORM; }
263 function getItemForm() { return ITEMFORM; }
264 function getItemType() { return ITEMTYPE; }
265 function getBibLevel() { return BIBLEVEL; }
266 function getAudience() { return AUDIENCE; }
267 function getSearches() { return SEARCHES; }
268 function getLanguage() { return LANGUAGE; }
269 function getRdepth() { return RDEPTH; }
270 function getAvail() { return AVAIL; }
271 function getCopyLocs() { return COPYLOCS; }
272 function getPubdBefore() { return PUBD_BEFORE; }
273 function getPubdAfter() { return PUBD_AFTER; }
274 function getPubdBetween() { return PUBD_BETWEEN; }
275 function getPubdDuring() { return PUBD_DURING; }
278 function findBasePath() {
279 var path = location.pathname;
280 if(!path.match(/.*\.xml$/)) path += "index.xml";
281 var idx = path.indexOf(config.page[findCurrentPage()]);
282 return path.substring(0, idx);
285 function findBaseURL(ssl) {
286 var path = findBasePath();
287 var proto = (ssl) ? "https:" : "http:";
288 if(ssl && location.protocol == 'oils:') proto = 'oils:';
290 /* strip port numbers. This is necessary for browsers that
291 send an explicit <host>:80, 443 - explicit ports
292 break links that need to change ports (e.g. http -> https) */
293 var h = location.host.replace(/:.*/,'');
295 return proto + "//" + h + path;
299 function buildISBNSrc(isbn) {
300 return "http://" + location.host + "/jackets/" + isbn;
304 function buildImageLink(name, ssl) {
305 return findBaseURL(ssl) + "../../../../images/" + name;
308 function buildExtrasLink(name, ssl) {
309 return findBaseURL(ssl) + "../../../../extras/" + name;
313 function _debug(str) {
314 try { dump('dbg: ' + str + '\n'); } catch(e) {}
316 /* potentially useful, but usually just annoying */
319 if(!consoleService) {
321 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
322 .getService(Components.interfaces.nsIConsoleService);
328 consoleService.logStringMessage(str + '\n');
335 var forceLoginSSL; // set via Apache env variable
336 function buildOPACLink(args, slim, ssl) {
341 if( ssl == undefined && (
342 location.protocol == 'https:' || location.protocol == 'oils:' ||
343 (forceLoginSSL && G.user && G.user.session))) {
348 string = findBaseURL(ssl);
349 if(args.page) string += config.page[args.page];
350 else string += config.page[findCurrentPage()];
353 /* this may seem unnecessary.. safety precaution for now */
355 if( args[PARAM_DEPTH] == null )
356 args[PARAM_DEPTH] = getDepth();
361 for( var x in args ) {
363 if(x == "page" || v == null || v == undefined || v+'' == 'NaN' ) continue;
364 if(x == PARAM_OFFSET && v == 0) continue;
365 if(x == PARAM_COUNT && v == 10) continue;
366 if(x == PARAM_FORM && v == 'all' ) continue;
367 if( instanceOf(v, Array) && v.length ) {
368 for( var i = 0; i < v.length; i++ ) {
369 string += "&" + x + "=" + encodeURIComponent(v[i]);
372 string += "&" + x + "=" + encodeURIComponent(v);
377 string += _appendParam(DEBUG, PARAM_DEBUG, args, getDebug, string);
378 if(getOrigLocation() != 1)
379 string += _appendParam(ORIGLOC, PARAM_ORIGLOC, args, getOrigLocation, string);
381 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
383 string += _appendParam(FACET, PARAM_FACET, args, getFacet, string);
385 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
386 if(getLocation() != 1)
387 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
388 if(getLasso() != null)
389 string += _appendParam(LASSO, PARAM_LASSO, args, getLasso, string);
390 if(getDepth() != null)
391 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
392 if(getForm() && (getForm() != 'all') )
393 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
394 if(getTform() && (getTform() != 'all') )
395 string += _appendParam(TFORM, PARAM_TFORM, args, getTform, string);
397 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
398 if(getDisplayCount() != 10)
399 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
401 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
403 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
405 string += _appendParam(RID, PARAM_RID, args, getRid, string);
407 string += _appendParam(AUTHTIME, PARAM_AUTHTIME, args, getAuthtime, string);
409 string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
411 string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
413 string += _appendParam(RTYPE, PARAM_RTYPE, args, getRtype, string);
415 string += _appendParam(ITEMFORM, PARAM_ITEMFORM, args, getItemForm, string);
417 string += _appendParam(ITEMTYPE, PARAM_ITEMTYPE, args, getItemType, string);
419 string += _appendParam(BIBLEVEL, PARAM_BIBLEVEL, args, getBibLevel, string);
421 string += _appendParam(LITFORM, PARAM_LITFORM, args, getLitForm, string);
423 string += _appendParam(AUDIENCE, PARAM_AUDIENCE, args, getAudience, string);
425 string += _appendParam(SEARCHES, PARAM_SEARCHES, args, getSearches, string);
427 string += _appendParam(LANGUAGE, PARAM_LANGUAGE, args, getLanguage, string);
428 if(getRdepth() != null)
429 string += _appendParam(RDEPTH, PARAM_RDEPTH, args, getRdepth, string);
430 if(getSort() != null)
431 string += _appendParam(SORT, PARAM_SORT, args, getSort, string);
432 if(getSortDir() != null)
433 string += _appendParam(SORT_DIR, PARAM_SORT_DIR, args, getSortDir, string);
435 string += _appendParam(AVAIL, PARAM_AVAIL, args, getAvail, string);
437 string += _appendParam(COPYLOCS, PARAM_COPYLOCS, args, getCopyLocs, string);
439 string += _appendParam(PUBD_BEFORE, PARAM_PUBD_BEFORE, args, getPubdBefore, string);
441 string += _appendParam(PUBD_AFTER, PARAM_PUBD_AFTER, args, getPubdAfter, string);
443 string += _appendParam(PUBD_BETWEEN, PARAM_PUBD_BETWEEN, args, getPubdBetween, string);
445 string += _appendParam(PUBD_DURING, PARAM_PUBD_DURING, args, getPubdDuring, string);
448 return string.replace(/\&$/,'').replace(/\?\&/,"?");
452 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
456 if( fieldVar != null &&
457 (fieldVar +'' != 'NaN') &&
458 overrideArgs[fieldName] == null &&
460 getFunc()+'' != '' ) {
462 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
468 /* ----------------------------------------------------------------------- */
469 function cleanISBN(isbn) {
471 isbn = isbn.toString().replace(/^\s+/,"");
472 var idx = isbn.indexOf(" ");
473 if(idx > -1) { isbn = isbn.substring(0, idx); }
479 /* builds a link that goes to the title listings for a metarecord */
480 function buildTitleLink(rec, link) {
482 link.appendChild(text(normalize(truncate(rec.title(), 65))));
485 args[PARAM_OFFSET] = 0;
486 args[PARAM_MRID] = rec.doc_id();
487 args[PARAM_RTYPE] = RTYPE_MRID;
488 var linkText = link.innerHTML; // IE
489 link.setAttribute("href", buildOPACLink(args));
490 link.innerHTML = linkText; // IE
493 function buildTitleDetailLink(rec, link) {
495 link.appendChild(text(normalize(truncate(rec.title(), 65))));
498 args[PARAM_RID] = rec.doc_id();
499 // in IE, if the link text contains a '@', it replaces the innerHTML text
500 // with the value of the href attribute. Wait, what? Yes. Capture the
501 // innerHTML and put it back into place after the href is set
502 var linkText = link.innerHTML; // IE
503 link.setAttribute("href", buildOPACLink(args));
504 link.innerHTML = linkText; // IE
507 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
508 'trunc' is the number of characters to show in the string, defaults to 65 */
509 function buildSearchLink(type, string, linknode, trunc) {
510 if(!trunc) trunc = 65;
512 if( SHOW_MR_DEFAULT || findCurrentPage() == MRESULT ) {
516 args[PARAM_RTYPE] = type;
518 args[PARAM_OFFSET] = 0;
519 args[PARAM_TERM] = string;
520 args[PARAM_STYPE] = type;
521 linknode.appendChild(text(normalize(truncate(string, trunc))));
522 linknode.setAttribute("href", buildOPACLink(args));
525 function setSessionCookie(ses) {
526 dojo.cookie(COOKIE_SES, ses, {'secure':'true'});
531 /* ----------------------------------------------------------------------- */
532 /* user session handling */
533 /* ----------------------------------------------------------------------- */
534 /* session is the login session. If no session is provided, we attempt
535 to find one in the cookies. If 'force' is true we retrieve the
536 user from the server even if there is already a global user present.
537 if ses != G.user.session, we also force a grab */
538 function grabUser(ses, force) {
540 _debug("grabUser auth token = " + ses);
541 if(!ses && isXUL()) {
542 stash = fetchXULStash();
543 ses = stash.session.key
544 _debug("stash auth token = " + ses);
548 ses = dojo.cookie(COOKIE_SES);
549 /* https cookies don't show up in http servers.. */
550 _debug("cookie auth token = " + ses);
553 if(!ses) return false;
556 if(G.user && G.user.session == ses)
559 /* first make sure the session is valid */
560 var request = new Request(FETCH_SESSION, ses);
561 request.request.alertEvent = false;
563 var user = request.result();
565 if(!user || user.textcode == 'NO_SESSION') {
568 dojo.require('openils.XUL');
569 dump('getNewSession in opac_utils.js\n');
570 openils.XUL.getNewSession(
571 function(success, authtoken) {
574 var request = new Request(FETCH_SESSION, ses);
575 request.request.alertEvent = false;
577 user = request.result();
583 if(!user || user.textcode == 'NO_SESSION') {
585 return false; /* unable to grab the session */
589 if( !(typeof user == 'object' && user._isfieldmapper) ) {
595 G.user.fleshed = false;
596 G.user.session = ses;
597 setSessionCookie(ses);
600 if(G.user.prefs['opac.hits_per_page'])
601 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
603 if(G.user.prefs[PREF_DEF_FONT])
604 setFontSize(G.user.prefs[PREF_DEF_FONT]);
606 var at = getAuthtime();
607 //if(isXUL()) at = xulG['authtime'];
609 if(at && !isXUL()) new AuthTimer(at).run();
614 /* sets the 'prefs' field of the user object to their preferences
615 and returns the preferences */
616 function grabUserPrefs(user, force) {
617 if(user == null) user = G.user;
618 if(!force && user.prefs) return user.prefs;
619 var req = new Request(FETCH_USER_PREFS, G.user.session, user.id());
621 user.prefs = req.result();
625 function grabFleshedUser() {
627 if(!G.user || !G.user.session) {
629 if(!G.user || !G.user.session) return null;
632 if(G.user.fleshed) return G.user;
634 var req = new Request(FETCH_FLESHED_USER, G.user.session);
637 G.user = req.result();
639 if(!G.user || G.user.length == 0) {
640 dojo.cookie(COOKIE_SES,null,{'expires':-1});
641 G.user = null; return false;
644 G.user.session = ses;
645 G.user.fleshed = true;
647 setSessionCookie(ses);
651 function checkUserSkin(new_skin) {
653 return; /* XXX do some debugging with this... */
655 var user_skin = getSkin();
656 var cur_skin = grabSkinFromURL();
658 if(new_skin) user_skin = new_skin;
663 if(grabUserPrefs()) {
664 user_skin = G.user.prefs["opac.skin"];
665 dojo.cookie( COOKIE_SKIN, user_skin, { 'expires' : 365 } );
670 if(!user_skin) return;
672 if( cur_skin != user_skin ) {
673 var url = buildOPACLink();
674 goTo(url.replace(cur_skin, user_skin));
678 function updateUserSetting(setting, value, user) {
679 if(user == null) user = G.user;
682 var req = new Request( UPDATE_USER_PREFS, user.session, a );
687 function commitUserPrefs() {
688 var req = new Request(
689 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
694 function grabSkinFromURL() {
695 var path = findBasePath();
696 path = path.replace("/xml/", "");
698 for( var i = path.length - 1; i >= 0; i-- ) {
699 var ch = path.charAt(i);
705 for( i = skin.length - 1; i >= 0; i--)
706 skin2 += skin.charAt(i);
712 /* returns a fleshed G.user on success, false on failure */
713 function doLogin(suppressEvents) {
717 var auth_proxy_enabled = false;
718 var auth_proxy_enabled_request = new Request( AUTH_PROXY_ENABLED );
719 auth_proxy_enabled_request.request.alertEvent = false;
720 auth_proxy_enabled_request.send(true);
721 if (auth_proxy_enabled_request.result() == 1) {
722 auth_proxy_enabled = true;
725 var uname = G.ui.login.username.value;
726 var passwd = G.ui.login.password.value;
730 org : getOrigLocation(),
734 r = fetchOrgSettingDefault(globalOrgTree.id(), 'opac.barcode_regex');
735 if(r) REGEX_BARCODE = new RegExp(r);
737 if( uname.match(REGEX_BARCODE) ) args.barcode = uname;
738 else args.username = uname;
741 if (!auth_proxy_enabled) {
742 var init_request = new Request( LOGIN_INIT, uname );
743 init_request.send(true);
744 var seed = init_request.result();
746 if( ! seed || seed == '0') {
747 alert( "Error Communicating with Authentication Server" );
751 args.password = hex_md5(seed + hex_md5(passwd));
752 auth_request = new Request( LOGIN_COMPLETE, args );
754 args.password = passwd;
755 auth_request = new Request( AUTH_PROXY_LOGIN, args );
758 auth_request.request.alertEvent = false;
759 auth_request.send(true);
760 var auth_result = auth_request.result();
763 alertId('patron_login_failed');
767 if( checkILSEvent(auth_result) ) {
769 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
770 alertId('patron_inactive_alert');
774 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
775 alertId('patron_card_inactive_alert');
779 if( auth_result.textcode == 'LOGIN_FAILED' ||
780 auth_result.textcode == 'PERM_FAILURE' ) {
781 alertId('patron_login_failed');
787 AUTHTIME = parseInt(auth_result.payload.authtime);
788 var u = grabUser(auth_result.payload.authtoken, true);
789 if(u && ! suppressEvents)
790 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
797 function doLogout() {
799 /* cancel everything else */
802 /* be nice and delete the session from the server */
803 if(G.user && G.user.session) {
804 var req = new Request(LOGIN_DELETE, G.user.session);
806 try { req.result(); } catch(E){}
811 /* remove any cached data */
812 dojo.require('dojo.cookie');
813 dojo.cookie(COOKIE_SES, null, {expires:-1});
814 dojo.cookie(COOKIE_RIDS, null, {expires:-1});
815 dojo.cookie(COOKIE_SKIN, null, {expires:-1});
816 dojo.cookie(COOKIE_SEARCH, null, {expires:-1});
819 checkUserSkin("default");
824 args[PARAM_TERM] = "";
825 args[PARAM_LOCATION] = getOrigLocation();
826 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation() || globalOrgTree);
831 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
832 if(!nored) goTo(buildOPACLink(args, false, false));
836 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
837 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
840 /* ----------------------------------------------------------------------- */
841 /* build the org tree */
842 /* ----------------------------------------------------------------------- */
843 function drawOrgTree() {
844 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
845 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
848 var checkOrgHiding_cached = false;
849 var checkOrgHiding_cached_context_org;
850 var checkOrgHiding_cached_depth;
851 function checkOrgHiding() {
853 return false; // disable org hiding for staff client
855 var context_org = getOrigLocation() || globalOrgTree.id();
857 if (checkOrgHiding_cached) {
858 if (checkOrgHiding_cached_context_org != context_org) {
859 checkOrgHiding_cached_context_org = context_org;
860 checkOrgHiding_cached_depth = undefined;
861 checkOrgHiding_cached = false;
863 depth = checkOrgHiding_cached_depth;
866 depth = fetchOrgSettingDefault( context_org, 'opac.org_unit_hiding.depth');
867 checkOrgHiding_cached_depth = depth;
868 checkOrgHiding_cached_context_org = context_org;
869 checkOrgHiding_cached = true;
871 if ( findOrgDepth( context_org ) < depth ) {
872 return false; // disable org hiding if Original Location doesn't make sense with setting depth (avoids disjointed org selectors)
875 return { 'org' : findOrgUnit(context_org), 'depth' : depth };
882 function buildOrgSelector(node) {
883 var tree = new SlimTree(node,'orgTreeSelector');
884 orgTreeSelector = tree;
885 var orgHiding = checkOrgHiding();
886 for (var i = 0; i < orgArraySearcherOrder.length; i++) {
887 var node = orgArraySearcher[orgArraySearcherOrder[i]];
888 if( node == null ) continue;
889 if(!isXUL() && !isTrue(node.opac_visible())) continue;
891 if ( ! orgIsMine( orgHiding.org, node, orgHiding.depth ) ) {
895 if(node.parent_ou() == null) {
896 tree.addNode(node.id(), -1, node.name(),
897 "javascript:orgSelect(" + node.id() + ");", node.name());
899 if (orgHiding && orgHiding.depth == findOrgDepth(node)) {
900 tree.addNode(node.id(), -1, node.name(),
901 "javascript:orgSelect(" + node.id() + ");", node.name());
903 tree.addNode(node.id(), node.parent_ou(), node.name(),
904 "javascript:orgSelect(" + node.id() + ");", node.name());
908 hideMe($('org_loading_div'));
909 unHideMe($('org_selector_tip'));
913 function orgSelect(id) {
915 runEvt("common", "locationChanged", id, findOrgDepth(id) );
918 var loc = findOrgLasso(getLasso());
919 if (!loc) loc = findOrgUnit(id);
921 removeChildren(G.ui.common.now_searching);
922 G.ui.common.now_searching.appendChild(text(loc.name()));
925 function setFontSize(size) {
927 dojo.cookie(COOKIE_FONT, size, { 'expires' : 365});
930 var resourceFormats = [
933 "sound recording", "software, multimedia",
938 "three dimensional object" ];
941 function modsFormatToMARC(format) {
947 case "sound recording":
949 case "sound recording-nonmusical":
951 case "sound recording-musical":
953 case "software, multimedia":
959 case "mixed material":
961 case "notated music":
963 case "three dimensional object":
970 function MARCFormatToMods(format) {
976 return "moving image";
978 return "sound recording-nonmusical";
980 return "sound recording-musical";
982 return "software, multimedia";
984 return "still image";
987 return "cartographic";
990 return "mixed material";
993 return "notated music";
995 return "three dimensional object";
1000 function MARCTypeToFriendly(format) {
1001 var words = $('format_words');
1004 case 't' : return $n(words, 'at').innerHTML;
1006 var node = $n(words,format);
1007 if( node ) return node.innerHTML;
1012 function setResourcePic( img, resource ) {
1013 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
1014 img.title = resource;
1019 function msg( text ) {
1020 try { alert( text ); } catch(e) {}
1023 function findRecord(id,type) {
1025 for( var i = 0; i != recordsCache.length; i++ ) {
1026 var rec = recordsCache[i];
1027 if( rec && rec.doc_id() == id ) return rec;
1030 var meth = FETCH_RMODS
1031 if(type == 'M') meth = FETCH_MRMODS;
1032 var req = new Request(meth, id);
1033 req.request.alertEvent = false;
1035 var res = req.result();
1036 if( checkILSEvent(res) ) return null;
1040 function Timer(name, node){
1045 Timer.prototype.start =
1046 function(){_timerRun(this.name);}
1047 Timer.prototype.stop =
1048 function(){this.done = true;}
1049 function _timerRun(tname) {
1053 if(_t.count > 100) return;
1055 if( (_t.count % 5) == 0 )
1057 _t.node.appendChild(text(str));
1058 setTimeout("_timerRun('"+tname+"');", 200);
1062 function checkILSEvent(obj) {
1063 if (obj && typeof obj == 'object' && typeof obj.ilsevent != 'undefined') {
1064 if (obj.ilsevent === '') {
1066 } else if ( obj.ilsevent != null && obj.ilsevent != 0 ) {
1067 return parseInt(obj.ilsevent);
1074 function alertILSEvent(evt, msg) {
1077 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
1079 alert(evt.textcode + '\n' + evt.desc );
1084 function AuthTimer(time) {
1085 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
1087 try {clearTimeout(__authTimer.id)} catch(e){}
1091 AuthTimer.prototype.run = function() {
1092 this.id = setTimeout('_authTimerAlert()', this.time);
1095 function _authTimerAlert() {
1096 alert( $('auth_session_expiring').innerHTML );
1097 if(!grabUser(null, true)) doLogout();
1101 function grabUserByBarcode( authtoken, barcode ) {
1102 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
1104 return req.result();
1109 goTo(buildOPACLink({page:HOME}));
1113 function buildOrgSel(selector, org, offset, namecol) {
1114 if(!namecol) namecol = 'name';
1115 if(!isXUL() && !isTrue(org.opac_visible())) return;
1116 insertSelectorVal( selector, -1,
1117 org[namecol](), org.id(), null, findOrgDepth(org) - offset );
1118 var kids = org.children();
1120 for( var c = 0; c < kids.length; c++ )
1121 buildOrgSel( selector, kids[c], offset, namecol);
1125 function buildMergedOrgSel(selector, org_list, offset, namecol) {
1126 if(!namecol) namecol = 'name';
1127 for(var i = 0; i < org_list.length; i++) {
1128 var org = findOrgUnit(org_list[i]);
1129 insertSelectorVal( selector, -1,
1130 org[namecol](), org.id(), null, findOrgDepth(org) - offset );
1131 var kids = org.children();
1133 for( var c = 0; c < kids.length; c++ )
1134 buildOrgSel( selector, kids[c], offset, namecol);
1140 function parseForm(form) {
1141 if(!form) return {};
1143 var it = form.replace(/-\w+$/,"");
1148 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
1152 for( var i = 0; i < it.length; i++ )
1153 item_type.push( it.charAt(i) );
1158 for( var i = 0; i < itf.length; i++ )
1159 item_form.push( itf.charAt(i) );
1162 return {item_type: item_type, item_form:item_form};
1166 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
1168 function fetchPermOrgs() {
1169 var a = []; /* Q: why does arguments come accross as an object and not an array? A: because arguments is a special object, a collection */
1171 for( var i = 0; i < arguments.length; i++ )
1172 a.push(arguments[i])
1174 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
1175 G.user.session, G.user.id(), a );
1177 return preq.result();
1181 function print_tabs(t) {
1183 for (var j = 0; j < t; j++ ) { r = r + " "; }
1186 function formatJSON(s) {
1187 var r = ''; var t = 0;
1189 if (s[i] == '{' || s[i] == '[' ) {
1190 r = r + s[i] + "\n" + print_tabs(++t);
1191 } else if (s[i] == '}' || s[i] == ']') {
1192 t--; r = r + "\n" + print_tabs(t) + s[i];
1193 } else if (s[i] == ',') {
1194 r = r + s[i] + "\n" + print_tabs(t);