persisting font choice
[working/Evergreen.git] / Open-ILS / web / opac / common / js / config.js
1 /* Export some constants  ----------------------------------------------------- */
2
3 /* URL params */
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
15 /* cookies */
16 var COOKIE_SB = "sbe";
17 var COOKIE_SES = "ses";
18 var COOKIE_IDS  = "ids";
19 var COOKIE_FONT = "fnt";
20
21 /* these are the actual param values - set on page load */
22
23 /* pages */
24 var MRESULT             = "mresult";
25 var RRESULT             = "rresult";
26 var RDETAIL             = "rdetail";
27 var MYOPAC              = "myopac";
28 var ADVANCED    = "advanced";
29 var HOME                        = "home";
30
31 /* search type (STYPE) options */
32 STYPE_AUTHOR    = "author";
33 STYPE_TITLE             = "title";
34 STYPE_SUBJECT   = "subject";
35 STYPE_SERIES    = "series";
36 STYPE_KEYWORD   = "keyword";
37
38
39 /* container for global variables shared accross pages */
40 var G           = {};
41 G.user  = null; /* global user object */
42 G.ui            = {} /* cache of UI components */
43
44
45 /* call me after page init and I will load references 
46         to all of the ui object id's defined below 
47         They will be stored in G.ui.<page>.<thingy>
48  */
49 function loadUIObjects() {
50         for( var p in config.ids ) {
51                 G.ui[p] = {};
52                 for( var o in config.ids[p] ) 
53                         G.ui[p][o] = getId(config.ids[p][o]);
54         }
55 }
56
57 /* try our best to free memory */
58 function clearUIObjects() {
59         for( var p in config.ids ) {
60                 for( var o in config.ids[p] ) {
61                         if(G.ui[p][o]) {
62                                 G.ui[p][o].onclick = null;
63                                 G.ui[p][o].onkeydown = null;
64                                 G.ui[p][o] = null;
65                         }
66                 }
67                 G.ui[p] = null;
68         }
69 }
70
71 /* ---------------------------------------------------------------------------- 
72         Set up ID's and CSS classes 
73         Any new ids, css, etc. may be added by giving the unique names and putting 
74         them into the correct scope 
75 /* ---------------------------------------------------------------------------- */
76
77 var config = {};
78
79 /* Set up the page names */
80 config.page = {};
81 config.page[HOME]                       = "index.xml";
82 config.page[ADVANCED]   = "advanced.xml";
83 config.page[MRESULT]            = "mresult.xml";
84 config.page[RRESULT]            = "rresult.xml";
85 config.page[MYOPAC]             = "myopac.xml";
86 config.page[RDETAIL]            = "rdetail.xml";
87
88
89 /* set up images  */
90 config.images = {};
91 config.images.logo = "main_logo.jpg";
92
93
94 /* set up ID's, CSS, and node names */
95 config.ids                              = {};
96 config.ids.result               = {};
97 config.ids.mresult      = {};
98 config.ids.advanced     = {};
99 config.ids.rresult      = {};
100 config.ids.myopac               = {};
101 config.ids.rdetail      = {};
102
103 config.css                              = {};
104 config.css.result               = {};
105 config.css.mresult      = {};
106 config.css.advanced     = {};
107 config.css.rresult      = {};
108 config.css.myopac               = {};
109 config.css.rdetail      = {};
110
111 config.names                    = {};
112 config.names.result     = {};
113 config.names.mresult = {};
114 config.names.advanced = {};
115 config.names.rresult = {};
116 config.names.myopac     = {};
117 config.names.rdetail = {};
118
119
120 /* id's shared accross skins. These *must* be defined */
121 config.ids.common = {};
122 config.ids.common.loading                       = "loading_div";                
123 config.ids.common.canvas                        = "canvas";                             
124 config.ids.common.canvas_main           = "canvas_main";                
125 config.ids.common.org_tree                      = "org_tree";                   
126 config.ids.common.org_container = "org_container";
127
128
129 /* shared CSS */
130 config.css.hide_me = "hide_me";
131
132
133 /* ---------------------------------------------------------------------------- */
134 /* These are pages that may replace the canvas */
135 /* ---------------------------------------------------------------------------- */
136 config.ids.altcanvas = {};
137
138
139
140 /* ---------------------------------------------------------------------------- */
141 /* Methods are defined as service:method 
142         An optional 3rd component is when a method is followed by a :1, such methods
143         have a staff counterpart and should have ".staff" appended to the method 
144         before the method is called when in XUL mode */
145
146 var FETCH_MRCOUNT                               = "open-ils.search:open-ils.search.biblio.class.count:1";
147 var FETCH_MRIDS                         = "open-ils.search:open-ils.search.biblio.class:1";
148 var FETCH_MRIDS_FULL                    = "open-ils.search:open-ils.search.biblio.class.full:1";
149 var FETCH_MRMODS                                = "open-ils.search:open-ils.search.biblio.metarecord.mods_slim.retrieve";
150 var FETCH_MR_COPY_COUNTS        = "open-ils.search:open-ils.search.biblio.metarecord.copy_count:1";
151 var FETCH_RIDS                                  = "open-ils.search:open-ils.search.biblio.metarecord_to_records:1";
152 var FETCH_RMODS                         = "open-ils.search:open-ils.search.biblio.record.mods_slim.retrieve";
153 var FETCH_R_COPY_COUNTS         = "open-ils.search:open-ils.search.biblio.record.copy_count";
154 var FETCH_FLESHED_USER          = "open-ils.actor:open-ils.actor.user.fleshed.retrieve";
155 var FETCH_SESSION                               = "open-ils.auth:open-ils.auth.session.retrieve";
156 var LOGIN_INIT                                  = "open-ils.auth:open-ils.auth.authenticate.init";
157 var LOGIN_COMPLETE                      = "open-ils.auth:open-ils.auth.authenticate.complete";
158 var LOGIN_DELETE                                = "open-ils.auth:open-ils.auth.session.delete";
159 /* ---------------------------------------------------------------------------- */
160
161
162
163 /* ---------------------------------------------------------------------------- */
164 /* event callback functions. Other functions may be appended to these vars to
165         for added functionality.  */
166
167 G.evt                           = {}; /* events container */
168
169 function runEvt(scope, name, a, b, c, d, e, f, g) {
170         var evt = G.evt[scope][name];
171         for( var i in evt ) evt[i](a, b, c, d, e, f, g);        
172 }
173
174 /* creates a new event if it doesn't already exist */
175 function createEvt(scope, name) {
176         if(!G.evt[scope]) G.evt[scope] = {};
177         if(G.evt[scope][name] == null)
178                 G.evt[scope][name] = []; 
179 }
180
181 function attachEvt(scope, name, action) {
182         createEvt(scope, name);
183         G.evt[scope][name].push(action);
184 }
185
186 createEvt("common", "init");                                            /* f() : what happens on page init */
187 createEvt("common", "pageRendered");                    /* f() : what happens when the page is done (up to the skin to call this even)*/
188 createEvt("common", "unload");                                  /* f() : what happens on window unload (clean memory, etc.)*/
189 createEvt("mresult", "run");                                            /* f() : kick of the page*/
190 createEvt("mresult", "idsReceived");                    /* f(ids) */
191 createEvt("rresult", "run");                                            /* f() : kick of the page*/
192 createEvt("rresult", "idsReceived");                    /* f(ids) */    
193
194 createEvt("result", "hitCountReceived");                /* f() : display hit info, pagination, etc. */
195 createEvt("result", "recordReceived");                  /* f(mvr, pagePosition, isMr) : display the record*/
196 createEvt("result", "copyCountsReceived");      /* f(mvr, pagePosition, copyCountInfo) : display copy counts*/
197 createEvt("result", "allRecordsReceived");      /* f(mvrsArray) : add other page stuff, sidebars, etc.*/
198
199
200
201