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