added a global flag to disable/enable authority lookups
[Evergreen.git] / Open-ILS / web / opac / common / js / config.js
1 /* Export some constants  ----------------------------------------------------- */
2
3 var SHOW_MR_DEFAULT = false; /* true if we show metarecords by default */
4
5 var DO_AUTHORITY_LOOKUPS = false;
6
7 /* URL param names */
8 var PARAM_TERM                  = "t";                  /* search term */
9 var PARAM_STYPE         = "tp";                 /* search type */
10 var PARAM_LOCATION      = "l";                  /* current location */
11 var PARAM_DEPTH         = "d";                  /* search depth */
12 var PARAM_FORM                  = "f";                  /* search format */
13 var PARAM_OFFSET                = "o";                  /* search offset */
14 var PARAM_COUNT         = "c";                  /* hits per page */
15 var PARAM_HITCOUNT      = "hc";                 /* hits per page */
16 var PARAM_MRID                  = "m";                  /* metarecord id */
17 var PARAM_RID                   = "r";                  /* record id */
18 var PARAM_RLIST         = "rl";
19 var PARAM_ORIGLOC               = "ol";                 /* the original location */
20 var PARAM_AUTHTIME      = "at";                 /* inactivity timeout in seconds */
21 var PARAM_ADVTERM               = "adv";                        /* advanced search term */
22 var PARAM_ADVTYPE               = "adt";                        /* the advanced search type */
23 var PARAM_RTYPE         = "rt";
24 var PARAM_SORT                  = "s";
25 var PARAM_SORT_DIR      = "sd";
26 var PARAM_DEBUG         = "dbg";
27 var PARAM_CN                    = "cn";
28 var PARAM_LITFORM               = 'lf';
29 var PARAM_ITEMFORM      = 'if';
30 var PARAM_ITEMTYPE      = 'it';
31 var PARAM_AUDIENCE      = 'a';
32 var PARAM_SEARCHES      = 'ss';
33 var PARAM_LANGUAGE      = 'la';
34 var PARAM_TFORM         = 'tf'; /* temporary format for title result pages */
35 var PARAM_RDEPTH                = 'rd';
36 var PARAM_REDIR         = 're'; /* true if we have been redirected by IP (we're at a real lib) */
37
38 /* URL param values (see comments above) */
39 var TERM;  
40 var STYPE;  
41 var LOCATION;  
42 var DEPTH;  
43 var FORM; 
44 var OFFSET;
45 var COUNT;  
46 var HITCOUNT;  
47 var RANKS; 
48 var FONTSIZE;
49 var ORIGLOC;
50 var AUTHTIME;
51 var ADVTERM;
52 var ADVTYPE;
53 var MRID;
54 var RID;
55 var RTYPE;
56 var SORT;
57 var SORT_DIR;
58 var RLIST;
59 var DEBUG;
60 var CALLNUM;
61 var LITFORM;
62 var ITEMFORM;
63 var ITEMTYPE;
64 var AUDIENCE;
65 var SEARCHES;
66 var LANGUAGE;
67 var TFORM;
68 var RDEPTH;
69
70 /* cookie values */
71 var SBEXTRAS; 
72 var SKIN;
73
74 /* cookies */
75 var COOKIE_SB           = "sbe";
76 var COOKIE_SES          = "ses";
77 //var COOKIE_IDS                = "ids"; /* list of mrecord ids */
78 //var COOKIE_SRIDS      = "srids"; /* record ids cached from a search */
79 var COOKIE_FONT = "fnt";
80 var COOKIE_SKIN = "skin";
81 var COOKIE_RIDS = "rids"; /* list of record ids */
82
83 /* pages */
84 var MRESULT             = "mresult";
85 var RRESULT             = "rresult";
86 var RDETAIL             = "rdetail";
87 var MYOPAC              = "myopac";
88 var ADVANCED    = "advanced";
89 var HOME                        = "home";
90 var BBAGS               = "bbags";
91 var REQITEMS    = "reqitems";
92 var CNBROWSE    = "cnbrowse";
93
94 /* search type (STYPE) options */
95 var STYPE_AUTHOR        = "author";
96 var STYPE_TITLE = "title";
97 var STYPE_SUBJECT       = "subject";
98 var STYPE_SERIES        = "series";
99 var STYPE_KEYWORD       = "keyword";
100
101 /* record-level search types */
102 var RTYPE_MRID          = "mrid";
103 var RTYPE_COOKIE        = "cookie";
104 var RTYPE_AUTHOR        = STYPE_AUTHOR;
105 var RTYPE_SUBJECT       = STYPE_SUBJECT;
106 var RTYPE_TITLE = STYPE_TITLE;
107 var RTYPE_SERIES        = STYPE_SERIES;
108 var RTYPE_KEYWORD       = STYPE_KEYWORD;
109 var RTYPE_LIST          = "list";
110 var RTYPE_MULTI = 'multi';
111 var RTYPE_MARC          = 'marc';
112 var RTYPE_ISBN          = 'isbn';
113 var RTYPE_ISSN          = 'issn';
114 var RTYPE_TCN           = 'tcn';
115
116 var SORT_TYPE_REL                       = "rel";
117 var SORT_TYPE_AUTHOR            = STYPE_AUTHOR; 
118 var SORT_TYPE_TITLE             = STYPE_TITLE;
119 var SORT_TYPE_PUBDATE   = "pubdate";
120 var SORT_DIR_ASC                        = "asc";
121 var SORT_DIR_DESC                       = "desc";
122
123 /* types of advanced search */
124 var ADVTYPE_MULTI = 'ml';
125 var ADVTYPE_MARC        = 'ma';
126
127 /*
128 var ADVTYPE_ISBN        = 'isbn';
129 var ADVTYPE_ISSN        = 'issn';
130 */
131
132 var LOGOUT_WARNING_TIME = 30; /* "head up" for session timeout */
133
134 /* user preferences */
135 var PREF_HITS_PER               = 'opac.hits_per_page';
136 var PREF_DEF_FONT               = 'opac.default_font';
137 var PREF_HOLD_NOTIFY = 'opac.hold_notify';
138 var PREF_DEF_LOCATION = 'opac.default_search_location';
139 var PREF_DEF_DEPTH      = 'opac.default_search_depth';
140
141
142 /* container for global variables shared accross pages */
143 var G           = {};
144 G.user  = null; /* global user object */
145 G.ui            = {} /* cache of UI components */
146
147
148 /* regexes */
149 var REGEX_BARCODE = /^\d+/; /* starts with a number */
150 var REGEX_PHONE = /^\d{3}-\d{3}-\d{4}$/; /* 111-222-3333 */
151
152
153 /* call me after page init and I will load references 
154         to all of the ui object id's defined below 
155         They will be stored in G.ui.<page>.<thingy>
156  */
157 function loadUIObjects() {
158         for( var p in config.ids ) {
159                 G.ui[p] = {};
160                 for( var o in config.ids[p] ) 
161                         G.ui[p][o] = getId(config.ids[p][o]);
162         }
163 }
164
165 /* try our best to free memory */
166 function clearUIObjects() {
167         for( var p in config.ids ) {
168                 for( var o in config.ids[p] ) {
169                         if(G.ui[p][o]) {
170                                 G.ui[p][o].onclick = null;
171                                 G.ui[p][o].onkeydown = null;
172                                 G.ui[p][o] = null;
173                         }
174                 }
175                 G.ui[p] = null;
176         }
177 }
178
179 /* ---------------------------------------------------------------------------- 
180         Set up ID's and CSS classes 
181         Any new ids, css, etc. may be added by giving the unique names and putting 
182         them into the correct scope 
183 /* ---------------------------------------------------------------------------- */
184
185 var config = {};
186
187 /* Set up the page names */
188 config.page = {};
189 config.page[HOME]                       = "index.xml";
190 config.page[ADVANCED]   = "advanced.xml";
191 config.page[MRESULT]            = "mresult.xml";
192 config.page[RRESULT]            = "rresult.xml";
193 config.page[MYOPAC]             = "myopac.xml";
194 config.page[RDETAIL]            = "rdetail.xml";
195 config.page[BBAGS]              = "bbags.xml";
196 config.page[REQITEMS]   = "reqitems.xml";
197 config.page[CNBROWSE]   = "cnbrowse.xml";
198
199 /* themes */
200 config.themes = {};
201
202 /* set up images  */
203 config.images = {};
204 config.images.logo = "main_logo.jpg";
205
206
207 /* set up ID's, CSS, and node names */
208 config.ids                              = {};
209 config.ids.result               = {};
210 config.ids.mresult      = {};
211 config.ids.advanced     = {};
212 config.ids.rresult      = {};
213 config.ids.myopac               = {};
214 config.ids.rdetail      = {};
215
216 config.css                              = {};
217 config.css.result               = {};
218 config.css.mresult      = {};
219 config.css.advanced     = {};
220 config.css.rresult      = {};
221 config.css.myopac               = {};
222 config.css.rdetail      = {};
223
224 config.names                    = {};
225 config.names.result     = {};
226 config.names.mresult = {};
227 config.names.advanced = {};
228 config.names.rresult = {};
229 config.names.myopac     = {};
230 config.names.rdetail = {};
231
232
233 /* id's shared accross skins. These *must* be defined */
234 config.ids.common = {};
235 config.ids.common.loading                       = "loading_div";                
236 config.ids.common.canvas                        = "canvas";                             
237 config.ids.common.canvas_main           = "canvas_main";                
238 config.ids.common.org_tree                      = "org_tree";                   
239 config.ids.common.org_container = "org_container";
240
241 config.ids.xul = {};
242
243
244 /* shared CSS */
245 config.css.hide_me = "hide_me";
246 config.css.dim = "dim";
247 config.css.dim2 = "dim2";
248
249
250 /* ---------------------------------------------------------------------------- */
251 /* These are pages that may replace the canvas */
252 /* ---------------------------------------------------------------------------- */
253 config.ids.altcanvas = {};
254
255
256
257 /* ---------------------------------------------------------------------------- */
258 /* Methods are defined as service:method 
259         An optional 3rd component is when a method is followed by a :1, such methods
260         have a staff counterpart and should have ".staff" appended to the method 
261         before the method is called when in XUL mode */
262
263 var SEARCH_MRS                                          = 'open-ils.search:open-ils.search.metabib.multiclass:1';
264 var SEARCH_RS                                           = 'open-ils.search:open-ils.search.biblio.multiclass:1';
265 var FETCH_SEARCH_RIDS                   = "open-ils.search:open-ils.search.biblio.record.class.search:1";
266 var FETCH_MRMODS                                        = "open-ils.search:open-ils.search.biblio.metarecord.mods_slim.retrieve";
267 var FETCH_MODS_FROM_COPY                = "open-ils.search:open-ils.search.biblio.mods_from_copy";
268 var FETCH_MR_COPY_COUNTS                = "open-ils.search:open-ils.search.biblio.metarecord.copy_count:1";
269 var FETCH_RIDS                                          = "open-ils.search:open-ils.search.biblio.metarecord_to_records:1";
270 var FETCH_RMODS                                 = "open-ils.search:open-ils.search.biblio.record.mods_slim.retrieve";
271 var FETCH_R_COPY_COUNTS                 = "open-ils.search:open-ils.search.biblio.record.copy_count:1";
272 var FETCH_FLESHED_USER                  = "open-ils.actor:open-ils.actor.user.fleshed.retrieve";
273 var FETCH_SESSION                                       = "open-ils.auth:open-ils.auth.session.retrieve";
274 var LOGIN_INIT                                          = "open-ils.auth:open-ils.auth.authenticate.init";
275 var LOGIN_COMPLETE                              = "open-ils.auth:open-ils.auth.authenticate.complete";
276 var LOGIN_DELETE                                        = "open-ils.auth:open-ils.auth.session.delete";
277 var FETCH_USER_PREFS                            = "open-ils.actor:open-ils.actor.patron.settings.retrieve"; 
278 var UPDATE_USER_PREFS                   = "open-ils.actor:open-ils.actor.patron.settings.update"; 
279 var FETCH_COPY_STATUSES                 = "open-ils.search:open-ils.search.config.copy_status.retrieve.all";
280 var FETCH_COPY_COUNTS_SUMMARY   = "open-ils.search:open-ils.search.biblio.copy_counts.summary.retrieve";
281 var FETCH_MARC_HTML                             = "open-ils.search:open-ils.search.biblio.record.html";
282 var FETCH_CHECKED_OUT_SUM               = "open-ils.actor:open-ils.actor.user.checked_out";
283 var FETCH_HOLDS                                 = "open-ils.circ:open-ils.circ.holds.retrieve";
284 var FETCH_FINES_SUMMARY                 = "open-ils.actor:open-ils.actor.user.fines.summary";
285 var FETCH_TRANSACTIONS                  = "open-ils.actor:open-ils.actor.user.transactions.have_charge.fleshed";
286 var FETCH_MONEY_BILLING                 = 'open-ils.circ:open-ils.circ.money.billing.retrieve.all';
287 var FETCH_CROSSREF                              = "open-ils.search:open-ils.search.authority.crossref";
288 var FETCH_CROSSREF_BATCH                = "open-ils.search:open-ils.search.authority.crossref.batch";
289 var CREATE_HOLD                                 = "open-ils.circ:open-ils.circ.holds.create";
290 var CREATE_HOLD_OVERRIDE                = "open-ils.circ:open-ils.circ.holds.create.override";
291 var CANCEL_HOLD                                 = "open-ils.circ:open-ils.circ.hold.cancel";
292 var UPDATE_USERNAME                             = "open-ils.actor:open-ils.actor.user.username.update";
293 var UPDATE_PASSWORD                             = "open-ils.actor:open-ils.actor.user.password.update";
294 var UPDATE_EMAIL                                        = "open-ils.actor:open-ils.actor.user.email.update";
295 var RENEW_CIRC                                          = "open-ils.circ:open-ils.circ.renew";
296 var CHECK_SPELL                                 = "open-ils.search:open-ils.search.spellcheck";
297 var FETCH_REVIEWS                                       = "open-ils.search:open-ils.search.added_content.review.retrieve.all";
298 var FETCH_TOC                                           = "open-ils.search:open-ils.search.added_content.toc.retrieve";
299 var FETCH_ACONT_SUMMARY                 = "open-ils.search:open-ils.search.added_content.summary.retrieve";
300 var FETCH_USER_BYBARCODE                = "open-ils.actor:open-ils.actor.user.fleshed.retrieve_by_barcode";
301 var FETCH_ADV_MARC_MRIDS                = "open-ils.search:open-ils.search.biblio.marc:1";
302 var FETCH_ADV_ISBN_RIDS                 = "open-ils.search:open-ils.search.biblio.isbn";
303 var FETCH_ADV_ISSN_RIDS                 = "open-ils.search:open-ils.search.biblio.issn";
304 var FETCH_ADV_TCN_RIDS                  = "open-ils.search:open-ils.search.biblio.tcn";
305 var FETCH_CNBROWSE                              = 'open-ils.search:open-ils.search.callnumber.browse';
306 var FETCH_CONTAINERS                            = 'open-ils.actor:open-ils.actor.container.retrieve_by_class';
307 var FETCH_CONTAINERS                            = 'open-ils.actor:open-ils.actor.container.retrieve_by_class';
308 var CREATE_CONTAINER                            = 'open-ils.actor:open-ils.actor.container.create';
309 var DELETE_CONTAINER                            = 'open-ils.actor:open-ils.actor.container.full_delete';
310 var CREATE_CONTAINER_ITEM               = 'open-ils.actor:open-ils.actor.container.item.create';
311 var DELETE_CONTAINER_ITEM               = 'open-ils.actor:open-ils.actor.container.item.delete';
312 var FLESH_CONTAINER                             = 'open-ils.actor:open-ils.actor.container.flesh';
313 var FLESH_PUBLIC_CONTAINER              = 'open-ils.actor:open-ils.actor.container.public.flesh';
314 var UPDATE_CONTAINER                            = 'open-ils.actor:open-ils.actor.container.update';
315 var FETCH_COPY                                          = 'open-ils.search:open-ils.search.asset.copy.retrieve';
316 var FETCH_FLESHED_COPY                  = 'open-ils.search:open-ils.search.asset.copy.fleshed2.retrieve';
317 var CHECK_HOLD_POSSIBLE                 = 'open-ils.circ:open-ils.circ.title_hold.is_possible';
318 var UPDATE_HOLD                                 = 'open-ils.circ:open-ils.circ.hold.update';
319 var FETCH_COPIES_FROM_VOLUME    = 'open-ils.search:open-ils.search.asset.copy.retrieve_by_cn_label';
320 var FETCH_VOLUME_BY_INFO                = 'open-ils.search:open-ils.search.call_number.retrieve_by_info'; /* XXX staff method? */
321 var FETCH_VOLUME                                        = 'open-ils.search:open-ils.search.asset.call_number.retrieve';
322 var FETCH_COPY_LOCATIONS                = 'open-ils.circ:open-ils.circ.copy_location.retrieve.all';
323 var FETCH_COPY_NOTES                            = 'open-ils.circ:open-ils.circ.copy_note.retrieve.all';
324 var FETCH_COPY_STAT_CATS                = 'open-ils.circ:open-ils.circ.asset.stat_cat_entries.fleshed.retrieve_by_copy';
325 var FETCH_LIT_FORMS                             = 'open-ils.search:open-ils.search.biblio.lit_form_map.retrieve.all';
326 var FETCH_ITEM_FORMS                            = 'open-ils.search:open-ils.search.biblio.item_form_map.retrieve.all';
327 var FETCH_ITEM_TYPES                            = 'open-ils.search:open-ils.search.biblio.item_type_map.retrieve.all';
328 var FETCH_AUDIENCES                             = 'open-ils.search:open-ils.search.biblio.audience_map.retrieve.all';
329 var FETCH_HOLD_STATUS                   = 'open-ils.circ:open-ils.circ.hold.status.retrieve';
330 var FETCH_NON_CAT_CIRCS                 = 'open-ils.circ:open-ils.circ.open_non_cataloged_circulation.user';
331 var FETCH_NON_CAT_CIRC                  = 'open-ils.circ:open-ils.circ.non_cataloged_circulation.retrieve';
332 var FETCH_NON_CAT_TYPES                 = "open-ils.circ:open-ils.circ.non_cat_types.retrieve.all";
333 var FETCH_BRE                                           = 'open-ils.search:open-ils.search.biblio.record_entry.slim.retrieve';
334 var CHECK_USERNAME                              = 'open-ils.actor:open-ils.actor.username.exists';
335 var FETCH_CIRC_BY_ID                            = 'open-ils.circ:open-ils.circ.retrieve';
336 var FETCH_MR_DESCRIPTORS                = 'open-ils.search:open-ils.search.metabib.record_to_descriptors';
337 var FETCH_HIGHEST_PERM_ORG              = 'open-ils.actor:open-ils.actor.user.perm.highest_org.batch';
338 var FETCH_USER_NOTES                            = 'open-ils.actor:open-ils.actor.note.retrieve.all';
339 var FETCH_ORG_BY_SHORTNAME              = 'open-ils.actor:open-ils.actor.org_unit.retrieve_by_shorname';
340
341 /* ---------------------------------------------------------------------------- */
342
343
344 /* ---------------------------------------------------------------------------- */
345 /* event callback functions. Other functions may be appended to these vars to
346         for added functionality.  */
347
348 G.evt                           = {}; /* events container */
349
350 function runEvt(scope, name, a, b, c, d, e, f, g) {
351         var evt = G.evt[scope][name];
352         for( var i in evt ) {
353                 evt[i](a, b, c, d, e, f, g);    
354         }
355 }
356
357 /* creates a new event if it doesn't already exist */
358 function createEvt(scope, name) {
359         if(!G.evt[scope]) G.evt[scope] = {};
360         if(G.evt[scope][name] == null)
361                 G.evt[scope][name] = []; 
362 }
363
364 function attachEvt(scope, name, action) {
365         createEvt(scope, name);
366         G.evt[scope][name].push(action);
367 }
368
369 function detachAllEvt(scope, name) {
370         G.evt[scope][name] = [];
371 }
372
373
374 createEvt("common", "init");                                            /* f() : what happens on page init */
375 createEvt("common", "pageRendered");                    /* f() : what happens when the page is done (up to the skin to call this even)*/
376 createEvt("common", "unload");                                  /* f() : what happens on window unload (clean memory, etc.)*/
377 createEvt("common", "locationChanged");         /* f() : what happens when the location has changed */
378 createEvt("common", "locationUpdated");         /* f() : what happens when the location has updated by the code */
379
380 createEvt("common", "run");                                             /* f() : make the page do stuff */
381 createEvt("result", "idsReceived");                             /* f(ids) */
382 createEvt("rresult", "recordDrawn");                    /* f(recordid, linkDOMNode) : after record is drawn, allow others (xul) to plugin actions */
383 createEvt("result", "preCollectRecords");               /* f() we're about to go and grab the recs */
384
385 createEvt("result", "hitCountReceived");                /* f() : display hit info, pagination, etc. */
386 createEvt("result", "recordReceived");                  /* f(mvr, pagePosition, isMr) : display the record*/
387 createEvt("result", "recordDrawn");                             /* f(recordid, linkDOMNode) : after record is drawn, allow others (xul) to plugin actions */
388 createEvt("result", "copyCountsReceived");      /* f(mvr, pagePosition, copyCountInfo) : display copy counts*/
389 createEvt("result", "allRecordsReceived");      /* f(mvrsArray) : add other page stuff, sidebars, etc.*/
390
391 createEvt("rdetail", "recordDrawn");                    /* f() : the record has been drawn */
392
393 createEvt("common", "loggedIn");                                        /* f() : user has just logged in */
394 createEvt('result', 'zeroHits');
395 createEvt('result', 'lowHits');
396 createEvt('rdetail', 'recordRetrieved');                        /* we are about to draw the rdetail page */
397 createEvt('common', 'depthChanged');
398 createEvt('common', 'holdUpdated'); 
399 createEvt('common', 'holdUpdateCanceled'); 
400
401 createEvt('rdetail', 'nextPrevDrawn');
402
403
404
405
406