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