3 /* - Request ------------------------------------------------------------- */
4 function Request(type) {
5 var s = type.split(":");
6 if(s[2] == "1" && isXUL()) s[1] += ".staff";
7 this.request = new RemoteRequest(s[0], s[1]);
8 for( var x = 1; x!= arguments.length; x++ )
9 this.request.addParam(arguments[x]);
12 Request.prototype.callback = function(cal) { this.request.setCompleteCallback(cal); }
13 Request.prototype.send = function(block){this.request.send(block);}
14 Request.prototype.result = function(){return this.request.getResultObject();}
15 /* ----------------------------------------------------------------------- */
17 function showCanvas() {
18 for( var x in G.ui.altcanvas ) {
19 hideMe(G.ui.altcanvas[x]);
21 hideMe(G.ui.common.loading);
22 unHideMe(G.ui.common.canvas_main);
23 G.ui.searchbar.text.focus();
26 function swapCanvas(newNode) {
27 for( var x in G.ui.altcanvas )
28 hideMe(G.ui.altcanvas[x]);
30 hideMe(G.ui.common.loading);
31 hideMe(G.ui.common.canvas_main);
35 /* finds the name of the current page */
36 var currentPage = null;
37 function findCurrentPage() {
38 if(currentPage) return currentPage;
41 for( var p in config.page ) pages.push(config.page[p]);
42 pages = pages.sort( function(a,b){ return - (a.length - b.length); } );
44 var path = location.pathname;
45 if(!path.match(/.*\.xml$/))
46 path += "index.xml"; /* in case they go to / */
49 for( var p in pages ) {
50 if( path.indexOf(pages[p]) != -1)
54 for( var p in config.page ) {
55 if(config.page[p] == page) {
65 /* sets all of the params values ----------------------------- */
66 function initParams() {
69 TERM = cgi.param(PARAM_TERM);
70 STYPE = cgi.param(PARAM_STYPE);
71 FORM = cgi.param(PARAM_FORM);
73 LOCATION = parseInt(cgi.param(PARAM_LOCATION));
74 ORIGLOC = parseInt(cgi.param(PARAM_ORIGLOC));
75 DEPTH = parseInt(cgi.param(PARAM_DEPTH));
76 OFFSET = parseInt(cgi.param(PARAM_OFFSET));
77 COUNT = parseInt(cgi.param(PARAM_COUNT));
78 HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT));
79 MRID = parseInt(cgi.param(PARAM_MRID));
80 RID = parseInt(cgi.param(PARAM_RID));
82 /* set up some sane defaults */
83 if(isNaN(LOCATION)) LOCATION = 1;
84 if(isNaN(DEPTH)) DEPTH = 0;
85 if(isNaN(OFFSET)) OFFSET = 0;
86 if(isNaN(COUNT)) COUNT = 10;
87 if(isNaN(HITCOUNT)) HITCOUNT = 0;
88 if(isNaN(MRID)) MRID = 0;
89 if(isNaN(RID)) RID = 0;
90 if(isNaN(ORIGLOC)) ORIGLOC = 0;
93 function initCookies() {
95 var font = fontCookie.get(COOKIE_FONT);
96 if(font) FONTSIZE = font;
97 SKIN = skinCookie.get(COOKIE_SKIN);
100 /* URL param accessors */
101 function getTerm(){return TERM;}
102 function getStype(){return STYPE;}
103 function getLocation(){return LOCATION;}
104 function getDepth(){return DEPTH;}
105 function getForm(){return FORM;}
106 function getOffset(){return OFFSET;}
107 function getDisplayCount(){return COUNT;}
108 function getHitCount(){return HITCOUNT;}
109 function getMrid(){return MRID;};
110 function getRid(){return RID;};
111 function getOrigLocation(){return ORIGLOC;}
113 function getSearchBarExtras(){return SBEXTRAS;}
114 function getFontSize(){return FONTSIZE;};
115 function getSkin(){return SKIN;};
119 /* builds an opac URL. If no page is defined, the current page is used
120 if slim, then only everything after the ? is returned (no host portion) */
121 function findBasePath() {
122 var path = location.pathname;
123 if(!path.match(/.*\.xml$/)) path += "index.xml";
124 var idx = path.indexOf(config.page[findCurrentPage()]);
125 return path.substring(0, idx);
128 function findBaseURL(ssl) {
129 var path = findBasePath();
130 var proto = location.protocol;
131 if(ssl) proto = "https:";
132 return proto + "//" + location.host + path;
135 function buildImageLink(name, ssl) {
136 return findBaseURL(ssl) + "../../../images/" + name;
139 function buildOPACLink(args, slim, ssl) {
145 string = findBaseURL(ssl);
146 if(args.page) string += config.page[args.page];
147 else string += config.page[findCurrentPage()];
152 for( var x in args ) {
153 if(x == "page" || args[x] == null) continue;
154 string += "&" + x + "=" + encodeURIComponent(args[x]);
157 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
158 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
159 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
160 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
161 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
162 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
163 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
164 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
165 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
166 string += _appendParam(RID, PARAM_RID, args, getRid, string);
167 return string.replace(/\&$/,'').replace(/\?\&/,"?");
170 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
172 if( fieldVar != null && overrideArgs[fieldName] == null )
173 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
179 function EX(message) { this.init(message); }
180 EX.prototype.init = function(message) { this.message = message; }
181 EX.prototype.toString = function() { return "\n *** Exception Occured \n" + this.message; }
182 EXCommunication.prototype = new EX();
183 EXCommunication.prototype.constructor = EXCommunication;
184 EXCommunication.baseClass = EX.prototype.constructor;
185 function EXCommunication(message) { this.init("EXCommunication: " + message); }
188 /* ----------------------------------------------------------------------- */
189 function cleanISBN(isbn) {
191 isbn = isbn.toString().replace(/^\s+/,"");
192 var idx = isbn.indexOf(" ");
193 if(idx > -1) { isbn = isbn.substring(0, idx); }
201 /* builds a link that goes to the title listings for a metarecord */
202 function buildTitleLink(rec, link) {
204 link.appendChild(text(normalize(truncate(rec.title(), 65))));
207 args[PARAM_OFFSET] = 0;
208 args[PARAM_MRID] = rec.doc_id();
209 link.setAttribute("href", buildOPACLink(args));
212 function buildTitleDetailLink(rec, link) {
214 link.appendChild(text(normalize(truncate(rec.title(), 65))));
217 args[PARAM_OFFSET] = 0;
218 args[PARAM_RID] = rec.doc_id();
219 link.setAttribute("href", buildOPACLink(args));
222 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
223 'trunc' is the number of characters to show in the string, defaults to 65 */
224 function buildSearchLink(type, string, linknode, trunc) {
225 if(!trunc) trunc = 65;
228 args[PARAM_OFFSET] = 0;
229 args[PARAM_TERM] = string;
230 args[PARAM_STYPE] = type;
231 linknode.appendChild(text(normalize(truncate(string, trunc))));
232 linknode.setAttribute("href", buildOPACLink(args));
236 /* ----------------------------------------------------------------------- */
237 /* user session handling */
238 /* ----------------------------------------------------------------------- */
240 /* session is the login session. If no session is provided, we attempt
241 to find one in the cookies. If 'force' is true we retrieve the
242 user from the server even if there is already a global user present.
243 if ses != G.user.session, we also force a grab */
244 var cookie = new cookieObject("ses", 1, "/", COOKIE_SES);
245 function grabUser(ses, force) {
247 if(!ses) ses = cookie.get(COOKIE_SES);
248 if(!ses) return false;
251 if(G.user && G.user.session == ses)
254 /* first make sure the session is valid */
255 var request = new Request(FETCH_SESSION, ses );
257 var user = request.result();
258 if( !(typeof user == 'object' && user._isfieldmapper) ) {
263 G.user.fleshed = false;
264 G.user.session = ses;
265 cookie.put(COOKIE_SES, ses);
272 /* sets the 'prefs' field of the user object to their preferences
273 and returns the preferences */
274 function grabUserPrefs(user, force) {
275 if(user == null) user = G.user;
276 if(!force && user.prefs) return user.prefs;
277 var req = new Request(FETCH_USER_PREFS, user.session, user.id());
279 user.prefs = req.result();
283 function grabFleshedUser() {
285 if(!G.user || !G.user.session) {
287 if(!G.user || !G.user.session) return null;
290 if(G.user.fleshed) return G.user;
292 var req = new Request(FETCH_FLESHED_USER, G.user.session);
295 G.user = req.result();
297 if(!G.user || G.user.length == 0) {
298 G.user = null; return false;
299 cookie.remove(COOKIE_SES);
302 G.user.session = ses;
303 G.user.fleshed = true;
305 cookie.put(COOKIE_SES, ses); /* update the cookie */
311 var skinCookie = new cookieObject("skin", 1, "/", COOKIE_SKIN);
312 function checkUserSkin(new_skin) {
314 var user_skin = getSkin();
315 var cur_skin = grabSkinFromURL();
317 if(new_skin) user_skin = new_skin;
319 if(isNull(user_skin)) {
322 if(grabUserPrefs()) {
323 user_skin = G.user.prefs["opac.skin"];
324 skinCookie.put( COOKIE_SKIN, user_skin );
330 if(isNull(user_skin)) return;
332 if( cur_skin != user_skin ) {
333 var url = buildOPACLink();
334 goTo(url.replace(cur_skin, user_skin));
338 function updateUserSetting(setting, value, user) {
339 if(user == null) user = G.user;
342 var req = new Request( UPDATE_USER_PREFS, user.session, a );
347 function grabSkinFromURL() {
348 var path = findBasePath();
349 path = path.replace("/xml/", "");
351 for( var i = path.length - 1; i >= 0; i-- ) {
352 var ch = path.charAt(i);
358 for( i = skin.length - 1; i >= 0; i--)
359 skin2 += skin.charAt(i);
365 /* returns a fleshed G.user on success, false on failure */
368 var uname = G.ui.login.username.value;
369 var passwd = G.ui.login.password.value;
371 var init_request = new Request( LOGIN_INIT, uname );
372 init_request.send(true);
373 var seed = init_request.result();
375 if( ! seed || seed == '0') {
376 alert( "Error Communicating with Authentication Server" );
380 var auth_request = new Request( LOGIN_COMPLETE,
381 uname, hex_md5(seed + hex_md5(passwd)), "opac");
383 auth_request.send(true);
384 var auth_result = auth_request.result();
386 if(auth_result == '0' || auth_result == null || auth_result.length == 0) { return false; }
388 var u = grabUser(auth_result, true);
389 if(u) updateLoc(u.home_ou(), findOrgDepth(u.home_ou()));
396 function doLogout() {
398 /* be nice and delete the session from the server */
399 if(G.user && G.user.session) {
400 var req = new Request(LOGIN_DELETE, G.user.session);
402 try { req.result(); } catch(E){}
406 cookie.remove(COOKIE_SES);
408 hideMe(G.ui.sidebar.logoutbox);
409 unHideMe(G.ui.sidebar.loginbox);
410 hideMe(G.ui.sidebar.logged_in_as);
411 skinCookie.remove(COOKIE_SKIN);
413 checkUserSkin("default");
417 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
418 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
421 /* ----------------------------------------------------------------------- */
422 /* build the org tree */
423 /* ----------------------------------------------------------------------- */
424 function drawOrgTree() {
425 G.ui.common.org_tree.innerHTML = buildOrgSelector().toString();
429 function buildOrgSelector() {
430 var tree = new dTree("orgTreeSelector");
431 for( var i in orgArraySearcher ) {
432 var node = orgArraySearcher[i];
433 if( node == null ) continue;
434 if(node.parent_ou() == null)
435 tree.add(node.id(), -1, node.name(),
436 "javascript:orgSelect(" + node.id() + ");", node.name());
438 tree.add(node.id(), findOrgUnit(node.parent_ou()).id(), node.name(),
439 "javascript:orgSelect(" + node.id() + ");", node.name());
442 orgTreeSelector = tree;
446 function orgSelect(id) {
448 updateLoc(id, findOrgDepth(id));
451 var fontCookie = new cookieObject("fonts", 1, "/", COOKIE_FONT);
452 function setFontSize(size) {
454 fontCookie.put(COOKIE_FONT, size);
459 /* ----------------------------------------------------------------------- */
460 /* resource icon code */
461 /* ----------------------------------------------------------------------- */
463 var resourceFormats = [
466 "sound recording", "software, multimedia",
471 "three dimensional object" ];
474 function modsFormatToMARC(format) {
480 case "sound recording":
482 case "sound recording-nonmusical":
484 case "sound recording-musical":
486 case "software, multimedia":
492 case "mixed material":
494 case "notated music":
496 case "three dimensional object":
503 function MARCFormatToMods(format) {
509 return "moving image";
511 return "sound recording-nonmusical";
513 return "sound recording-musical";
515 return "software, multimedia";
517 return "still images";
520 return "cartographic";
523 return "mixed material";
526 return "notated music";
528 return "three dimensional object";
534 function setResourcePic( img, resource ) {
535 img.setAttribute( "src", "../../../images/tor/" + resource + ".jpg");
536 img.title = resource;