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