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 /* ----------------------------------------------------------------------- */
20 /* ----------------------------------------------------------------------- */
21 /* Functions for showing the canvas (and hiding any other shown stuff) */
22 /* ----------------------------------------------------------------------- */
23 function showCanvas() { setTimeout(_showCanvas, 200); }
24 function _showCanvas() {
25 for( var x in G.ui.altcanvas ) {
26 hideMe(G.ui.altcanvas[x]);
28 hideMe(G.ui.common.loading);
29 unHideMe(G.ui.common.canvas_main);
30 G.ui.searchbar.text.focus(); /* focus the searchbar */
35 function swapCanvas(newNode) { newCanvasNode = newNode; setTimeout(_swapCanvas, 200); }
36 function _swapCanvas() {
37 for( var x in G.ui.altcanvas )
38 hideMe(G.ui.altcanvas[x]);
40 hideMe(G.ui.common.loading);
41 hideMe(G.ui.common.canvas_main);
42 unHideMe(newCanvasNode);
44 /* ----------------------------------------------------------------------- */
47 /* finds the name of the current page */
48 function findCurrentPage() {
49 for( var p in config.page ) {
50 var path = location.pathname;
52 if(!path.match(/.*\.xml$/))
53 path += "index.xml"; /* in case they go to / */
55 if( config.page[p] == path)
62 /* builds an opac URL. If no page is defined, the current page is used
63 if slim, then only everything after the ? is returned (no host portion)
65 function buildOPACLink(args, slim) {
70 var string = location.protocol + "//" + location.host;
71 if(args.page) string += config.page[args.page];
72 else string += config.page[findCurrentPage()];
77 for( var x in args ) {
78 if(x == "page" || args[x] == null) continue;
79 string += "&" + x + "=" + encodeURIComponent(args[x]);
82 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
83 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
84 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
85 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
86 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
87 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
88 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
89 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
90 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
91 string += _appendParam(RID, PARAM_RID, args, getRid, string);
92 return string.replace(/\&$/,'').replace(/\?\&/,"?");
95 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
97 if( fieldVar != null && overrideArgs[fieldName] == null )
98 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
106 /* ----------------------------------------------------------------------- */
107 /* some useful exceptions */
108 function EX(message) { this.init(message); }
110 EX.prototype.init = function(message) {
111 this.message = message;
114 EX.prototype.toString = function() {
115 return "\n *** Exception Occured \n" + this.message;
118 EXCommunication.prototype = new EX();
119 EXCommunication.prototype.constructor = EXCommunication;
120 EXCommunication.baseClass = EX.prototype.constructor;
122 function EXCommunication(message) {
123 this.init("EXCommunication: " + message);
125 /* ----------------------------------------------------------------------- */
127 function cleanISBN(isbn) {
129 isbn = isbn.toString().replace(/^\s+/,"");
130 var idx = isbn.indexOf(" ");
131 if(idx > -1) { isbn = isbn.substring(0, idx); }
139 /* ----------------------------------------------------------------------- */
140 /* builds a link that goes to the title listings for a metarecord */
141 function buildTitleLink(rec, link) {
143 link.appendChild(text(normalize(truncate(rec.title(), 65))));
146 args[PARAM_OFFSET] = 0;
147 args[PARAM_MRID] = rec.doc_id();
148 link.setAttribute("href", buildOPACLink(args));
151 function buildTitleDetailLink(rec, link) {
153 link.appendChild(text(normalize(truncate(rec.title(), 65))));
156 args[PARAM_OFFSET] = 0;
157 args[PARAM_RID] = rec.doc_id();
158 link.setAttribute("href", buildOPACLink(args));
161 /* builds an author search link */
162 function buildAuthorLink(rec, link) {
164 link.appendChild(text(normalize(truncate(rec.author(), 65))));
167 args[PARAM_OFFSET] = 0;
168 args[PARAM_STYPE] = STYPE_AUTHOR;
169 args[PARAM_TERM] = rec.author();
170 link.setAttribute("href", buildOPACLink(args));
174 function buildSubjectLink(subject, link) {
175 if(subject == null) return;
176 link.appendChild(text(normalize(truncate(subject, 35))));
179 args[PARAM_OFFSET] = 0;
180 args[PARAM_STYPE] = STYPE_SUBJECT;
181 args[PARAM_TERM] = subject;
182 link.setAttribute("href", buildOPACLink(args));
184 /* ----------------------------------------------------------------------- */
188 /* ----------------------------------------------------------------------- */
189 /* user session handling */
190 /* ----------------------------------------------------------------------- */
192 /* session is the login session. If no session is provided, we attempt
193 to find one in the cookies.
194 If 'force' is true we retrieve the
195 user from the server even if there is already a global user present.
196 if ses != G.user.session, we also force a grab */
197 var cookie = new cookieObject("ses", 1, "/", COOKIE_SES);
198 function grabUser(ses, force) {
200 if(!ses) ses = cookie.get(COOKIE_SES);
201 if(!ses) return false;
204 if(G.user && G.user.session == ses)
208 /* first make sure the session is valid */
209 var request = new Request(FETCH_SESSION, ses );
211 var user = request.result();
212 if( !(typeof user == 'object' && user._isfieldmapper) ) {
217 var req = new Request(FETCH_FLESHED_USER, ses);
220 G.user = req.result();
222 if(!G.user || G.user.length == 0) {
223 G.user = null; return false;
224 cookie.remove(COOKIE_SES);
227 G.user.session = ses;
228 cookie.put(COOKIE_SES, ses);
236 /* returns a fleshed G.user on success, false on failure */
239 var uname = G.ui.login.username.value;
240 var passwd = G.ui.login.password.value;
242 var init_request = new Request( LOGIN_INIT, uname );
243 init_request.send(true);
244 var seed = init_request.result();
246 if( ! seed || seed == '0') {
247 alert( "Error Communicating with Authentication Server" );
251 var auth_request = new Request( LOGIN_COMPLETE,
252 uname, hex_md5(seed + hex_md5(passwd)), "opac");
254 auth_request.send(true);
255 var auth_result = auth_request.result();
257 if(auth_result == '0' || auth_result == null || auth_result.length == 0) { return false; }
259 var u = grabUser(auth_result, true);
260 if(u) updateLoc(u.home_ou(), findOrgDepth(u.home_ou()));
265 function doLogout() {
267 /* be nice and delete the session from the server */
268 if(G.user && G.user.session) {
269 var req = new Request(LOGIN_DELETE, G.user.session);
271 try { req.result(); } catch(E){}
275 cookie.remove(COOKIE_SES);
277 hideMe(G.ui.sidebar.logoutbox);
278 unHideMe(G.ui.sidebar.loginbox);
279 hideMe(G.ui.sidebar.logged_in_as);
284 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
285 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
288 /* ----------------------------------------------------------------------- */
289 /* build the org tree */
290 /* ----------------------------------------------------------------------- */
293 function buildOrgSelector() {
294 var tree = new dTree("orgTreeSelector");
295 for( var i in orgArraySearcher ) {
296 var node = orgArraySearcher[i];
297 if( node == null ) continue;
298 if(node.parent_ou() == null)
299 tree.add(node.id(), -1, node.name(),
300 "javascript:orgSelect(" + node.id() + ");", node.name());
302 tree.add(node.id(), node.parent_ou().id(), node.name(),
303 "javascript:orgSelect(" + node.id() + ");", node.name());
306 orgTreeSelector = tree;
310 function orgSelect(id) {
316 /* ------------------------------------------------------------------------------------------------------ */
317 /* org tree utilities */
318 /* ------------------------------------------------------------------------------------------------------ */
320 /* takes an org unit or id and return the numeric depth */
321 function findOrgDepth(org_id_or_node) {
322 return findOrgType(findOrgUnit(org_id_or_node).ou_type()).depth();
325 /* takes the org type id from orgunit.ou_type() field and returns
326 the org type object */
327 function findOrgType(type_id) {
328 if(typeof type_id == 'object') return type_id;
329 for(var type in globalOrgTypes) {
330 var t =globalOrgTypes[type];
331 if( t.id() == type_id || t.id() == parseInt(type_id) )
338 /* returns an org unit by id. if an object is passed in as the id,
339 then the object is assumed to be an org unit and is returned */
340 function findOrgUnit(org_id) {
341 return (typeof org_id == 'object') ? org_id : orgArraySearcher[org_id];
345 /* builds a trail from the top of the org tree to the node provide.
346 basically fleshes out 'my orgs'
347 Returns an array of [org0, org1, ..., myorg] */
348 function orgNodeTrail(node) {
349 var na = new Array();
352 node = findOrgUnit(node.parent_ou());
358 /* returns an array of sibling org units */
359 function findSiblingOrgs(node) { return findOrgUnit(node.parent_ou()).children(); }
360 /* ------------------------------------------------------------------------------------------------------ */