2 function isXUL() { return IAMXUL; }
5 /* - Request ------------------------------------------------------------- */
6 function Request(type) {
7 var s = type.split(":");
8 if(s[2] == "1" && isXUL()) s[1] += ".staff";
9 this.request = new RemoteRequest(s[0], s[1]);
10 for( var x = 1; x!= arguments.length; x++ )
11 this.request.addParam(arguments[x]);
14 Request.prototype.callback = function(cal) { this.request.setCompleteCallback(cal); }
15 Request.prototype.send = function(block){this.request.send(block);}
16 Request.prototype.result = function(){return this.request.getResultObject();}
17 /* ----------------------------------------------------------------------- */
19 function showCanvas() { setTimeout(_showCanvas, 200); }
20 function _showCanvas() {
21 for( var x in G.ui.altcanvas ) {
22 hideMe(G.ui.altcanvas[x]);
24 hideMe(G.ui.common.loading);
25 unHideMe(G.ui.common.canvas_main);
26 G.ui.searchbar.text.focus();
30 function swapCanvas(newNode) { newCanvasNode = newNode; setTimeout(_swapCanvas, 200); }
31 function _swapCanvas() {
32 for( var x in G.ui.altcanvas )
33 hideMe(G.ui.altcanvas[x]);
35 hideMe(G.ui.common.loading);
36 hideMe(G.ui.common.canvas_main);
37 unHideMe(newCanvasNode);
40 /* finds the name of the current page */
41 function findCurrentPage() {
42 for( var p in config.page ) {
43 var path = location.pathname;
45 if(!path.match(/.*\.xml$/))
46 path += "index.xml"; /* in case they go to / */
48 if( config.page[p] == path)
55 /* builds an opac URL. If no page is defined, the current page is used
56 if slim, then only everything after the ? is returned (no host portion) */
57 function buildOPACLink(args, slim) {
62 var string = location.protocol + "//" + location.host;
63 if(args.page) string += config.page[args.page];
64 else string += config.page[findCurrentPage()];
69 for( var x in args ) {
70 if(x == "page" || args[x] == null) continue;
71 string += "&" + x + "=" + encodeURIComponent(args[x]);
74 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
75 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
76 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
77 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
78 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
79 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
80 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
81 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
82 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
83 string += _appendParam(RID, PARAM_RID, args, getRid, string);
84 return string.replace(/\&$/,'').replace(/\?\&/,"?");
87 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
89 if( fieldVar != null && overrideArgs[fieldName] == null )
90 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
95 function EX(message) { this.init(message); }
96 EX.prototype.init = function(message) { this.message = message; }
97 EX.prototype.toString = function() { return "\n *** Exception Occured \n" + this.message; }
98 EXCommunication.prototype = new EX();
99 EXCommunication.prototype.constructor = EXCommunication;
100 EXCommunication.baseClass = EX.prototype.constructor;
101 function EXCommunication(message) { this.init("EXCommunication: " + message); }
103 /* ----------------------------------------------------------------------- */
104 function cleanISBN(isbn) {
106 isbn = isbn.toString().replace(/^\s+/,"");
107 var idx = isbn.indexOf(" ");
108 if(idx > -1) { isbn = isbn.substring(0, idx); }
116 /* builds a link that goes to the title listings for a metarecord */
117 function buildTitleLink(rec, link) {
119 link.appendChild(text(normalize(truncate(rec.title(), 65))));
122 args[PARAM_OFFSET] = 0;
123 args[PARAM_MRID] = rec.doc_id();
124 link.setAttribute("href", buildOPACLink(args));
127 function buildTitleDetailLink(rec, link) {
129 link.appendChild(text(normalize(truncate(rec.title(), 65))));
132 args[PARAM_OFFSET] = 0;
133 args[PARAM_RID] = rec.doc_id();
134 link.setAttribute("href", buildOPACLink(args));
137 /* 'type' is one of STYPE_AUTHOR, STYPE_SUBJECT, ... found in config.js
138 'trunc' is the number of characters to show in the string, defaults to 65 */
139 function buildSearchLink(type, string, linknode, trunc) {
140 if(!trunc) trunc = 65;
143 args[PARAM_OFFSET] = 0;
144 args[PARAM_TERM] = string;
145 args[PARAM_STYPE] = type;
146 linknode.appendChild(text(normalize(truncate(string, trunc))));
147 linknode.setAttribute("href", buildOPACLink(args));
151 /* ----------------------------------------------------------------------- */
152 /* user session handling */
153 /* ----------------------------------------------------------------------- */
155 /* session is the login session. If no session is provided, we attempt
156 to find one in the cookies. If 'force' is true we retrieve the
157 user from the server even if there is already a global user present.
158 if ses != G.user.session, we also force a grab */
159 var cookie = new cookieObject("ses", 1, "/", COOKIE_SES);
160 function grabUser(ses, force) {
162 if(!ses) ses = cookie.get(COOKIE_SES);
163 if(!ses) return false;
166 if(G.user && G.user.session == ses)
169 /* first make sure the session is valid */
170 var request = new Request(FETCH_SESSION, ses );
172 var user = request.result();
173 if( !(typeof user == 'object' && user._isfieldmapper) ) {
178 G.user.fleshed = false;
179 G.user.session = ses;
180 cookie.put(COOKIE_SES, ses);
187 function grabFleshedUser() {
189 if(!G.user || !G.user.session) {
191 if(!G.user || !G.user.session) return null;
194 if(G.user.fleshed) return G.user;
196 var req = new Request(FETCH_FLESHED_USER, G.user.session);
199 G.user = req.result();
201 if(!G.user || G.user.length == 0) {
202 G.user = null; return false;
203 cookie.remove(COOKIE_SES);
206 G.user.session = ses;
207 G.user.fleshed = true;
209 cookie.put(COOKIE_SES, ses); /* update the cookie */
216 /* returns a fleshed G.user on success, false on failure */
219 var uname = G.ui.login.username.value;
220 var passwd = G.ui.login.password.value;
222 var init_request = new Request( LOGIN_INIT, uname );
223 init_request.send(true);
224 var seed = init_request.result();
226 if( ! seed || seed == '0') {
227 alert( "Error Communicating with Authentication Server" );
231 var auth_request = new Request( LOGIN_COMPLETE,
232 uname, hex_md5(seed + hex_md5(passwd)), "opac");
234 auth_request.send(true);
235 var auth_result = auth_request.result();
237 if(auth_result == '0' || auth_result == null || auth_result.length == 0) { return false; }
239 var u = grabUser(auth_result, true);
240 if(u) updateLoc(u.home_ou(), findOrgDepth(u.home_ou()));
245 function doLogout() {
247 /* be nice and delete the session from the server */
248 if(G.user && G.user.session) {
249 var req = new Request(LOGIN_DELETE, G.user.session);
251 try { req.result(); } catch(E){}
255 cookie.remove(COOKIE_SES);
257 hideMe(G.ui.sidebar.logoutbox);
258 unHideMe(G.ui.sidebar.loginbox);
259 hideMe(G.ui.sidebar.logged_in_as);
264 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
265 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
268 /* ----------------------------------------------------------------------- */
269 /* build the org tree */
270 /* ----------------------------------------------------------------------- */
273 function buildOrgSelector() {
274 var tree = new dTree("orgTreeSelector");
275 for( var i in orgArraySearcher ) {
276 var node = orgArraySearcher[i];
277 if( node == null ) continue;
278 if(node.parent_ou() == null)
279 tree.add(node.id(), -1, node.name(),
280 "javascript:orgSelect(" + node.id() + ");", node.name());
282 tree.add(node.id(), node.parent_ou().id(), node.name(),
283 "javascript:orgSelect(" + node.id() + ");", node.name());
286 orgTreeSelector = tree;
290 function orgSelect(id) {
292 updateLoc(id, findOrgDepth(id));
296 /* ------------------------------------------------------------------------------------------------------ */
297 /* org tree utilities */
298 /* ------------------------------------------------------------------------------------------------------ */
300 /* takes an org unit or id and return the numeric depth */
301 function findOrgDepth(org_id_or_node) {
302 return findOrgType(findOrgUnit(org_id_or_node).ou_type()).depth();
305 /* takes the org type id from orgunit.ou_type() field and returns
306 the org type object */
307 function findOrgType(type_id) {
308 if(typeof type_id == 'object') return type_id;
309 for(var type in globalOrgTypes) {
310 var t =globalOrgTypes[type];
311 if( t.id() == type_id || t.id() == parseInt(type_id) )
318 /* returns an org unit by id. if an object is passed in as the id,
319 then the object is assumed to be an org unit and is returned */
320 function findOrgUnit(org_id) {
321 return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id];
325 /* builds a trail from the top of the org tree to the node provide.
326 basically fleshes out 'my orgs'
327 Returns an array of [org0, org1, ..., myorg] */
328 function orgNodeTrail(node) {
329 var na = new Array();
332 node = findOrgUnit(node.parent_ou());
338 /* returns an array of sibling org units */
339 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
340 /* ------------------------------------------------------------------------------------------------------ */