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