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