2 function isXUL() { return IAMXUL; }
5 /* - Request ------------------------------------------------------------- */
6 function Request(type) {
7 var s = type.split(":");
8 this.request = new RemoteRequest(s[0], s[1]);
9 for( var x = 1; x!= arguments.length; x++ )
10 this.request.addParam(arguments[x]);
13 Request.prototype.callback = function(cal) { this.request.setCompleteCallback(cal); }
14 Request.prototype.send = function(block){this.request.send(block);}
15 Request.prototype.result = function(){return this.request.getResultObject();}
16 /* ----------------------------------------------------------------------- */
19 /* finds the name of the current page */
20 function findCurrentPage() {
21 for( var p in config.page ) {
22 var path = location.pathname;
24 if(!path.match(/.*\.xml$/))
25 path += "index.xml"; /* in case they go to / */
27 if( config.page[p] == path)
34 /* builds an opac URL. If no page is defined, the current page is used
35 if slim, then only everything after the ? is returned (no host portion)
37 function buildOPACLink(args, slim) {
42 var string = location.protocol + "//" + location.host;
43 if(args.page) string += config.page[args.page];
44 else string += config.page[findCurrentPage()];
49 for( var x in args ) {
50 if(x == "page" || args[x] == null) continue;
51 string += "&" + x + "=" + encodeURIComponent(args[x]);
54 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
55 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
56 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
57 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
58 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
59 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
60 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
61 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
62 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
63 string += _appendParam(RID, PARAM_RID, args, getRid, string);
64 return string.replace(/\&$/,'').replace(/\?\&/,"?");
67 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
69 if( fieldVar != null && overrideArgs[fieldName] == null )
70 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
78 /* ----------------------------------------------------------------------- */
79 /* some useful exceptions */
80 function EX(message) { this.init(message); }
82 EX.prototype.init = function(message) {
83 this.message = message;
86 EX.prototype.toString = function() {
87 return "\n *** Exception Occured \n" + this.message;
90 EXCommunication.prototype = new EX();
91 EXCommunication.prototype.constructor = EXCommunication;
92 EXCommunication.baseClass = EX.prototype.constructor;
94 function EXCommunication(message) {
95 this.init("EXCommunication: " + message);
97 /* ----------------------------------------------------------------------- */
99 function cleanISBN(isbn) {
101 isbn = isbn.toString().replace(/^\s+/,"");
102 var idx = isbn.indexOf(" ");
103 if(idx > -1) { isbn = isbn.substring(0, idx); }
111 /* ----------------------------------------------------------------------- */
112 /* builds a link that goes to the title listings for a metarecord */
113 function buildTitleLink(rec, link) {
116 t = normalize(truncate(t, 65));
117 link.appendChild(text(t));
121 args[PARAM_OFFSET] = 0;
122 args[PARAM_MRID] = rec.doc_id();
123 link.setAttribute("href", buildOPACLink(args));
126 /* builds an author search link */
127 function buildAuthorLink(rec, link) {
129 var a = rec.author();
130 a = normalize(truncate(a, 65));
131 link.appendChild(text(a));
135 args[PARAM_OFFSET] = 0;
136 args[PARAM_STYPE] = STYPE_AUTHOR;
137 args[PARAM_TERM] = rec.author();
138 link.setAttribute("href", buildOPACLink(args));
141 /* ----------------------------------------------------------------------- */
145 /* ----------------------------------------------------------------------- */
146 /* user session handling */
147 /* ----------------------------------------------------------------------- */
149 /* session is the login session. If no session is provided, we attempt
150 to find one in the cookies.
151 If 'force' is true we retrieve the
152 user from the server even if there is already a global user present.
153 if ses != G.user.session, we also force a grab */
154 var cookie = new cookieObject("ses", 1, "/", COOKIE_SES);
155 function grabUser(ses, force) {
157 if(!ses) ses = cookie.get(COOKIE_SES);
158 if(!ses) return false;
161 if(G.user && G.user.session == ses)
165 /* first make sure the session is valid */
166 var request = new Request(FETCH_SESSION, ses );
168 var user = request.result();
169 if( !(typeof user == 'object' && user._isfieldmapper) ) {
174 var req = new Request(FETCH_FLESHED_USER, ses);
177 G.user = req.result();
179 if(!G.user || G.user.length == 0) {
180 G.user = null; return false;
181 cookie.remove(COOKIE_SES);
184 G.user.session = ses;
185 cookie.put(COOKIE_SES, ses);
193 /* returns a fleshed G.user on success, false on failure */
196 var uname = G.ui.login.username.value;
197 var passwd = G.ui.login.password.value;
199 var init_request = new Request( LOGIN_INIT, uname );
200 init_request.send(true);
201 var seed = init_request.result();
203 if( ! seed || seed == '0') {
204 alert( "Error Communicating with Authentication Server" );
208 var auth_request = new Request( LOGIN_COMPLETE,
209 uname, hex_md5(seed + hex_md5(passwd)), "opac");
211 auth_request.send(true);
212 var auth_result = auth_request.result();
214 if(auth_result == '0' || auth_result == null || auth_request.length == 0) { return false; }
216 return grabUser(auth_result, true);
219 function doLogout() {
221 /* be nice and delete the session from the server */
222 if(G.user && G.user.session) {
223 var req = new Request(LOGIN_DELETE, G.user.session);
225 try { req.result(); } catch(E){}
229 cookie.remove(COOKIE_SES);
231 hideMe(G.ui.sidebar.logoutbox);
232 unHideMe(G.ui.sidebar.loginbox);
233 hideMe(G.ui.sidebar.logged_in_as);
238 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
239 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }