]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/GlobalInit.js
f82cebebe7aff03aa359d16371f905e78058cdd6
[Evergreen.git] / Open-ILS / src / javascript / opac / GlobalInit.js
1 /* */
2
3 var globalPage                                          = null; /* the current top level page object */
4 var globalUser                                          = null; /* the user session */
5 var globalOrgTreeWidget                 = null;
6 var globalLocation                              = null;
7 var globalOrgTreeWidgetBox              = null;
8 var globalSelectedLocation              = null;
9 var globalSearchDepth                   = null;
10 var globalMenuManager                   = null;
11 var globalCopyStatus                            = null;
12 var locationStack                                       = new Array();
13 var globalCopyLocations                 = null;
14
15 var lastSearchString                            = null;
16 var lastSearchType                              = null;
17
18 /* this is true if we directed to the record detail page
19         becuase of only having one hit on the record result
20         page.  this allows us to back up from the detail
21         page to the mr_result page */
22 var recordResultRedirect = false;
23
24 var loaded = false;
25
26
27 function addLocation(type, title) {
28         try { 
29                 if(globalAppFrame) {
30                         var obj = new Object();
31                         obj.location = globalAppFrame.location.href;
32                         obj.title = title;
33                         locationStack[type] = obj;
34                 }
35         } catch(E){}
36
37 }
38
39 function _test() {
40         debug("At: " + (new RegExp(".+").exec(
41                         arguments.callee.toString()))[0].replace("{", "") );
42 }
43
44
45 function globalInit() {
46
47
48         _test();
49         debug(" --- XUL IS " + isXUL() );
50
51
52         if( isXUL() && globalAppFrame )
53                 globalAppFrame.document.body.style.background = "#FFF";
54
55         getDocument().body.onunload = cleanIEMemory;
56
57
58         var page_name = globalPageTarget;
59
60         if(!page_name) 
61                 throw new EXArg("globalInit requires globalPageTarget to be set");
62
63         debug("globalInit init-ing page: " + page_name );
64
65         switch( page_name ) {
66
67                 case "start":
68                         globalPage = new OPACStartPage();
69                         addLocation("start", "Home");
70                         locationStack["advanced_search"] = null;
71                         break;
72
73                 case  "advanced_search":
74                         globalPage = new AdvancedSearchPage();
75                         addLocation("advanced_search", "Advanced Search");
76                         locationStack["start"] = null;
77                         break;
78
79                 case  "mr_result":
80                         //globalPage = new MRResultPage();
81                         globalPage = MRResultPage.instance();
82                         addLocation("mr_result", "Title Group Results");
83                         break;
84
85                 case  "record_result":
86                         //globalPage = new RecordResultPage();
87                         globalPage = RecordResultPage.instance();
88                         addLocation("record_result", "Title Results");
89                         break;
90
91                 case  "login":
92                         globalPage = new LoginPage();
93                         break;
94
95                 case  "logout":
96                         globalPage = new LogoutPage();
97                         break;
98
99                 case  "my_opac":
100                         globalPage = new MyOPACPage();
101                         break;
102
103                 case "record_detail":
104                         globalPage = new RecordDetailPage();
105                         addLocation("record_detail", "Title Details");
106                         break;
107
108                 case  "about":
109                         globalPage = new AboutPage();
110                         break;
111
112                 }
113
114         if( ! globalPage ) 
115                 throw new EXArg(
116                         "globalInit requires a valid page target: " + page_name );
117
118         if(!loaded) { loaded = true; GlobalInitLoad(); }
119
120         globalMenuManager = new ContextMenuManager();
121
122         /* hide all context menus on body click */
123         getDocument().body.onclick = function() {
124                         globalMenuManager.hideAll(); 
125         }
126
127         globalPage.init();
128
129         if(paramObj.__location != null) {
130                 debug("Someone passed us a location ID of " + paramObj.__location);
131
132                 globalSelectedLocation = findOrgUnit(paramObj.__location);
133
134                 if(paramObj.__depth == null) {
135                         paramObj.__depth = findOrgType(globalSelectedLocation.ou_type()).depth();
136                 }
137
138                 if(globalSelectedLocation == null) 
139                         debug("Invalid location in url : " + paramObj.__location);
140                 else
141                         debug("Setting selected location to " + globalSelectedLocation.name() );
142
143         } else {
144                 debug("No location provided in URL");
145         }
146
147
148         if(paramObj.__depth != null) {
149                 debug("Passed in depth from search params: " + paramObj.__depth);
150                 globalSearchDepth = parseInt(paramObj.__depth);
151                 debug("Setting selected depth to " + globalSearchDepth );
152         }
153
154         globalPage.setLocDisplay();
155         globalPage.locationTree = globalOrgTreeWidget;
156         globalPage.setPageTrail();
157
158         if(globalSearchBarChunk)
159                 globalSearchBarChunk.reset();
160         
161         if( globalSearchBarFormChunk != null)
162                 globalSearchBarFormChunk.resetPage();
163
164
165
166 }
167
168
169 /* we only do this on loading of the outer frame (i.e. only once) */
170 function GlobalInitLoad() {
171
172         debug("Global Init is doing its primary load");
173         globalOrgTreeWidget = new LocationTree(globalOrgTree);
174
175         var ses = null;
176         var org = null;
177
178         if(isXUL()) {
179                 ses = G['auth_ses'][0]; /* G is shoved in by XUL */
180                 org = G['user_ou']; /* the desired location of the user */
181         }
182
183         if(paramObj.__logout) {
184                 doLogout();
185
186         } else {
187
188                 globalUser = UserSession.instance();
189                 if(globalUser.verifySession(ses)) {
190                         globalUser.grabOrgUnit(org);
191         
192                 } else  {
193                         globalUser = null;
194                         globalLocation = globalOrgTree;
195                         if(globalSearchDepth == null)
196                                 globalSearchDepth = findOrgDepth(globalOrgTree.ou_type());
197                 }
198         }
199
200         grabCopyStatus();
201
202 }
203
204 function grabCopyStatus() {
205         if(globalCopyStatus) return;
206
207         debug("Grabbing copy statuses");
208         var req = new RemoteRequest(
209                 "open-ils.search",
210                 "open-ils.search.config.copy_status.retrieve.all" );
211
212
213         //if(paramObj.__sub_frame) {
214                 req.send(true);
215                 globalCopyStatus = req.getResultObject();
216                 if(!globalCopyStatus) {
217                         userMessage("Retrieving copy statuses");
218                 }
219
220                 /*
221         } else {
222
223                 req.setCompleteCallback(function(r) { 
224                         debug("Got globalCopyStatus");
225                         globalCopyStatus = r.getResultObject(); });
226         
227                 req.send();
228         }
229         */
230 }
231
232
233