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