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