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