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 /* ----------------------------------------------------------------------- */
20 /* Functions for showing the canvas (and hiding any other shown stuff) */
21 /* ----------------------------------------------------------------------- */
22 function showCanvas() {
23 for( var x in G.ui.altcanvas ) {
24 hideMe(G.ui.altcanvas[x]);
26 hideMe(G.ui.common.loading);
27 unHideMe(G.ui.common.canvas_main);
28 G.ui.searchbar.text.focus(); /* focus the searchbar */
31 function swapCanvas(newNode) {
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);
39 /* ----------------------------------------------------------------------- */
42 /* finds the name of the current page */
43 function findCurrentPage() {
44 for( var p in config.page ) {
45 var path = location.pathname;
47 if(!path.match(/.*\.xml$/))
48 path += "index.xml"; /* in case they go to / */
50 if( config.page[p] == path)
57 /* builds an opac URL. If no page is defined, the current page is used
58 if slim, then only everything after the ? is returned (no host portion)
60 function buildOPACLink(args, slim) {
65 var string = location.protocol + "//" + location.host;
66 if(args.page) string += config.page[args.page];
67 else string += config.page[findCurrentPage()];
72 for( var x in args ) {
73 if(x == "page" || args[x] == null) continue;
74 string += "&" + x + "=" + encodeURIComponent(args[x]);
77 string += _appendParam(TERM, PARAM_TERM, args, getTerm, string);
78 string += _appendParam(STYPE, PARAM_STYPE, args, getStype, string);
79 string += _appendParam(LOCATION, PARAM_LOCATION, args, getLocation, string);
80 string += _appendParam(DEPTH, PARAM_DEPTH, args, getDepth, string);
81 string += _appendParam(FORM, PARAM_FORM, args, getForm, string);
82 string += _appendParam(OFFSET, PARAM_OFFSET, args, getOffset, string);
83 string += _appendParam(COUNT, PARAM_COUNT, args, getDisplayCount, string);
84 string += _appendParam(HITCOUNT, PARAM_HITCOUNT, args, getHitCount, string);
85 string += _appendParam(MRID, PARAM_MRID, args, getMrid, string);
86 string += _appendParam(RID, PARAM_RID, args, getRid, string);
87 return string.replace(/\&$/,'').replace(/\?\&/,"?");
90 function _appendParam( fieldVar, fieldName, overrideArgs, getFunc, string ) {
92 if( fieldVar != null && overrideArgs[fieldName] == null )
93 ret = "&" + fieldName + "=" + encodeURIComponent(getFunc());
101 /* ----------------------------------------------------------------------- */
102 /* some useful exceptions */
103 function EX(message) { this.init(message); }
105 EX.prototype.init = function(message) {
106 this.message = message;
109 EX.prototype.toString = function() {
110 return "\n *** Exception Occured \n" + this.message;
113 EXCommunication.prototype = new EX();
114 EXCommunication.prototype.constructor = EXCommunication;
115 EXCommunication.baseClass = EX.prototype.constructor;
117 function EXCommunication(message) {
118 this.init("EXCommunication: " + message);
120 /* ----------------------------------------------------------------------- */
122 function cleanISBN(isbn) {
124 isbn = isbn.toString().replace(/^\s+/,"");
125 var idx = isbn.indexOf(" ");
126 if(idx > -1) { isbn = isbn.substring(0, idx); }
134 /* ----------------------------------------------------------------------- */
135 /* builds a link that goes to the title listings for a metarecord */
136 function buildTitleLink(rec, link) {
139 t = normalize(truncate(t, 65));
140 link.appendChild(text(t));
144 args[PARAM_OFFSET] = 0;
145 args[PARAM_MRID] = rec.doc_id();
146 link.setAttribute("href", buildOPACLink(args));
149 /* builds an author search link */
150 function buildAuthorLink(rec, link) {
152 var a = rec.author();
153 a = normalize(truncate(a, 65));
154 link.appendChild(text(a));
158 args[PARAM_OFFSET] = 0;
159 args[PARAM_STYPE] = STYPE_AUTHOR;
160 args[PARAM_TERM] = rec.author();
161 link.setAttribute("href", buildOPACLink(args));
164 /* ----------------------------------------------------------------------- */
168 /* ----------------------------------------------------------------------- */
169 /* user session handling */
170 /* ----------------------------------------------------------------------- */
172 /* session is the login session. If no session is provided, we attempt
173 to find one in the cookies.
174 If 'force' is true we retrieve the
175 user from the server even if there is already a global user present.
176 if ses != G.user.session, we also force a grab */
177 var cookie = new cookieObject("ses", 1, "/", COOKIE_SES);
178 function grabUser(ses, force) {
180 if(!ses) ses = cookie.get(COOKIE_SES);
181 if(!ses) return false;
184 if(G.user && G.user.session == ses)
188 /* first make sure the session is valid */
189 var request = new Request(FETCH_SESSION, ses );
191 var user = request.result();
192 if( !(typeof user == 'object' && user._isfieldmapper) ) {
197 var req = new Request(FETCH_FLESHED_USER, ses);
200 G.user = req.result();
202 if(!G.user || G.user.length == 0) {
203 G.user = null; return false;
204 cookie.remove(COOKIE_SES);
207 G.user.session = ses;
208 cookie.put(COOKIE_SES, ses);
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_request.length == 0) { return false; }
239 return grabUser(auth_result, true);
242 function doLogout() {
244 /* be nice and delete the session from the server */
245 if(G.user && G.user.session) {
246 var req = new Request(LOGIN_DELETE, G.user.session);
248 try { req.result(); } catch(E){}
252 cookie.remove(COOKIE_SES);
254 hideMe(G.ui.sidebar.logoutbox);
255 unHideMe(G.ui.sidebar.loginbox);
256 hideMe(G.ui.sidebar.logged_in_as);
261 function hideMe(obj) { addCSSClass(obj, config.css.hide_me); }
262 function unHideMe(obj) { removeCSSClass(obj, config.css.hide_me); }
265 /* ----------------------------------------------------------------------- */
266 /* build the org tree */
267 /* ----------------------------------------------------------------------- */
270 function buildOrgSelector() {
271 var tree = new dTree("orgTreeSelector");
272 for( var i in orgArraySearcher ) {
273 var node = orgArraySearcher[i];
274 if( node == null ) continue;
275 if(node.parent_ou() == null)
276 tree.add(node.id(), -1, node.name(),
277 "javascript:orgSelect(" + node.id() + ");", node.name());
279 tree.add(node.id(), node.parent_ou().id(), node.name(),
280 "javascript:orgSelect(" + node.id() + ");", node.name());
283 orgTreeSelector = tree;
287 function orgSelect(id) {
289 newSearchLocation = id;
294 /* ----------------------------------------------------------------------- */