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;
298 function buildImageLink(name, ssl) {
299 return findBaseURL(ssl) + "../../../../images/" + name;
302 function buildExtrasLink(name, ssl) {
303 return findBaseURL(ssl) + "../../../../extras/" + name;
307 function _debug(str) {
308 try { dump('dbg: ' + str + '\n'); } catch(e) {}
310 /* potentially useful, but usually just annoying */
313 if(!consoleService) {
315 this.consoleService = Components.classes['@mozilla.org/consoleservice;1']
316 .getService(Components.interfaces.nsIConsoleService);
322 consoleService.logStringMessage(str + '\n');
329 var forceLoginSSL; // set via Apache env variable
330 function buildOPACLink(args, slim, ssl) {
335 if( ssl == undefined && (
336 location.protocol == 'https:' || location.protocol == 'oils:' ||
337 (forceLoginSSL && G.user && G.user.session))) {
342 string = findBaseURL(ssl);
343 if(args.page) string += config.page[args.page];
344 else string += config.page[findCurrentPage()];
347 /* this may seem unnecessary.. safety precaution for now */
349 if( args[PARAM_DEPTH] == null )
350 args[PARAM_DEPTH] = getDepth();
355 for( var x in args ) {
357 if(x == "page" || v == null || v == undefined || v+'' == 'NaN' ) continue;
358 if(x == PARAM_OFFSET && v == 0) continue;
359 if(x == PARAM_COUNT && v == 10) continue;
360 if(x == PARAM_FORM && v == 'all' ) continue;
361 if( instanceOf(v, Array) && v.length ) {
362 for( var i = 0; i < v.length; i++ ) {
363 string += "&" + x + "=" + encodeURIComponent(v[i]);
366 string += "&" + x + "=" + encodeURIComponent(v);
371 string += _appendParam(DEBUG, PARAM_DEBUG, args, getDebug, string);
372 if(getOrigLocation() != 1)
373 string += _appendParam(ORIGLOC, PARAM_ORIGLOC, args, getOrigLocation, string);
375 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
377 string += _appendParam(FACET, PARAM_FACET, args, getFacet, string);
379 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
380 if(getLocation() != 1)
381 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
382 if(getLasso() != null)
383 string += _appendParam(LASSO, PARAM_LASSO, args, getLasso, string);
384 if(getDepth() != null)
385 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
386 if(getForm() && (getForm() != 'all') )
387 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
388 if(getTform() && (getTform() != 'all') )
389 string += _appendParam(TFORM, PARAM_TFORM, args, getTform, string);
391 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
392 if(getDisplayCount() != 10)
393 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
395 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
397 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
399 string += _appendParam(RID, PARAM_RID, args, getRid, string);
401 string += _appendParam(AUTHTIME, PARAM_AUTHTIME, args, getAuthtime, string);
403 string += _appendParam(ADVTERM, PARAM_ADVTERM, args, getAdvTerm, string);
405 string += _appendParam(ADVTYPE, PARAM_ADVTYPE, args, getAdvType, string);
407 string += _appendParam(RTYPE, PARAM_RTYPE, args, getRtype, string);
409 string += _appendParam(ITEMFORM, PARAM_ITEMFORM, args, getItemForm, string);
411 string += _appendParam(ITEMTYPE, PARAM_ITEMTYPE, args, getItemType, string);
413 string += _appendParam(BIBLEVEL, PARAM_BIBLEVEL, args, getBibLevel, string);
415 string += _appendParam(LITFORM, PARAM_LITFORM, args, getLitForm, string);
417 string += _appendParam(AUDIENCE, PARAM_AUDIENCE, args, getAudience, string);
419 string += _appendParam(SEARCHES, PARAM_SEARCHES, args, getSearches, string);
421 string += _appendParam(LANGUAGE, PARAM_LANGUAGE, args, getLanguage, string);
422 if(getRdepth() != null)
423 string += _appendParam(RDEPTH, PARAM_RDEPTH, args, getRdepth, string);
424 if(getSort() != null)
425 string += _appendParam(SORT, PARAM_SORT, args, getSort, string);
426 if(getSortDir() != null)
427 string += _appendParam(SORT_DIR, PARAM_SORT_DIR, args, getSortDir, string);
429 string += _appendParam(AVAIL, PARAM_AVAIL, args, getAvail, string);
431 string += _appendParam(COPYLOCS, PARAM_COPYLOCS, args, getCopyLocs, string);
433 string += _appendParam(PUBD_BEFORE, PARAM_PUBD_BEFORE, args, getPubdBefore, string);
435 string += _appendParam(PUBD_AFTER, PARAM_PUBD_AFTER, args, getPubdAfter, string);
437 string += _appendParam(PUBD_BETWEEN, PARAM_PUBD_BETWEEN, args, getPubdBetween, string);
439 string += _appendParam(PUBD_DURING, PARAM_PUBD_DURING, args, getPubdDuring, string);
442 return string.replace(/\&$/,'').replace(/\?\&/,"?");
446 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
450 if( fieldVar != null &&
451 (fieldVar +'' != 'NaN') &&
452 overrideArgs[fieldName] == null &&
454 getFunc()+'' != '' ) {
456 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
462 /* ----------------------------------------------------------------------- */
463 function cleanISBN(isbn) {
465 isbn = isbn.toString().replace(/^\s+/,"");
466 var idx = isbn.indexOf(" ");
467 if(idx > -1) { isbn = isbn.substring(0, idx); }
473 /* builds a link that goes to the title listings for a metarecord */
474 function buildTitleLink(rec, link) {
476 link.appendChild(text(normalize(truncate(rec.title(), 65))));
479 args[PARAM_OFFSET] = 0;
480 args[PARAM_MRID] = rec.doc_id();
481 args[PARAM_RTYPE] = RTYPE_MRID;
482 var linkText = link.innerHTML; // IE
483 link.setAttribute("href", buildOPACLink(args));
484 link.innerHTML = linkText; // IE
487 function buildTitleDetailLink(rec, link) {
489 link.appendChild(text(normalize(truncate(rec.title(), 65))));
492 args[PARAM_RID] = rec.doc_id();
493 // in IE, if the link text contains a '@', it replaces the innerHTML text
494 // with the value of the href attribute. Wait, what? Yes. Capture the
495 // innerHTML and put it back into place after the href is set
496 var linkText = link.innerHTML; // IE
497 link.setAttribute("href", buildOPACLink(args));
498 link.innerHTML = linkText; // IE
501 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
502 'trunc' is the number of characters to show in the string, defaults to 65 */
503 function buildSearchLink(type, string, linknode, trunc) {
504 if(!trunc) trunc = 65;
506 if( SHOW_MR_DEFAULT || findCurrentPage() == MRESULT ) {
510 args[PARAM_RTYPE] = type;
512 args[PARAM_OFFSET] = 0;
513 args[PARAM_TERM] = string;
514 args[PARAM_STYPE] = type;
515 linknode.appendChild(text(normalize(truncate(string, trunc))));
516 linknode.setAttribute("href", buildOPACLink(args));
519 function setSessionCookie(ses) {
520 dojo.cookie(COOKIE_SES, ses, {'secure':'true'});
525 /* ----------------------------------------------------------------------- */
526 /* user session handling */
527 /* ----------------------------------------------------------------------- */
528 /* session is the login session. If no session is provided, we attempt
529 to find one in the cookies. If 'force' is true we retrieve the
530 user from the server even if there is already a global user present.
531 if ses != G.user.session, we also force a grab */
532 function grabUser(ses, force) {
534 _debug("grabUser auth token = " + ses);
535 if(!ses && isXUL()) {
536 stash = fetchXULStash();
537 ses = stash.session.key
538 _debug("stash auth token = " + ses);
542 ses = dojo.cookie(COOKIE_SES);
543 /* https cookies don't show up in http servers.. */
544 _debug("cookie auth token = " + ses);
547 if(!ses) return false;
550 if(G.user && G.user.session == ses)
553 /* first make sure the session is valid */
554 var request = new Request(FETCH_SESSION, ses);
555 request.request.alertEvent = false;
557 var user = request.result();
559 if(!user || user.textcode == 'NO_SESSION') {
562 dojo.require('openils.XUL');
563 dump('getNewSession in opac_utils.js\n');
564 openils.XUL.getNewSession(
565 function(success, authtoken) {
568 var request = new Request(FETCH_SESSION, ses);
569 request.request.alertEvent = false;
571 user = request.result();
577 if(!user || user.textcode == 'NO_SESSION') {
579 return false; /* unable to grab the session */
583 if( !(typeof user == 'object' && user._isfieldmapper) ) {
589 G.user.fleshed = false;
590 G.user.session = ses;
591 setSessionCookie(ses);
594 if(G.user.prefs['opac.hits_per_page'])
595 COUNT = parseInt(G.user.prefs['opac.hits_per_page']);
597 if(G.user.prefs[PREF_DEF_FONT])
598 setFontSize(G.user.prefs[PREF_DEF_FONT]);
600 var at = getAuthtime();
601 //if(isXUL()) at = xulG['authtime'];
603 if(at && !isXUL()) new AuthTimer(at).run();
608 /* sets the 'prefs' field of the user object to their preferences
609 and returns the preferences */
610 function grabUserPrefs(user, force) {
611 if(user == null) user = G.user;
612 if(!force && user.prefs) return user.prefs;
613 var req = new Request(FETCH_USER_PREFS, G.user.session, user.id());
615 user.prefs = req.result();
619 function grabFleshedUser() {
621 if(!G.user || !G.user.session) {
623 if(!G.user || !G.user.session) return null;
626 if(G.user.fleshed) return G.user;
628 var req = new Request(FETCH_FLESHED_USER, G.user.session);
631 G.user = req.result();
633 if(!G.user || G.user.length == 0) {
634 dojo.cookie(COOKIE_SES,null,{'expires':-1});
635 G.user = null; return false;
638 G.user.session = ses;
639 G.user.fleshed = true;
641 setSessionCookie(ses);
645 function checkUserSkin(new_skin) {
647 return; /* XXX do some debugging with this... */
649 var user_skin = getSkin();
650 var cur_skin = grabSkinFromURL();
652 if(new_skin) user_skin = new_skin;
657 if(grabUserPrefs()) {
658 user_skin = G.user.prefs["opac.skin"];
659 dojo.cookie( COOKIE_SKIN, user_skin, { 'expires' : 365 } );
664 if(!user_skin) return;
666 if( cur_skin != user_skin ) {
667 var url = buildOPACLink();
668 goTo(url.replace(cur_skin, user_skin));
672 function updateUserSetting(setting, value, user) {
673 if(user == null) user = G.user;
676 var req = new Request( UPDATE_USER_PREFS, user.session, a );
681 function commitUserPrefs() {
682 var req = new Request(
683 UPDATE_USER_PREFS, G.user.session, null, G.user.prefs );
688 function grabSkinFromURL() {
689 var path = findBasePath();
690 path = path.replace("/xml/", "");
692 for( var i = path.length - 1; i >= 0; i-- ) {
693 var ch = path.charAt(i);
699 for( i = skin.length - 1; i >= 0; i--)
700 skin2 += skin.charAt(i);
706 /* returns a fleshed G.user on success, false on failure */
707 function doLogin(suppressEvents) {
711 var auth_proxy_enabled = false;
712 var auth_proxy_enabled_request = new Request( AUTH_PROXY_ENABLED );
713 auth_proxy_enabled_request.request.alertEvent = false;
714 auth_proxy_enabled_request.send(true);
715 if (auth_proxy_enabled_request.result() == 1) {
716 auth_proxy_enabled = true;
719 var uname = G.ui.login.username.value;
720 var passwd = G.ui.login.password.value;
724 org : getOrigLocation(),
728 r = fetchOrgSettingDefault(globalOrgTree.id(), 'opac.barcode_regex');
729 if(r) REGEX_BARCODE = new RegExp(r);
731 if( uname.match(REGEX_BARCODE) ) args.barcode = uname;
732 else args.username = uname;
735 if (!auth_proxy_enabled) {
736 var init_request = new Request( LOGIN_INIT, uname );
737 init_request.send(true);
738 var seed = init_request.result();
740 if( ! seed || seed == '0') {
741 alert( "Error Communicating with Authentication Server" );
745 args.password = hex_md5(seed + hex_md5(passwd));
746 auth_request = new Request( LOGIN_COMPLETE, args );
748 args.password = passwd;
749 auth_request = new Request( AUTH_PROXY_LOGIN, args );
752 auth_request.request.alertEvent = false;
753 auth_request.send(true);
754 var auth_result = auth_request.result();
757 alertId('patron_login_failed');
761 if( checkILSEvent(auth_result) ) {
763 if( auth_result.textcode == 'PATRON_INACTIVE' ) {
764 alertId('patron_inactive_alert');
768 if( auth_result.textcode == 'PATRON_CARD_INACTIVE' ) {
769 alertId('patron_card_inactive_alert');
773 if( auth_result.textcode == 'LOGIN_FAILED' ||
774 auth_result.textcode == 'PERM_FAILURE' ) {
775 alertId('patron_login_failed');
781 AUTHTIME = parseInt(auth_result.payload.authtime);
782 var u = grabUser(auth_result.payload.authtoken, true);
783 if(u && ! suppressEvents)
784 runEvt( "common", "locationChanged", u.ws_ou(), findOrgDepth(u.ws_ou()) );
791 function doLogout() {
793 /* cancel everything else */
796 /* be nice and delete the session from the server */
797 if(G.user && G.user.session) {
798 var req = new Request(LOGIN_DELETE, G.user.session);
800 try { req.result(); } catch(E){}
805 /* remove any cached data */
806 dojo.require('dojo.cookie');
807 dojo.cookie(COOKIE_SES, null, {expires:-1});
808 dojo.cookie(COOKIE_RIDS, null, {expires:-1});
809 dojo.cookie(COOKIE_SKIN, null, {expires:-1});
810 dojo.cookie(COOKIE_SEARCH, null, {expires:-1});
813 checkUserSkin("default");
818 args[PARAM_TERM] = "";
819 args[PARAM_LOCATION] = getOrigLocation();
820 args[PARAM_DEPTH] = findOrgDepth(getOrigLocation() || globalOrgTree);
825 try{ if(isFrontPage) nored = true; } catch(e){nored = false;}
826 if(!nored) goTo(buildOPACLink(args, false, false));
830 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
831 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
834 /* ----------------------------------------------------------------------- */
835 /* build the org tree */
836 /* ----------------------------------------------------------------------- */
837 function drawOrgTree() {
838 //setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 10 );
839 setTimeout( 'buildOrgSelector(G.ui.common.org_tree, orgTreeSelector);', 1 );
842 var checkOrgHiding_cached = false;
843 var checkOrgHiding_cached_context_org;
844 var checkOrgHiding_cached_depth;
845 function checkOrgHiding() {
847 return false; // disable org hiding for staff client
849 var context_org = getOrigLocation() || globalOrgTree.id();
851 if (checkOrgHiding_cached) {
852 if (checkOrgHiding_cached_context_org != context_org) {
853 checkOrgHiding_cached_context_org = context_org;
854 checkOrgHiding_cached_depth = undefined;
855 checkOrgHiding_cached = false;
857 depth = checkOrgHiding_cached_depth;
860 depth = fetchOrgSettingDefault( context_org, 'opac.org_unit_hiding.depth');
861 checkOrgHiding_cached_depth = depth;
862 checkOrgHiding_cached_context_org = context_org;
863 checkOrgHiding_cached = true;
865 if ( findOrgDepth( context_org ) < depth ) {
866 return false; // disable org hiding if Original Location doesn't make sense with setting depth (avoids disjointed org selectors)
869 return { 'org' : findOrgUnit(context_org), 'depth' : depth };
876 function buildOrgSelector(node) {
877 var tree = new SlimTree(node,'orgTreeSelector');
878 orgTreeSelector = tree;
879 var orgHiding = checkOrgHiding();
880 for (var i = 0; i < orgArraySearcherOrder.length; i++) {
881 var node = orgArraySearcher[orgArraySearcherOrder[i]];
882 if( node == null ) continue;
883 if(!isXUL() && !isTrue(node.opac_visible())) continue;
885 if ( ! orgIsMine( orgHiding.org, node, orgHiding.depth ) ) {
889 if(node.parent_ou() == null) {
890 tree.addNode(node.id(), -1, node.name(),
891 "javascript:orgSelect(" + node.id() + ");", node.name());
893 if (orgHiding && orgHiding.depth == findOrgDepth(node)) {
894 tree.addNode(node.id(), -1, node.name(),
895 "javascript:orgSelect(" + node.id() + ");", node.name());
897 tree.addNode(node.id(), node.parent_ou(), node.name(),
898 "javascript:orgSelect(" + node.id() + ");", node.name());
902 hideMe($('org_loading_div'));
903 unHideMe($('org_selector_tip'));
907 function orgSelect(id) {
909 runEvt("common", "locationChanged", id, findOrgDepth(id) );
912 var loc = findOrgLasso(getLasso());
913 if (!loc) loc = findOrgUnit(id);
915 removeChildren(G.ui.common.now_searching);
916 G.ui.common.now_searching.appendChild(text(loc.name()));
919 function setFontSize(size) {
921 dojo.cookie(COOKIE_FONT, size, { 'expires' : 365});
924 var resourceFormats = [
927 "sound recording", "software, multimedia",
932 "three dimensional object" ];
935 function modsFormatToMARC(format) {
941 case "sound recording":
943 case "sound recording-nonmusical":
945 case "sound recording-musical":
947 case "software, multimedia":
953 case "mixed material":
955 case "notated music":
957 case "three dimensional object":
964 function MARCFormatToMods(format) {
970 return "moving image";
972 return "sound recording-nonmusical";
974 return "sound recording-musical";
976 return "software, multimedia";
978 return "still image";
981 return "cartographic";
984 return "mixed material";
987 return "notated music";
989 return "three dimensional object";
994 function MARCTypeToFriendly(format) {
995 var words = $('format_words');
998 case 't' : return $n(words, 'at').innerHTML;
1000 var node = $n(words,format);
1001 if( node ) return node.innerHTML;
1006 function setResourcePic( img, resource ) {
1007 img.setAttribute( "src", "../../../../images/tor/" + resource + ".jpg");
1008 img.title = resource;
1013 function msg( text ) {
1014 try { alert( text ); } catch(e) {}
1017 function findRecord(id,type) {
1019 for( var i = 0; i != recordsCache.length; i++ ) {
1020 var rec = recordsCache[i];
1021 if( rec && rec.doc_id() == id ) return rec;
1024 var meth = FETCH_RMODS
1025 if(type == 'M') meth = FETCH_MRMODS;
1026 var req = new Request(meth, id);
1027 req.request.alertEvent = false;
1029 var res = req.result();
1030 if( checkILSEvent(res) ) return null;
1034 function Timer(name, node){
1039 Timer.prototype.start =
1040 function(){_timerRun(this.name);}
1041 Timer.prototype.stop =
1042 function(){this.done = true;}
1043 function _timerRun(tname) {
1047 if(_t.count > 100) return;
1049 if( (_t.count % 5) == 0 )
1051 _t.node.appendChild(text(str));
1052 setTimeout("_timerRun('"+tname+"');", 200);
1056 function checkILSEvent(obj) {
1057 if (obj && typeof obj == 'object' && typeof obj.ilsevent != 'undefined') {
1058 if (obj.ilsevent === '') {
1060 } else if ( obj.ilsevent != null && obj.ilsevent != 0 ) {
1061 return parseInt(obj.ilsevent);
1068 function alertILSEvent(evt, msg) {
1071 alert(msg +'\n' + evt.textcode + '\n' + evt.desc );
1073 alert(evt.textcode + '\n' + evt.desc );
1078 function AuthTimer(time) {
1079 this.time = (time - LOGOUT_WARNING_TIME) * 1000;
1081 try {clearTimeout(__authTimer.id)} catch(e){}
1085 AuthTimer.prototype.run = function() {
1086 this.id = setTimeout('_authTimerAlert()', this.time);
1089 function _authTimerAlert() {
1090 alert( $('auth_session_expiring').innerHTML );
1091 if(!grabUser(null, true)) doLogout();
1095 function grabUserByBarcode( authtoken, barcode ) {
1096 var req = new Request( FETCH_USER_BYBARCODE, authtoken, barcode );
1098 return req.result();
1103 goTo(buildOPACLink({page:HOME}));
1107 function buildOrgSel(selector, org, offset, namecol) {
1108 if(!namecol) namecol = 'name';
1109 if(!isXUL() && !isTrue(org.opac_visible())) return;
1110 insertSelectorVal( selector, -1,
1111 org[namecol](), org.id(), null, findOrgDepth(org) - offset );
1112 var kids = org.children();
1114 for( var c = 0; c < kids.length; c++ )
1115 buildOrgSel( selector, kids[c], offset, namecol);
1119 function buildMergedOrgSel(selector, org_list, offset, namecol) {
1120 if(!namecol) namecol = 'name';
1121 for(var i = 0; i < org_list.length; i++) {
1122 var org = findOrgUnit(org_list[i]);
1123 insertSelectorVal( selector, -1,
1124 org[namecol](), org.id(), null, findOrgDepth(org) - offset );
1125 var kids = org.children();
1127 for( var c = 0; c < kids.length; c++ )
1128 buildOrgSel( selector, kids[c], offset, namecol);
1134 function parseForm(form) {
1135 if(!form) return {};
1137 var it = form.replace(/-\w+$/,"");
1142 if(form.match(/-/)) itf = form.replace(/^\w+-/,"");
1146 for( var i = 0; i < it.length; i++ )
1147 item_type.push( it.charAt(i) );
1152 for( var i = 0; i < itf.length; i++ )
1153 item_form.push( itf.charAt(i) );
1156 return {item_type: item_type, item_form:item_form};
1160 function isTrue(x) { return ( x && x != "0" && !(x+'').match(/^f$/i) ); }
1162 function fetchPermOrgs() {
1163 var a = []; /* Q: why does arguments come accross as an object and not an array? A: because arguments is a special object, a collection */
1165 for( var i = 0; i < arguments.length; i++ )
1166 a.push(arguments[i])
1168 var preq = new Request(FETCH_HIGHEST_PERM_ORG,
1169 G.user.session, G.user.id(), a );
1171 return preq.result();
1175 function print_tabs(t) {
1177 for (var j = 0; j < t; j++ ) { r = r + " "; }
1180 function formatJSON(s) {
1181 var r = ''; var t = 0;
1183 if (s[i] == '{' || s[i] == '[' ) {
1184 r = r + s[i] + "\n" + print_tabs(++t);
1185 } else if (s[i] == '}' || s[i] == ']') {
1186 t--; r = r + "\n" + print_tabs(t) + s[i];
1187 } else if (s[i] == ',') {
1188 r = r + s[i] + "\n" + print_tabs(t);