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() { setTimeout(_showCanvas, 200); }
18 function _showCanvas() {
19 for( var x in G.ui.altcanvas ) {
20 hideMe(G.ui.altcanvas[x]);
22 hideMe(G.ui.common.loading);
23 unHideMe(G.ui.common.canvas_main);
24 G.ui.searchbar.text.focus();
27 function swapCanvas(newNode) {
28 for( var x in G.ui.altcanvas )
29 hideMe(G.ui.altcanvas[x]);
31 hideMe(G.ui.common.loading);
32 hideMe(G.ui.common.canvas_main);
36 /* finds the name of the current page */
37 var currentPage = null;
38 function findCurrentPage() {
39 if(currentPage) return currentPage;
42 for( var p in config.page ) pages.push(config.page[p]);
43 pages = pages.sort( function(a,b){ return - (a.length - b.length); } );
45 var path = location.pathname;
46 if(!path.match(/.*\.xml$/))
47 path += "index.xml"; /* in case they go to / */
50 for( var p in pages ) {
51 if( path.indexOf(pages[p]) != -1)
55 for( var p in config.page ) {
56 if(config.page[p] == page) {
66 /* sets all of the params values ----------------------------- */
67 function initParams() {
70 TERM = cgi.param(PARAM_TERM);
71 STYPE = cgi.param(PARAM_STYPE);
72 FORM = cgi.param(PARAM_FORM);
74 LOCATION = parseInt(cgi.param(PARAM_LOCATION));
75 ORIGLOC = parseInt(cgi.param(PARAM_ORIGLOC));
76 DEPTH = parseInt(cgi.param(PARAM_DEPTH));
77 OFFSET = parseInt(cgi.param(PARAM_OFFSET));
78 COUNT = parseInt(cgi.param(PARAM_COUNT));
79 HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT));
80 MRID = parseInt(cgi.param(PARAM_MRID));
81 RID = parseInt(cgi.param(PARAM_RID));
83 /* set up some sane defaults */
84 if(isNaN(LOCATION)) LOCATION = 1;
85 if(isNaN(DEPTH)) DEPTH = 0;
86 if(isNaN(OFFSET)) OFFSET = 0;
87 if(isNaN(COUNT)) COUNT = 10;
88 if(isNaN(HITCOUNT)) HITCOUNT = 0;
89 if(isNaN(MRID)) MRID = 0;
90 if(isNaN(RID)) RID = 0;
91 if(isNaN(ORIGLOC)) ORIGLOC = 0;
94 function initCookies() {
96 var font = fontCookie.get(COOKIE_FONT);
97 if(font) FONTSIZE = font;
98 SKIN = skinCookie.get(COOKIE_SKIN);
101 /* URL param accessors */
102 function getTerm(){return TERM;}
103 function getStype(){return STYPE;}
104 function getLocation(){return LOCATION;}
105 function getDepth(){return DEPTH;}
106 function getForm(){return FORM;}
107 function getOffset(){return OFFSET;}
108 function getDisplayCount(){return COUNT;}
109 function getHitCount(){return HITCOUNT;}
110 function getMrid(){return MRID;};
111 function getRid(){return RID;};
112 function getOrigLocation(){return ORIGLOC;}
114 function getSearchBarExtras(){return SBEXTRAS;}
115 function getFontSize(){return FONTSIZE;};
116 function getSkin(){return SKIN;};
120 /* builds an opac URL. If no page is defined, the current page is used
121 if slim, then only everything after the ? is returned (no host portion) */
122 function findBasePath() {
123 var path = location.pathname;
124 if(!path.match(/.*\.xml$/)) path += "index.xml";
125 var idx = path.indexOf(config.page[findCurrentPage()]);
126 return path.substring(0, idx);
129 function findBaseURL(ssl) {
130 var path = findBasePath();
131 var proto = location.protocol;
132 if(ssl) proto = "https";
133 return location.protocol + "//" + location.host + path;
136 function buildImageLink(name, ssl) {
137 return findBaseURL(ssl) + "../../../images/" + name;
140 function buildOPACLink(args, slim, ssl) {
146 string = findBaseURL(ssl);
147 if(args.page) string += config.page[args.page];
148 else string += config.page[findCurrentPage()];
153 for( var x in args ) {
154 if(x == "page" || args[x] == null) continue;
155 string += "&" + x + "=" + encodeURIComponent(args[x]);
158 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
159 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
160 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
161 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
162 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
163 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
164 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
165 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
166 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
167 string += _appendParam(RID, PARAM_RID, args, getRid, string);
168 return string.replace(/\&$/,'').replace(/\?\&/,"?");
171 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
173 if( fieldVar != null && overrideArgs[fieldName] == null )
174 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
180 function EX(message) { this.init(message); }
181 EX.prototype.init = function(message) { this.message = message; }
182 EX.prototype.toString = function() { return "\n *** Exception Occured \n" + this.message; }
183 EXCommunication.prototype = new EX();
184 EXCommunication.prototype.constructor = EXCommunication;
185 EXCommunication.baseClass = EX.prototype.constructor;
186 function EXCommunication(message) { this.init("EXCommunication: " + message); }
189 /* ----------------------------------------------------------------------- */
190 function cleanISBN(isbn) {
192 isbn = isbn.toString().replace(/^\s+/,"");
193 var idx = isbn.indexOf(" ");
194 if(idx > -1) { isbn = isbn.substring(0, idx); }
202 /* builds a link that goes to the title listings for a metarecord */
203 function buildTitleLink(rec, link) {
205 link.appendChild(text(normalize(truncate(rec.title(), 65))));
208 args[PARAM_OFFSET] = 0;
209 args[PARAM_MRID] = rec.doc_id();
210 link.setAttribute("href", buildOPACLink(args));
213 function buildTitleDetailLink(rec, link) {
215 link.appendChild(text(normalize(truncate(rec.title(), 65))));
218 args[PARAM_OFFSET] = 0;
219 args[PARAM_RID] = rec.doc_id();
220 link.setAttribute("href", buildOPACLink(args));
223 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
224 'trunc' is the number of characters to show in the string, defaults to 65 */
225 function buildSearchLink(type, string, linknode, trunc) {
226 if(!trunc) trunc = 65;
229 args[PARAM_OFFSET] = 0;
230 args[PARAM_TERM] = string;
231 args[PARAM_STYPE] = type;
232 linknode.appendChild(text(normalize(truncate(string, trunc))));
233 linknode.setAttribute("href", buildOPACLink(args));
237 /* ----------------------------------------------------------------------- */
238 /* user session handling */
239 /* ----------------------------------------------------------------------- */
241 /* session is the login session. If no session is provided, we attempt
242 to find one in the cookies. If 'force' is true we retrieve the
243 user from the server even if there is already a global user present.
244 if ses != G.user.session, we also force a grab */
245 var cookie = new cookieObject("ses", 1, "/", COOKIE_SES);
246 function grabUser(ses, force) {
248 if(!ses) ses = cookie.get(COOKIE_SES);
249 if(!ses) return false;
252 if(G.user && G.user.session == ses)
255 /* first make sure the session is valid */
256 var request = new Request(FETCH_SESSION, ses );
258 var user = request.result();
259 if( !(typeof user == 'object' && user._isfieldmapper) ) {
264 G.user.fleshed = false;
265 G.user.session = ses;
266 cookie.put(COOKIE_SES, ses);
273 /* sets the 'prefs' field of the user object to their preferences
274 and returns the preferences */
275 function grabUserPrefs(user, force) {
276 if(user == null) user = G.user;
277 if(!force && user.prefs) return user.prefs;
278 var req = new Request(FETCH_USER_PREFS, user.session, user.id());
280 user.prefs = req.result();
284 function grabFleshedUser() {
286 if(!G.user || !G.user.session) {
288 if(!G.user || !G.user.session) return null;
291 if(G.user.fleshed) return G.user;
293 var req = new Request(FETCH_FLESHED_USER, G.user.session);
296 G.user = req.result();
298 if(!G.user || G.user.length == 0) {
299 G.user = null; return false;
300 cookie.remove(COOKIE_SES);
303 G.user.session = ses;
304 G.user.fleshed = true;
306 cookie.put(COOKIE_SES, ses); /* update the cookie */
312 var skinCookie = new cookieObject("skin", 1, "/", COOKIE_SKIN);
313 function checkUserSkin(new_skin) {
315 var user_skin = getSkin();
316 var cur_skin = grabSkinFromURL();
318 if(new_skin) user_skin = new_skin;
320 if(isNull(user_skin)) {
323 if(grabUserPrefs()) {
324 user_skin = G.user.prefs["opac.skin"];
325 skinCookie.put( COOKIE_SKIN, user_skin );
331 if(isNull(user_skin)) return;
333 if( cur_skin != user_skin ) {
334 var url = buildOPACLink();
335 goTo(url.replace(cur_skin, user_skin));
339 function updateUserSetting(setting, value, user) {
340 if(user == null) user = G.user;
343 var req = new Request( UPDATE_USER_PREFS, user.session, a );
348 function grabSkinFromURL() {
349 var path = findBasePath();
350 path = path.replace("/xml/", "");
352 for( var i = path.length - 1; i >= 0; i-- ) {
353 var ch = path.charAt(i);
359 for( i = skin.length - 1; i >= 0; i--)
360 skin2 += skin.charAt(i);
366 /* returns a fleshed G.user on success, false on failure */
369 var uname = G.ui.login.username.value;
370 var passwd = G.ui.login.password.value;
372 var init_request = new Request( LOGIN_INIT, uname );
373 init_request.send(true);
374 var seed = init_request.result();
376 if( ! seed || seed == '0') {
377 alert( "Error Communicating with Authentication Server" );
381 var auth_request = new Request( LOGIN_COMPLETE,
382 uname, hex_md5(seed + hex_md5(passwd)), "opac");
384 auth_request.send(true);
385 var auth_result = auth_request.result();
387 if(auth_result == '0' || auth_result == null || auth_result.length == 0) { return false; }
389 var u = grabUser(auth_result, true);
390 if(u) updateLoc(u.home_ou(), findOrgDepth(u.home_ou()));
397 function doLogout() {
399 /* be nice and delete the session from the server */
400 if(G.user && G.user.session) {
401 var req = new Request(LOGIN_DELETE, G.user.session);
403 try { req.result(); } catch(E){}
407 cookie.remove(COOKIE_SES);
409 hideMe(G.ui.sidebar.logoutbox);
410 unHideMe(G.ui.sidebar.loginbox);
411 hideMe(G.ui.sidebar.logged_in_as);
412 skinCookie.remove(COOKIE_SKIN);
414 checkUserSkin("default");
418 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
419 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
422 /* ----------------------------------------------------------------------- */
423 /* build the org tree */
424 /* ----------------------------------------------------------------------- */
427 function drawOrgTree() {
428 G.ui.common.org_tree.innerHTML = buildOrgSelector().toString();
432 function buildOrgSelector() {
433 var tree = new dTree("orgTreeSelector");
434 for( var i in orgArraySearcher ) {
435 var node = orgArraySearcher[i];
436 if( node == null ) continue;
437 if(node.parent_ou() == null)
438 tree.add(node.id(), -1, node.name(),
439 "javascript:orgSelect(" + node.id() + ");", node.name());
441 tree.add(node.id(), findOrgUnit(node.parent_ou()).id(), node.name(),
442 "javascript:orgSelect(" + node.id() + ");", node.name());
445 orgTreeSelector = tree;
449 function orgSelect(id) {
451 updateLoc(id, findOrgDepth(id));
454 var fontCookie = new cookieObject("fonts", 1, "/", COOKIE_FONT);
455 function setFontSize(size) {
457 fontCookie.put(COOKIE_FONT, size);