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