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();
28 function swapCanvas(newNode) { newCanvasNode = newNode; setTimeout(_swapCanvas, 200); }
29 function _swapCanvas() {
30 for( var x in G.ui.altcanvas )
31 hideMe(G.ui.altcanvas[x]);
33 hideMe(G.ui.common.loading);
34 hideMe(G.ui.common.canvas_main);
35 unHideMe(newCanvasNode);
38 /* finds the name of the current page */
39 var currentPage = null;
40 function findCurrentPage() {
41 if(currentPage) return currentPage;
44 for( var p in config.page ) pages.push(config.page[p]);
45 pages = pages.sort( function(a,b){ return - (a.length - b.length); } );
47 var path = location.pathname;
48 if(!path.match(/.*\.xml$/))
49 path += "index.xml"; /* in case they go to / */
52 for( var p in pages ) {
53 if( path.indexOf(pages[p]) != -1)
57 for( var p in config.page ) {
58 if(config.page[p] == page) {
68 /* sets all of the params values ----------------------------- */
69 var TERM, STYPE, LOCATION, DEPTH, FORM, OFFSET, COUNT,
70 HITCOUNT, RANKS, SEARCHBAR_EXTRAS, FONTSIZE;
72 function initParams() {
75 TERM = cgi.param(PARAM_TERM);
76 STYPE = cgi.param(PARAM_STYPE);
77 FORM = cgi.param(PARAM_FORM);
79 LOCATION = parseInt(cgi.param(PARAM_LOCATION));
80 DEPTH = parseInt(cgi.param(PARAM_DEPTH));
81 OFFSET = parseInt(cgi.param(PARAM_OFFSET));
82 COUNT = parseInt(cgi.param(PARAM_COUNT));
83 HITCOUNT = parseInt(cgi.param(PARAM_HITCOUNT));
84 MRID = parseInt(cgi.param(PARAM_MRID));
85 RID = parseInt(cgi.param(PARAM_RID));
87 /* set up some sane defaults */
88 if(isNaN(LOCATION)) LOCATION = 1;
89 if(isNaN(DEPTH)) DEPTH = 0;
90 if(isNaN(OFFSET)) OFFSET = 0;
91 if(isNaN(COUNT)) COUNT = 10;
92 if(isNaN(HITCOUNT)) HITCOUNT = 0;
93 if(isNaN(SEARCHBAR_EXTRAS)) SEARCHBAR_EXTRAS = 0;
94 if(isNaN(MRID)) MRID = 0;
95 if(isNaN(RID)) RID = 0;
98 function initCookies() {
100 var font = fontCookie.get(COOKIE_FONT);
101 if(font) FONTSIZE = font;
104 /* URL param accessors */
105 function getTerm(){return TERM;}
106 function getStype(){return STYPE;}
107 function getLocation(){return LOCATION;}
108 function getDepth(){return DEPTH;}
109 function getForm(){return FORM;}
110 function getOffset(){return OFFSET;}
111 function getDisplayCount(){return COUNT;}
112 function getHitCount(){return HITCOUNT;}
113 function getSearchBarExtras(){return SEARCHBAR_EXTRAS;}
114 function getMrid(){return MRID;};
115 function getRid(){return RID;};
117 function getFontSize(){return FONTSIZE;};
121 /* builds an opac URL. If no page is defined, the current page is used
122 if slim, then only everything after the ? is returned (no host portion) */
123 function findBasePath() {
124 var path = location.pathname;
125 if(!path.match(/.*\.xml$/)) path += "index.xml";
126 var idx = path.indexOf(config.page[findCurrentPage()]);
127 return path.substring(0, idx);
130 function findBaseURL(ssl) {
131 var path = findBasePath();
132 var proto = location.protocol;
133 if(ssl) proto = "https";
134 return location.protocol + "//" + location.host + path;
137 function buildImageLink(name, ssl) {
138 return findBaseURL(ssl) + "../../../images/" + name;
141 function buildOPACLink(args, slim, ssl) {
147 string = findBaseURL(ssl);
148 if(args.page) string += config.page[args.page];
149 else string += config.page[findCurrentPage()];
154 for( var x in args ) {
155 if(x == "page" || args[x] == null) continue;
156 string += "&" + x + "=" + encodeURIComponent(args[x]);
159 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
160 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
161 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
162 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
163 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
164 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
165 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
166 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
167 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
168 string += _appendParam(RID, PARAM_RID, args, getRid, string);
169 return string.replace(/\&$/,'').replace(/\?\&/,"?");
172 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
174 if( fieldVar != null && overrideArgs[fieldName] == null )
175 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
181 function EX(message) { this.init(message); }
182 EX.prototype.init = function(message) { this.message = message; }
183 EX.prototype.toString = function() { return "\n *** Exception Occured \n" + this.message; }
184 EXCommunication.prototype = new EX();
185 EXCommunication.prototype.constructor = EXCommunication;
186 EXCommunication.baseClass = EX.prototype.constructor;
187 function EXCommunication(message) { this.init("EXCommunication: " + message); }
190 /* ----------------------------------------------------------------------- */
191 function cleanISBN(isbn) {
193 isbn = isbn.toString().replace(/^\s+/,"");
194 var idx = isbn.indexOf(" ");
195 if(idx > -1) { isbn = isbn.substring(0, idx); }
203 /* builds a link that goes to the title listings for a metarecord */
204 function buildTitleLink(rec, link) {
206 link.appendChild(text(normalize(truncate(rec.title(), 65))));
209 args[PARAM_OFFSET] = 0;
210 args[PARAM_MRID] = rec.doc_id();
211 link.setAttribute("href", buildOPACLink(args));
214 function buildTitleDetailLink(rec, link) {
216 link.appendChild(text(normalize(truncate(rec.title(), 65))));
219 args[PARAM_OFFSET] = 0;
220 args[PARAM_RID] = rec.doc_id();
221 link.setAttribute("href", buildOPACLink(args));
224 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
225 'trunc' is the number of characters to show in the string, defaults to 65 */
226 function buildSearchLink(type, string, linknode, trunc) {
227 if(!trunc) trunc = 65;
230 args[PARAM_OFFSET] = 0;
231 args[PARAM_TERM] = string;
232 args[PARAM_STYPE] = type;
233 linknode.appendChild(text(normalize(truncate(string, trunc))));
234 linknode.setAttribute("href", buildOPACLink(args));
238 /* ----------------------------------------------------------------------- */
239 /* user session handling */
240 /* ----------------------------------------------------------------------- */
242 /* session is the login session. If no session is provided, we attempt
243 to find one in the cookies. If 'force' is true we retrieve the
244 user from the server even if there is already a global user present.
245 if ses != G.user.session, we also force a grab */
246 var cookie = new cookieObject("ses", 1, "/", COOKIE_SES);
247 function grabUser(ses, force) {
249 if(!ses) ses = cookie.get(COOKIE_SES);
250 if(!ses) return false;
253 if(G.user && G.user.session == ses)
256 /* first make sure the session is valid */
257 var request = new Request(FETCH_SESSION, ses );
259 var user = request.result();
260 if( !(typeof user == 'object' && user._isfieldmapper) ) {
265 G.user.fleshed = false;
266 G.user.session = ses;
267 cookie.put(COOKIE_SES, ses);
274 function grabFleshedUser() {
276 if(!G.user || !G.user.session) {
278 if(!G.user || !G.user.session) return null;
281 if(G.user.fleshed) return G.user;
283 var req = new Request(FETCH_FLESHED_USER, G.user.session);
286 G.user = req.result();
288 if(!G.user || G.user.length == 0) {
289 G.user = null; return false;
290 cookie.remove(COOKIE_SES);
293 G.user.session = ses;
294 G.user.fleshed = true;
296 cookie.put(COOKIE_SES, ses); /* update the cookie */
303 /* returns a fleshed G.user on success, false on failure */
306 var uname = G.ui.login.username.value;
307 var passwd = G.ui.login.password.value;
309 var init_request = new Request( LOGIN_INIT, uname );
310 init_request.send(true);
311 var seed = init_request.result();
313 if( ! seed || seed == '0') {
314 alert( "Error Communicating with Authentication Server" );
318 var auth_request = new Request( LOGIN_COMPLETE,
319 uname, hex_md5(seed + hex_md5(passwd)), "opac");
321 auth_request.send(true);
322 var auth_result = auth_request.result();
324 if(auth_result == '0' || auth_result == null || auth_result.length == 0) { return false; }
326 var u = grabUser(auth_result, true);
327 if(u) updateLoc(u.home_ou(), findOrgDepth(u.home_ou()));
332 function doLogout() {
334 /* be nice and delete the session from the server */
335 if(G.user && G.user.session) {
336 var req = new Request(LOGIN_DELETE, G.user.session);
338 try { req.result(); } catch(E){}
342 cookie.remove(COOKIE_SES);
344 hideMe(G.ui.sidebar.logoutbox);
345 unHideMe(G.ui.sidebar.loginbox);
346 hideMe(G.ui.sidebar.logged_in_as);
351 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
352 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
355 /* ----------------------------------------------------------------------- */
356 /* build the org tree */
357 /* ----------------------------------------------------------------------- */
360 function drawOrgTree() {
361 G.ui.common.org_tree.innerHTML = buildOrgSelector().toString();
365 function buildOrgSelector() {
366 var tree = new dTree("orgTreeSelector");
367 for( var i in orgArraySearcher ) {
368 var node = orgArraySearcher[i];
369 if( node == null ) continue;
370 if(node.parent_ou() == null)
371 tree.add(node.id(), -1, node.name(),
372 "javascript:orgSelect(" + node.id() + ");", node.name());
374 tree.add(node.id(), findOrgUnit(node.parent_ou()).id(), node.name(),
375 "javascript:orgSelect(" + node.id() + ");", node.name());
378 orgTreeSelector = tree;
382 function orgSelect(id) {
384 updateLoc(id, findOrgDepth(id));
387 var fontCookie = new cookieObject("fonts", 1, "/", COOKIE_FONT);
388 function setFontSize(size) {
390 fontCookie.put(COOKIE_FONT, size);