started work on the notes interface in the opac.
[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
110
111 /* container for global variables shared accross pages */
112 var G           = {};
113 G.user  = null; /* global user object */
114 G.ui            = {} /* cache of UI components */
115
116
117 /* call me after page init and I will load references 
118         to all of the ui object id's defined below 
119         They will be stored in G.ui.<page>.<thingy>
120  */
121 function loadUIObjects() {
122         for( var p in config.ids ) {
123                 G.ui[p] = {};
124                 for( var o in config.ids[p] ) 
125                         G.ui[p][o] = getId(config.ids[p][o]);
126         }
127 }
128
129 /* try our best to free memory */
130 function clearUIObjects() {
131         for( var p in config.ids ) {
132                 for( var o in config.ids[p] ) {
133                         if(G.ui[p][o]) {
134                                 G.ui[p][o].onclick = null;
135                                 G.ui[p][o].onkeydown = null;
136                                 G.ui[p][o] = null;
137                         }
138                 }
139                 G.ui[p] = null;
140         }
141 }
142
143 /* ---------------------------------------------------------------------------- 
144         Set up ID's and CSS classes 
145         Any new ids, css, etc. may be added by giving the unique names and putting 
146         them into the correct scope 
147 /* ---------------------------------------------------------------------------- */
148
149 var config = {};
150
151 /* Set up the page names */
152 config.page = {};
153 config.page[HOME]                       = "index.xml";
154 config.page[ADVANCED]   = "advanced.xml";
155 config.page[MRESULT]            = "mresult.xml";
156 config.page[RRESULT]            = "rresult.xml";
157 config.page[MYOPAC]             = "myopac.xml";
158 config.page[RDETAIL]            = "rdetail.xml";
159 config.page[BBAGS]              = "bbags.xml";
160 config.page[REQITEMS]   = "reqitems.xml";
161 config.page[CNBROWSE]   = "cnbrowse.xml";
162
163 /* themes */
164 config.themes = {};
165
166 /* set up images  */
167 config.images = {};
168 config.images.logo = "main_logo.jpg";
169
170
171 /* set up ID's, CSS, and node names */
172 config.ids                              = {};
173 config.ids.result               = {};
174 config.ids.mresult      = {};
175 config.ids.advanced     = {};
176 config.ids.rresult      = {};
177 config.ids.myopac               = {};
178 config.ids.rdetail      = {};
179
180 config.css                              = {};
181 config.css.result               = {};
182 config.css.mresult      = {};
183 config.css.advanced     = {};
184 config.css.rresult      = {};
185 config.css.myopac               = {};
186 config.css.rdetail      = {};
187
188 config.names                    = {};
189 config.names.result     = {};
190 config.names.mresult = {};
191 config.names.advanced = {};
192 config.names.rresult = {};
193 config.names.myopac     = {};
194 config.names.rdetail = {};
195
196
197 /* id's shared accross skins. These *must* be defined */
198 config.ids.common = {};
199 config.ids.common.loading                       = "loading_div";                
200 config.ids.common.canvas                        = "canvas";                             
201 config.ids.common.canvas_main           = "canvas_main";                
202 config.ids.common.org_tree                      = "org_tree";                   
203 config.ids.common.org_container = "org_container";
204
205 config.ids.xul = {};
206
207
208 /* shared CSS */
209 config.css.hide_me = "hide_me";
210 config.css.dim = "dim";
211 config.css.dim2 = "dim2";
212
213
214 /* ---------------------------------------------------------------------------- */
215 /* These are pages that may replace the canvas */
216 /* ---------------------------------------------------------------------------- */
217 config.ids.altcanvas = {};
218
219
220
221 /* ---------------------------------------------------------------------------- */
222 /* Methods are defined as service:method 
223         An optional 3rd component is when a method is followed by a :1, such methods
224         have a staff counterpart and should have ".staff" appended to the method 
225         before the method is called when in XUL mode */
226
227 var FETCH_MRIDS_                                        = "open-ils.search:open-ils.search.biblio.metabib.class.search:1";
228 var FETCH_SEARCH_RIDS                   = "open-ils.search:open-ils.search.biblio.record.class.search:1";
229 var FETCH_MRMODS                                        = "open-ils.search:open-ils.search.biblio.metarecord.mods_slim.retrieve";
230 var FETCH_MODS_FROM_COPY                = "open-ils.search:open-ils.search.biblio.mods_from_copy";
231 var FETCH_MR_COPY_COUNTS                = "open-ils.search:open-ils.search.biblio.metarecord.copy_count:1";
232 var FETCH_RIDS                                          = "open-ils.search:open-ils.search.biblio.metarecord_to_records:1";
233 var FETCH_RMODS                                 = "open-ils.search:open-ils.search.biblio.record.mods_slim.retrieve";
234 var FETCH_R_COPY_COUNTS                 = "open-ils.search:open-ils.search.biblio.record.copy_count";
235 var FETCH_FLESHED_USER                  = "open-ils.actor:open-ils.actor.user.fleshed.retrieve";
236 var FETCH_SESSION                                       = "open-ils.auth:open-ils.auth.session.retrieve";
237 var LOGIN_INIT                                          = "open-ils.auth:open-ils.auth.authenticate.init";
238 var LOGIN_COMPLETE                              = "open-ils.auth:open-ils.auth.authenticate.complete";
239 var LOGIN_DELETE                                        = "open-ils.auth:open-ils.auth.session.delete";
240 var FETCH_USER_PREFS                            = "open-ils.actor:open-ils.actor.patron.settings.retrieve"; 
241 var UPDATE_USER_PREFS                   = "open-ils.actor:open-ils.actor.patron.settings.update"; 
242 var FETCH_COPY_STATUSES                 = "open-ils.search:open-ils.search.config.copy_status.retrieve.all";
243 var FETCH_COPY_COUNTS_SUMMARY   = "open-ils.search:open-ils.search.biblio.copy_counts.summary.retrieve";
244 var FETCH_MARC_HTML                             = "open-ils.search:open-ils.search.biblio.record.html";
245 var FETCH_CHECKED_OUT                   = "open-ils.circ:open-ils.circ.actor.user.checked_out";
246 var FETCH_CHECKED_OUT_SLIM              = "open-ils.circ:open-ils.circ.actor.user.checked_out.slim";
247 var FETCH_HOLDS                                 = "open-ils.circ:open-ils.circ.holds.retrieve";
248 var FETCH_FINES_SUMMARY                 = "open-ils.actor:open-ils.actor.user.fines.summary";
249 var FETCH_TRANSACTIONS                  = "open-ils.actor:open-ils.actor.user.transactions.have_charge.fleshed";
250 var FETCH_MONEY_BILLING                 = 'open-ils.circ:open-ils.circ.money.billing.retrieve.all';
251 var FETCH_CROSSREF                              = "open-ils.search:open-ils.search.authority.crossref";
252 var FETCH_CROSSREF_BATCH                = "open-ils.search:open-ils.search.authority.crossref.batch";
253 var CREATE_HOLD                                 = "open-ils.circ:open-ils.circ.holds.create";
254 var CANCEL_HOLD                                 = "open-ils.circ:open-ils.circ.hold.cancel";
255 var UPDATE_USERNAME                             = "open-ils.actor:open-ils.actor.user.username.update";
256 var UPDATE_PASSWORD                             = "open-ils.actor:open-ils.actor.user.password.update";
257 var UPDATE_EMAIL                                        = "open-ils.actor:open-ils.actor.user.email.update";
258 var RENEW_CIRC                                          = "open-ils.circ:open-ils.circ.renew";
259 var CHECK_SPELL                                 = "open-ils.search:open-ils.search.spell_check";
260 var FETCH_REVIEWS                                       = "open-ils.search:open-ils.search.added_content.review.retrieve.all";
261 var FETCH_TOC                                           = "open-ils.search:open-ils.search.added_content.toc.retrieve";
262 var FETCH_ACONT_SUMMARY                 = "open-ils.search:open-ils.search.added_content.summary.retrieve";
263 var FETCH_USER_BYBARCODE                = "open-ils.actor:open-ils.actor.user.fleshed.retrieve_by_barcode";
264 var FETCH_ADV_MRIDS                             = "open-ils.search:open-ils.search.biblio.multiclass:1";
265 var FETCH_ADV_MARC_MRIDS                = "open-ils.search:open-ils.search.biblio.marc:1";
266 var FETCH_ADV_ISBN_MRIDS                = "open-ils.search:open-ils.search.biblio.isbn";
267 var FETCH_ADV_ISSN_MRIDS                = "open-ils.search:open-ils.search.biblio.issn";
268 var FETCH_CNBROWSE_TARGET               = 'open-ils.search:open-ils.search.callnumber.browse.target';
269 var FETCH_CNBROWSE_PREV                 = 'open-ils.search:open-ils.search.callnumber.browse.page_up';
270 var FETCH_CNBROWSE_NEXT                 = 'open-ils.search:open-ils.search.callnumber.browse.page_down';
271 var FETCH_CONTAINERS                            = 'open-ils.actor:open-ils.actor.container.retrieve_by_class';
272 var FETCH_CONTAINERS                            = 'open-ils.actor:open-ils.actor.container.retrieve_by_class';
273 var CREATE_CONTAINER                            = 'open-ils.actor:open-ils.actor.container.create';
274 var DELETE_CONTAINER                            = 'open-ils.actor:open-ils.actor.container.full_delete';
275 var CREATE_CONTAINER_ITEM               = 'open-ils.actor:open-ils.actor.container.item.create';
276 var DELETE_CONTAINER_ITEM               = 'open-ils.actor:open-ils.actor.container.item.delete';
277 var FLESH_CONTAINER                             = 'open-ils.actor:open-ils.actor.container.flesh';
278 var FLESH_PUBLIC_CONTAINER              = 'open-ils.actor:open-ils.actor.container.public.flesh';
279 var FETCH_COPY                                          = 'open-ils.search:open-ils.search.asset.copy.retrieve';
280 var CHECK_HOLD_POSSIBLE                 = 'open-ils.circ:open-ils.circ.title_hold.is_possible';
281 var FETCH_BIBLIO_NOTES                  = 'open-ils.circ:open-ils.circ.biblio_notes.public.batch.retrieve';
282 /* ---------------------------------------------------------------------------- */
283
284
285 /* ---------------------------------------------------------------------------- */
286 /* event callback functions. Other functions may be appended to these vars to
287         for added functionality.  */
288
289 G.evt                           = {}; /* events container */
290
291 function runEvt(scope, name, a, b, c, d, e, f, g) {
292         var evt = G.evt[scope][name];
293         for( var i in evt ) {
294                 evt[i](a, b, c, d, e, f, g);    
295         }
296 }
297
298 /* creates a new event if it doesn't already exist */
299 function createEvt(scope, name) {
300         if(!G.evt[scope]) G.evt[scope] = {};
301         if(G.evt[scope][name] == null)
302                 G.evt[scope][name] = []; 
303 }
304
305 function attachEvt(scope, name, action) {
306         createEvt(scope, name);
307         G.evt[scope][name].push(action);
308 }
309
310 function detachAllEvt(scope, name) {
311         G.evt[scope][name] = [];
312 }
313
314
315 createEvt("common", "init");                                            /* f() : what happens on page init */
316 createEvt("common", "pageRendered");                    /* f() : what happens when the page is done (up to the skin to call this even)*/
317 createEvt("common", "unload");                                  /* f() : what happens on window unload (clean memory, etc.)*/
318 createEvt("common", "locationChanged");         /* f() : what happens when the location has changed */
319 createEvt("common", "locationUpdated");         /* f() : what happens when the location has updated by the code */
320
321 createEvt("common", "run");                                             /* f() : make the page do stuff */
322 createEvt("result", "idsReceived");                             /* f(ids) */
323 createEvt("rresult", "recordDrawn");                    /* f(recordid, linkDOMNode) : after record is drawn, allow others (xul) to plugin actions */
324 createEvt("result", "preCollectRecords");               /* f() we're about to go and grab the recs */
325
326 createEvt("result", "hitCountReceived");                /* f() : display hit info, pagination, etc. */
327 createEvt("result", "recordReceived");                  /* f(mvr, pagePosition, isMr) : display the record*/
328 createEvt("result", "recordDrawn");                             /* f(recordid, linkDOMNode) : after record is drawn, allow others (xul) to plugin actions */
329 createEvt("result", "copyCountsReceived");      /* f(mvr, pagePosition, copyCountInfo) : display copy counts*/
330 createEvt("result", "allRecordsReceived");      /* f(mvrsArray) : add other page stuff, sidebars, etc.*/
331
332 createEvt("rdetail", "recordDrawn");                    /* f() : the record has been drawn */
333
334 createEvt("common", "loggedIn");                                        /* f() : user has just logged in */
335 createEvt('result', 'zeroHits');
336 createEvt('result', 'lowHits');
337 createEvt('rdetail', 'recordRetrieved');                        /* we are about to draw the rdetail page */
338 createEvt('common', 'depthChanged');
339
340
341
342
343