1 /* - Request ------------------------------------------------------------- */
4 /* define it again here for pages that don't load RemoteRequest */
5 function isXUL() { try { if(IAMXUL) return true;}catch(e){return false;}; }
8 var __ilsEvent; /* the last event the occurred */
11 function Request(type) {
13 var s = type.split(":");
14 if(s[2] == "1" && isXUL()) s[1] += ".staff";
15 this.request = new RemoteRequest(s[0], s[1]);
19 if(!location.href.match(/^https:/))
20 this.request.setSecure(false);
24 if( G.user && G.user.session ) {
25 /* if the user is logged in, all activity resets the timeout
26 This is not entirely accurate in the sense that not all
27 requests will reset the server timeout - this should
28 get close enough, however.
30 var at = getAuthtime();
31 if(at) new AuthTimer(at).run();
35 for( var x = 1; x!= arguments.length; x++ ) {
37 this.request.addParam(arguments[x]);
42 for( var i = 0; i != p.length; i++ ) {
43 if( i > 0 ) str += ", "
46 _debug('request ' + s[0] + ' ' + s[1] + ' ' + str );
48 } else if( DEBUGSLIM ) {
49 _debug('request ' + s[1]);
53 Request.prototype.callback = function(cal) {this.request.setCompleteCallback(cal);}
54 Request.prototype.send = function(block){this.request.send(block);}
55 Request.prototype.result = function(){return this.request.getResultObject();}
57 function showCanvas() {
58 for( var x in G.ui.altcanvas ) {
59 hideMe(G.ui.altcanvas[x]);
61 hideMe(G.ui.common.loading);
62 unHideMe(G.ui.common.canvas_main);
63 try{G.ui.searchbar.text.focus();}catch(e){}
66 function swapCanvas(newNode) {
67 for( var x in G.ui.altcanvas )
68 hideMe(G.ui.altcanvas[x]);
70 hideMe(G.ui.common.loading);
71 hideMe(G.ui.common.canvas_main);
75 /* finds the name of the current page */
76 var currentPage = null;
77 function findCurrentPage() {
78 if(currentPage) return currentPage;
81 for( var p in config.page ) pages.push(config.page[p]);
82 pages = pages.sort( function(a,b){ return - (a.length - b.length); } );
84 var path = location.pathname;
85 if(!path.match(/.*\.xml$/))
86 path += "index.xml"; /* in case they go to / */
89 for( var p = 0; p < pages.length; p++ ) {
90 if( path.indexOf(pages[p]) != -1)
94 for( var p in config.page ) {
95 if(config.page[p] == page) {
104 /* sets all of the params values ----------------------------- */
105 function initParams() {
108 /* handle the location var */
110 var loc = cgi.param(PARAM_LOCATION);
111 var lasso = cgi.param(PARAM_LASSO);
114 lasso = findOrgLasso( lasso );
115 LASSO = lasso ? lasso.id() : null;
119 org = findOrgUnit(loc);
120 LOCATION = org ? org.id() : null;
123 org = findOrgUnit(loc);
124 LOCATION = org ? org.id() : null;
129 loc = cgi.param(PARAM_ORIGLOC);
131 org = findOrgUnit(loc);
132 if(!org) org = findOrgUnitSN(loc);
134 ORIGLOC = (org) ? org.id() : null;
137 DEPTH = parseInt(cgi.param(PARAM_DEPTH));
138 if(isNaN(DEPTH)) DEPTH = null;
141 FACET = cgi.param(PARAM_FACET);
142 TERM = cgi.param(PARAM_TERM);
143 STYPE = cgi.param(PARAM_STYPE);
144 FORM = cgi.param(PARAM_FORM);
145 //DEPTH = parseInt(cgi.param(PARAM_DEPTH));
146 OFFSET = parseInt(cgi.param(PARAM_OFFSET));
147 COUNT = parseInt(cgi.param(PARAM_COUNT));
148 HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT));
149 MRID = parseInt(cgi.param(PARAM_MRID));
150 RID = parseInt(cgi.param(PARAM_RID));
151 AUTHTIME = parseInt(cgi.param(PARAM_AUTHTIME));
152 ADVTERM = cgi.param(PARAM_ADVTERM);
153 ADVTYPE = cgi.param(PARAM_ADVTYPE);
154 RTYPE = cgi.param(PARAM_RTYPE);
155 SORT = cgi.param(PARAM_SORT);
156 SORT_DIR = cgi.param(PARAM_SORT_DIR);
157 DEBUG = cgi.param(PARAM_DEBUG);
158 CALLNUM = cgi.param(PARAM_CN);
159 LITFORM = cgi.param(PARAM_LITFORM);
160 ITEMFORM = cgi.param(PARAM_ITEMFORM);
161 ITEMTYPE = cgi.param(PARAM_ITEMTYPE);
162 BIBLEVEL = cgi.param(PARAM_BIBLEVEL);
163 AUDIENCE = cgi.param(PARAM_AUDIENCE);
164 SEARCHES = cgi.param(PARAM_SEARCHES);
165 LANGUAGE = cgi.param(PARAM_LANGUAGE);
166 TFORM = cgi.param(PARAM_TFORM);
167 RDEPTH = cgi.param(PARAM_RDEPTH);
168 AVAIL = cgi.param(PARAM_AVAIL);
169 COPYLOCS = cgi.param(PARAM_COPYLOCS);
170 PUBD_BEFORE = cgi.param(PARAM_PUBD_BEFORE);
171 PUBD_AFTER = cgi.param(PARAM_PUBD_AFTER);
172 PUBD_BETWEEN = cgi.param(PARAM_PUBD_BETWEEN);
173 PUBD_DURING = cgi.param(PARAM_PUBD_DURING);
176 /* set up some sane defaults */
177 //if(isNaN(DEPTH)) DEPTH = 0;
178 if(isNaN(RDEPTH)) RDEPTH = 0;
179 if(isNaN(OFFSET)) OFFSET = 0;
180 if(isNaN(COUNT)) COUNT = 10;
181 if(isNaN(HITCOUNT)) HITCOUNT = 0;
182 if(isNaN(MRID)) MRID = 0;
183 if(isNaN(RID)) RID = 0;
184 if(isNaN(ORIGLOC)) ORIGLOC = 0; /* so we know it hasn't been set */
185 if(isNaN(AUTHTIME)) AUTHTIME = 0;
186 if(ADVTERM==null) ADVTERM = "";
187 if(isNaN(AVAIL)) AVAIL = 0;
190 function clearSearchParams() {
222 function initCookies() {
223 dojo.require('dojo.cookie');
224 FONTSIZE = "regular";
225 var font = dojo.cookie(COOKIE_FONT);
227 if(font) FONTSIZE = font;
228 SKIN = dojo.cookie(COOKIE_SKIN);
229 if(findCurrentPage() == HOME)
230 dojo.cookie(COOKIE_SEARCH,null,{'expires':-1});
233 /* URL param accessors */
234 function getTerm(){return TERM;}
235 function getFacet(){return FACET;}
236 function getStype(){return STYPE;}
237 function getLocation(){return LOCATION;}
238 function getLasso(){return LASSO;}
239 function getDepth(){return DEPTH;}
240 function getForm(){return FORM;}
241 function getTform(){return TFORM;}
242 function getOffset(){return OFFSET;}
243 function getDisplayCount(){return COUNT;}
244 function getHitCount(){return HITCOUNT;}
245 function getMrid(){return MRID;};
246 function getRid(){return RID;};
247 function getOrigLocation(){return ORIGLOC;}
248 function getAuthtime() { return AUTHTIME; }
249 function getSearchBarExtras(){return SBEXTRAS;}
250 function getFontSize(){return FONTSIZE;};
251 function getSkin(){return SKIN;};
252 function getAdvTerm(){return ADVTERM;}
253 function getAdvType(){return ADVTYPE;}
254 function getRtype(){return RTYPE;}
255 function getSort(){return SORT;}
256 function getSortDir(){return SORT_DIR;}
257 function getDebug(){return DEBUG;}
258 function getCallnumber() { return CALLNUM; }
259 function getLitForm() { return LITFORM; }
260 function getItemForm() { return ITEMFORM; }
261 function getItemType() { return ITEMTYPE; }
262 function getBibLevel() { return BIBLEVEL; }
263 function getAudience() { return AUDIENCE; }
264 function getSearches() { return SEARCHES; }
265 function getLanguage() { return LANGUAGE; }
266 function getRdepth() { return RDEPTH; }
267 function getAvail() { return AVAIL; }
268 function getCopyLocs() { return COPYLOCS; }
269 function getPubdBefore() { return PUBD_BEFORE; }
270 function getPubdAfter() { return PUBD_AFTER; }
271 function getPubdBetween() { return PUBD_BETWEEN; }
272 function getPubdDuring() { return PUBD_DURING; }
275 function findBasePath() {
276 var path = location.pathname;
277 if(!path.match(/.*\.xml$/)) path += "index.xml";
278 var idx = path.indexOf(config.page[findCurrentPage()]);
279 return path.substring(0, idx);
282 function findBaseURL(ssl) {
283 var path = findBasePath();
284 var proto = (ssl) ? "https:" : "http:";
286 /* strip port numbers. This is necessary for browsers that
287 send an explicit <host>:80, 443 - explicit ports
288 break links that need to change ports (e.g. http -> https) */
289 var h = location.host.replace(/:.*/,'');
291 return proto + "//" + h + path;
295 function buildISBNSrc(isbn) {
296 return "http://" + location.host + "/jackets/" + isbn;
300 function buildImageLink(name, ssl) {
301 return findBaseURL(ssl) + "../../../../images/" + name;
304 function buildExtrasLink(name, ssl) {
305 return findBaseURL(ssl) + "../../../../extras/" + name;
309 function _debug(str) {
310 try { dump('dbg: ' + str + '\n'); } catch(e) {}
312 /* potentially useful, but usually just annoying */
315 if(!consoleService) {
317 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
318 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
319 .getService(Components.interfaces.nsIConsoleService);
325 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
326 consoleService.logStringMessage(str + '\n');
333 var forceLoginSSL; // set via Apache env variable
334 function buildOPACLink(args, slim, ssl) {
339 if( ssl == undefined && (
340 location.protocol == 'https:' ||
341 (forceLoginSSL && G.user && G.user.session))) {
346 string = findBaseURL(ssl);
347 if(args.page) string += config.page[args.page];
348 else string += config.page[findCurrentPage()];
351 /* this may seem unnecessary.. safety precaution for now */
353 if( args[PARAM_DEPTH] == null )
354 args[PARAM_DEPTH] = getDepth();
359 for( var x in args ) {
361 if(x == "page" || v == null || v == undefined || v+'' == 'NaN' ) continue;
362 if(x == PARAM_OFFSET && v == 0) continue;
363 if(x == PARAM_COUNT && v == 10) continue;
364 if(x == PARAM_FORM && v == 'all' ) continue;
365 if( instanceOf(v, Array) && v.length ) {
366 for( var i = 0; i < v.length; i++ ) {
367 string += "&" + x + "=" + encodeURIComponent(v[i]);
370 string += "&" + x + "=" + encodeURIComponent(v);
375 string += _appendParam(DEBUG, PARAM_DEBUG, args, getDebug, string);
376 if(getOrigLocation() != 1)
377 string += _appendParam(ORIGLOC, PARAM_ORIGLOC, args, getOrigLocation, string);
379 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
381 string += _appendParam(FACET, PARAM_FACET, args, getFacet, string);
383 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
384 if(getLocation() != 1)
385 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
386 if(getLasso() != null)
387 string += _appendParam(LASSO, PARAM_LASSO, args, getLasso, string);
388 if(getDepth() != null)
389 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
390 if(getForm() && (getForm() != 'all') )
391 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
392 if(getTform() && (getTform() != 'all') )
393 string += _appendParam(TFORM, PARAM_TFORM, args, getTform, string);
395 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
396 if(getDisplayCount() != 10)
397 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
399 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
401 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
403 string += _appendParam(RID, PARAM_RID, args, getRid, string);
405 string += _appendParam(AUTHTIME, PARAM_AUTHTIME, args, getAuthtime, string);
407 string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
409 string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
411 string += _appendParam(RTYPE, PARAM_RTYPE, args, getRtype, string);
413 string += _appendParam(ITEMFORM, PARAM_ITEMFORM, args, getItemForm, string);
415 string += _appendParam(ITEMTYPE, PARAM_ITEMTYPE, args, getItemType, string);
417 string += _appendParam(BIBLEVEL, PARAM_BIBLEVEL, args, getBibLevel, string);
419 string += _appendParam(LITFORM, PARAM_LITFORM, args, getLitForm, string);
421 string += _appendParam(AUDIENCE, PARAM_AUDIENCE, args, getAudience, string);
423 string += _appendParam(SEARCHES, PARAM_SEARCHES, args, getSearches, string);
425 string += _appendParam(LANGUAGE, PARAM_LANGUAGE, args, getLanguage, string);
426 if(getRdepth() != null)
427 string += _appendParam(RDEPTH, PARAM_RDEPTH, args, getRdepth, string);
428 if(getSort() != null)
429 string += _appendParam(SORT, PARAM_SORT, args, getSort, string);
430 if(getSortDir() != null)
431 string += _appendParam(SORT_DIR, PARAM_SORT_DIR, args, getSortDir, string);
433 string += _appendParam(AVAIL, PARAM_AVAIL, args, getAvail, string);
435 string += _appendParam(COPYLOCS, PARAM_COPYLOCS, args, getCopyLocs, string);
437 string += _appendParam(PUBD_BEFORE, PARAM_PUBD_BEFORE, args, getPubdBefore, string);
439 string += _appendParam(PUBD_AFTER, PARAM_PUBD_AFTER, args, getPubdAfter, string);
441 string += _appendParam(PUBD_BETWEEN, PARAM_PUBD_BETWEEN, args, getPubdBetween, string);
443 string += _appendParam(PUBD_DURING, PARAM_PUBD_DURING, args, getPubdDuring, string);
446 return string.replace(/\&$/,'').replace(/\?\&/,"?");
450 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
454 if( fieldVar != null &&
455 (fieldVar +'' != 'NaN') &&
456 overrideArgs[fieldName] == null &&
458 getFunc()+'' != '' ) {
460 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
466 /* ----------------------------------------------------------------------- */
467 function cleanISBN(isbn) {
469 isbn = isbn.toString().replace(/^\s+/,"");
470 var idx = isbn.indexOf(" ");
471 if(idx > -1) { isbn = isbn.substring(0, idx); }
477 /* builds a link that goes to the title listings for a metarecord */
478 function buildTitleLink(rec, link) {
480 link.appendChild(text(normalize(truncate(rec.title(), 65))));
483 args[PARAM_OFFSET] = 0;
484 args[PARAM_MRID] = rec.doc_id();
485 args[PARAM_RTYPE] = RTYPE_MRID;
486 var linkText = link.innerHTML; // IE
487 link.setAttribute("href", buildOPACLink(args));
488 link.innerHTML = linkText; // IE
491 function buildTitleDetailLink(rec, link) {
493 link.appendChild(text(normalize(truncate(rec.title(), 65))));
496 args[PARAM_RID] = rec.doc_id();
497 // in IE, if the link text contains a '@', it replaces the innerHTML text
498 // with the value of the href attribute. Wait, what? Yes. Capture the
499 // innerHTML and put it back into place after the href is set
500 var linkText = link.innerHTML; // IE
501 link.setAttribute("href", buildOPACLink(args));
502 link.innerHTML = linkText; // IE
505 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
506 'trunc' is the number of characters to show in the string, defaults to 65 */
507 function buildSearchLink(type, string, linknode, trunc) {
508 if(!trunc) trunc = 65;
510 if( SHOW_MR_DEFAULT || findCurrentPage() == MRESULT ) {
514 args[PARAM_RTYPE] = type;
516 args[PARAM_OFFSET] = 0;
517 args[PARAM_TERM] = string;
518 args[PARAM_STYPE] = type;
519 linknode.appendChild(text(normalize(truncate(string, trunc))));
520 linknode.setAttribute("href", buildOPACLink(args));
523 function setSessionCookie(ses) {
524 dojo.cookie(COOKIE_SES, ses);
529 /* ----------------------------------------------------------------------- */
530 /* user session handling */
531 /* ----------------------------------------------------------------------- */
532 /* session is the login session. If no session is provided, we attempt
533 to find one in the cookies. If 'force' is true we retrieve the
534 user from the server even if there is already a global user present.
535 if ses != G.user.session, we also force a grab */
536 function grabUser(ses, force) {
538 _debug("grabUser auth token = " + ses);
539 if(!ses && isXUL()) {
540 stash = fetchXULStash();
541 ses = stash.session.key
542 _debug("stash auth token = " + ses);
546 ses = dojo.cookie(COOKIE_SES);
547 /* https cookies don't show up in http servers.. */
548 _debug("cookie auth token = " + ses);
551 if(!ses) return false;
554 if(G.user && G.user.session == ses)
557 /* first make sure the session is valid */
558 var request = new Request(FETCH_SESSION, ses);
559 request.request.alertEvent = false;
561 var user = request.result();
563 if(!user || user.textcode == 'NO_SESSION') {
566 dojo.require('openils.XUL');
567 dump('getNewSession in opac_utils.js\n');
568 openils.XUL.getNewSession(
569 function(success, authtoken) {
572 var request = new Request(FETCH_SESSION, ses);
573 request.request.alertEvent = false;
575 user = request.result();
581 if(!user || user.textcode == 'NO_SESSION') {
583 return false; /* unable to grab the session */
587 if( !(typeof user == 'object' && user._isfieldmapper) ) {
593 G.user.fleshed = false;
594 G.user.session = ses;
595 setSessionCookie(ses);
598 if(G.user.prefs['opac.hits_per_page'])
599 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
601 if(G.user.prefs[PREF_DEF_FONT])
602 setFontSize(G.user.prefs[PREF_DEF_FONT]);
604 var at = getAuthtime();
605 //if(isXUL()) at = xulG['authtime'];
607 if(at && !isXUL()) new AuthTimer(at).run();
612 /* sets the 'prefs' field of the user object to their preferences
613 and returns the preferences */
614 function grabUserPrefs(user, force) {
615 if(user == null) user = G.user;
616 if(!force && user.prefs) return user.prefs;
617 var req = new Request(FETCH_USER_PREFS, G.user.session, user.id());
619 user.prefs = req.result();
623 function grabFleshedUser() {
625 if(!G.user || !G.user.session) {
627 if(!G.user || !G.user.session) return null;
630 if(G.user.fleshed) return G.user;
632 var req = new Request(FETCH_FLESHED_USER, G.user.session);
635 G.user = req.result();
637 if(!G.user || G.user.length == 0) {
638 dojo.cookie(COOKIE_SES,null,{'expires':-1});
639 G.user = null; return false;
642 G.user.session = ses;
643 G.user.fleshed = true;
645 setSessionCookie(ses);
649 function checkUserSkin(new_skin) {
651 return; /* XXX do some debugging with this... */
653 var user_skin = getSkin();
654 var cur_skin = grabSkinFromURL();
656 if(new_skin) user_skin = new_skin;
661 if(grabUserPrefs()) {
662 user_skin = G.user.prefs["opac.skin"];
663 dojo.cookie( COOKIE_SKIN, user_skin, { 'expires' : 365 } );
668 if(!user_skin) return;
670 if( cur_skin != user_skin ) {
671 var url = buildOPACLink();
672 goTo(url.replace(cur_skin, user_skin));
676 function updateUserSetting(setting, value, user) {
677 if(user == null) user = G.user;
680 var req = new Request( UPDATE_USER_PREFS, user.session, a );
685 function commitUserPrefs() {
686 var req = new Request(
687 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
692 function grabSkinFromURL() {
693 var path = findBasePath();
694 path = path.replace("/xml/", "");
696 for( var i = path.length - 1; i >= 0; i-- ) {
697 var ch = path.charAt(i);
703 for( i = skin.length - 1; i >= 0; i--)
704 skin2 += skin.charAt(i);
710 /* returns a fleshed G.user on success, false on failure */
711 function doLogin(suppressEvents) {
715 var auth_proxy_enabled = false;
716 var auth_proxy_enabled_request = new Request( AUTH_PROXY_ENABLED );
717 auth_proxy_enabled_request.request.alertEvent = false;
718 auth_proxy_enabled_request.send(true);
719 if (auth_proxy_enabled_request.result() == 1) {
720 auth_proxy_enabled = true;
723 var uname = G.ui.login.username.value;
724 var passwd = G.ui.login.password.value;
728 org : getOrigLocation(),
732 r = fetchOrgSettingDefault(globalOrgTree.id(), 'opac.barcode_regex');
733 if(r) REGEX_BARCODE = new RegExp(r);
735 if( uname.match(REGEX_BARCODE) ) args.barcode = uname;
736 else args.username = uname;
739 if (!auth_proxy_enabled) {
740 var init_request = new Request( LOGIN_INIT, uname );
741 init_request.send(true);
742 var seed = init_request.result();
744 if( ! seed || seed == '0') {
745 alert( "Error Communicating with Authentication Server" );
749 args.password = hex_md5(seed + hex_md5(passwd));
750 auth_request = new Request( LOGIN_COMPLETE, args );
752 args.password = passwd;
753 auth_request = new Request( AUTH_PROXY_LOGIN, args );
756 auth_request.request.alertEvent = false;
757 auth_request.send(true);
758 var auth_result = auth_request.result();
761 alertId('patron_login_failed');
765 if( checkILSEvent(auth_result) ) {
767 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
768 alertId('patron_inactive_alert');
772 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
773 alertId('patron_card_inactive_alert');
777 if( auth_result.textcode == 'LOGIN_FAILED' ||
778 auth_result.textcode == 'PERM_FAILURE' ) {
779 alertId('patron_login_failed');
785 AUTHTIME = parseInt(auth_result.payload.authtime);
786 var u = grabUser(auth_result.payload.authtoken, true);
787 if(u && ! suppressEvents)
788 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
795 function doLogout() {
797 /* cancel everything else */
800 /* be nice and delete the session from the server */
801 if(G.user && G.user.session) {
802 var req = new Request(LOGIN_DELETE, G.user.session);
804 try { req.result(); } catch(E){}
809 /* remove any cached data */
810 dojo.require('dojo.cookie');
811 dojo.cookie(COOKIE_SES, null, {expires:-1});
812 dojo.cookie(COOKIE_RIDS, null, {expires:-1});
813 dojo.cookie(COOKIE_SKIN, null, {expires:-1});
814 dojo.cookie(COOKIE_SEARCH, null, {expires:-1});
817 checkUserSkin("default");
822 args[PARAM_TERM] = "";
823 args[PARAM_LOCATION] = getOrigLocation();
824 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation() || globalOrgTree);
829 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
830 if(!nored) goTo(buildOPACLink(args, false, false));
834 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
835 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
838 /* ----------------------------------------------------------------------- */
839 /* build the org tree */
840 /* ----------------------------------------------------------------------- */
841 function drawOrgTree() {
842 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
843 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
846 var checkOrgHiding_cached = false;
847 var checkOrgHiding_cached_context_org;
848 var checkOrgHiding_cached_depth;
849 function checkOrgHiding() {
851 return false; // disable org hiding for staff client
853 var context_org = getOrigLocation() || globalOrgTree.id();
855 if (checkOrgHiding_cached) {
856 if (checkOrgHiding_cached_context_org != context_org) {
857 checkOrgHiding_cached_context_org = context_org;
858 checkOrgHiding_cached_depth = undefined;
859 checkOrgHiding_cached = false;
861 depth = checkOrgHiding_cached_depth;
864 depth = fetchOrgSettingDefault( context_org, 'opac.org_unit_hiding.depth');
865 checkOrgHiding_cached_depth = depth;
866 checkOrgHiding_cached_context_org = context_org;
867 checkOrgHiding_cached = true;
869 if ( findOrgDepth( context_org ) < depth ) {
870 return false; // disable org hiding if Original Location doesn't make sense with setting depth (avoids disjointed org selectors)
873 return { 'org' : findOrgUnit(context_org), 'depth' : depth };
880 function buildOrgSelector(node) {
881 var tree = new SlimTree(node,'orgTreeSelector');
882 orgTreeSelector = tree;
883 var orgHiding = checkOrgHiding();
884 for( var i in orgArraySearcher ) {
885 var node = orgArraySearcher[i];
886 if( node == null ) continue;
887 if(!isXUL() && !isTrue(node.opac_visible())) continue;
889 if ( ! orgIsMine( orgHiding.org, node, orgHiding.depth ) ) {
893 if(node.parent_ou() == null) {
894 tree.addNode(node.id(), -1, node.name(),
895 "javascript:orgSelect(" + node.id() + ");", node.name());
897 if (orgHiding && orgHiding.depth == findOrgDepth(node)) {
898 tree.addNode(node.id(), -1, node.name(),
899 "javascript:orgSelect(" + node.id() + ");", node.name());
901 tree.addNode(node.id(), node.parent_ou(), node.name(),
902 "javascript:orgSelect(" + node.id() + ");", node.name());
906 hideMe($('org_loading_div'));
907 unHideMe($('org_selector_tip'));
911 function orgSelect(id) {
913 runEvt("common", "locationChanged", id, findOrgDepth(id) );
916 var loc = findOrgLasso(getLasso());
917 if (!loc) loc = findOrgUnit(id);
919 removeChildren(G.ui.common.now_searching);
920 G.ui.common.now_searching.appendChild(text(loc.name()));
923 function setFontSize(size) {
925 dojo.cookie(COOKIE_FONT, size, { 'expires' : 365});
928 var resourceFormats = [
931 "sound recording", "software, multimedia",
936 "three dimensional object" ];
939 function modsFormatToMARC(format) {
945 case "sound recording":
947 case "sound recording-nonmusical":
949 case "sound recording-musical":
951 case "software, multimedia":
957 case "mixed material":
959 case "notated music":
961 case "three dimensional object":
968 function MARCFormatToMods(format) {
974 return "moving image";
976 return "sound recording-nonmusical";
978 return "sound recording-musical";
980 return "software, multimedia";
982 return "still image";
985 return "cartographic";
988 return "mixed material";
991 return "notated music";
993 return "three dimensional object";
998 function MARCTypeToFriendly(format) {
999 var words = $('format_words');
1002 case 't' : return $n(words, 'at').innerHTML;
1004 var node = $n(words,format);
1005 if( node ) return node.innerHTML;
1010 function setResourcePic( img, resource ) {
1011 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
1012 img.title = resource;
1017 function msg( text ) {
1018 try { alert( text ); } catch(e) {}
1021 function findRecord(id,type) {
1023 for( var i = 0; i != recordsCache.length; i++ ) {
1024 var rec = recordsCache[i];
1025 if( rec && rec.doc_id() == id ) return rec;
1028 var meth = FETCH_RMODS
1029 if(type == 'M') meth = FETCH_MRMODS;
1030 var req = new Request(meth, id);
1031 req.request.alertEvent = false;
1033 var res = req.result();
1034 if( checkILSEvent(res) ) return null;
1038 function Timer(name, node){
1043 Timer.prototype.start =
1044 function(){_timerRun(this.name);}
1045 Timer.prototype.stop =
1046 function(){this.done = true;}
1047 function _timerRun(tname) {
1051 if(_t.count > 100) return;
1053 if( (_t.count % 5) == 0 )
1055 _t.node.appendChild(text(str));
1056 setTimeout("_timerRun('"+tname+"');", 200);
1060 function checkILSEvent(obj) {
1061 if (obj && typeof obj == 'object' && typeof obj.ilsevent != 'undefined') {
1062 if (obj.ilsevent === '') {
1064 } else if ( obj.ilsevent != null && obj.ilsevent != 0 ) {
1065 return parseInt(obj.ilsevent);
1072 function alertILSEvent(evt, msg) {
1075 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
1077 alert(evt.textcode + '\n' + evt.desc );
1082 function AuthTimer(time) {
1083 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
1085 try {clearTimeout(__authTimer.id)} catch(e){}
1089 AuthTimer.prototype.run = function() {
1090 this.id = setTimeout('_authTimerAlert()', this.time);
1093 function _authTimerAlert() {
1094 alert( $('auth_session_expiring').innerHTML );
1095 if(!grabUser(null, true)) doLogout();
1099 function grabUserByBarcode( authtoken, barcode ) {
1100 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
1102 return req.result();
1107 goTo(buildOPACLink({page:HOME}));
1111 function buildOrgSel(selector, org, offset, namecol) {
1112 if(!namecol) namecol = 'name';
1113 if(!isXUL() && !isTrue(org.opac_visible())) return;
1114 insertSelectorVal( selector, -1,
1115 org[namecol](), org.id(), null, findOrgDepth(org) - offset );
1116 var kids = org.children();
1118 for( var c = 0; c < kids.length; c++ )
1119 buildOrgSel( selector, kids[c], offset, namecol);
1123 function buildMergedOrgSel(selector, org_list, offset, namecol) {
1124 if(!namecol) namecol = 'name';
1125 for(var i = 0; i < org_list.length; i++) {
1126 var org = findOrgUnit(org_list[i]);
1127 insertSelectorVal( selector, -1,
1128 org[namecol](), org.id(), null, findOrgDepth(org) - offset );
1129 var kids = org.children();
1131 for( var c = 0; c < kids.length; c++ )
1132 buildOrgSel( selector, kids[c], offset, namecol);
1138 function parseForm(form) {
1139 if(!form) return {};
1141 var it = form.replace(/-\w+$/,"");
1146 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
1150 for( var i = 0; i < it.length; i++ )
1151 item_type.push( it.charAt(i) );
1156 for( var i = 0; i < itf.length; i++ )
1157 item_form.push( itf.charAt(i) );
1160 return {item_type: item_type, item_form:item_form};
1164 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
1166 function fetchPermOrgs() {
1167 var a = []; /* Q: why does arguments come accross as an object and not an array? A: because arguments is a special object, a collection */
1169 for( var i = 0; i < arguments.length; i++ )
1170 a.push(arguments[i])
1172 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
1173 G.user.session, G.user.id(), a );
1175 return preq.result();
1179 function print_tabs(t) {
1181 for (var j = 0; j < t; j++ ) { r = r + " "; }
1184 function formatJSON(s) {
1185 var r = ''; var t = 0;
1187 if (s[i] == '{' || s[i] == '[' ) {
1188 r = r + s[i] + "\n" + print_tabs(++t);
1189 } else if (s[i] == '}' || s[i] == ']') {
1190 t--; r = r + "\n" + print_tabs(t) + s[i];
1191 } else if (s[i] == ',') {
1192 r = r + s[i] + "\n" + print_tabs(t);