]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/GlobalInit.js
af0d2d7d22df86261bf03dc888c25f11ae88a1fe
[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                 globalSelectedLocation = findOrgUnit(paramObj.__location);
131                 if(globalSelectedLocation == null) 
132                         debug("Invalid location in url : " + paramObj.__location);
133                 else
134                         debug("Setting selected location to " + globalSelectedLocation.name() );
135         } 
136
137
138         if(paramObj.__depth != null) {
139                 debug("Passed in depth from search params: " + paramObj.__depth);
140                 globalSearchDepth = parseInt(paramObj.__depth);
141                 debug("Setting selected depth to " + globalSearchDepth );
142         }
143
144         globalPage.setLocDisplay();
145         globalPage.locationTree = globalOrgTreeWidget;
146         globalPage.setPageTrail();
147
148         if(globalSearchBarChunk)
149                 globalSearchBarChunk.reset();
150         
151         if( globalSearchBarFormChunk != null)
152                 globalSearchBarFormChunk.resetPage();
153
154
155
156 }
157
158
159 /* we only do this on loading of the outer frame (i.e. only once) */
160 function GlobalInitLoad() {
161
162         debug("Global Init is doing its primary load");
163         globalOrgTreeWidget = new LocationTree(globalOrgTree);
164
165         var ses = null;
166         var org = null;
167
168         if(isXUL()) {
169                 ses = G['auth_ses'][0]; /* G is shoved in by XUL */
170                 org = G['user_ou']; /* the desired location of the user */
171         }
172
173         if(paramObj.__logout) {
174                 doLogout();
175
176         } else {
177
178                 globalUser = UserSession.instance();
179                 if(globalUser.verifySession(ses)) {
180                         globalUser.grabOrgUnit(org);
181         
182                 } else  {
183                         globalUser = null;
184                         globalLocation = globalOrgTree;
185                         if(globalSearchDepth == null)
186                                 globalSearchDepth = findOrgDepth(globalOrgTree.ou_type());
187                 }
188         }
189
190         grabCopyStatus();
191
192 }
193
194 function grabCopyStatus() {
195         if(globalCopyStatus) return;
196
197         debug("Grabbing copy statuses");
198         var req = new RemoteRequest(
199                 "open-ils.search",
200                 "open-ils.search.config.copy_status.retrieve.all" );
201
202
203         //if(paramObj.__sub_frame) {
204                 req.send(true);
205                 globalCopyStatus = req.getResultObject();
206                 if(!globalCopyStatus) {
207                         userMessage("Retrieving copy statuses");
208                 }
209
210                 /*
211         } else {
212
213                 req.setCompleteCallback(function(r) { 
214                         debug("Got globalCopyStatus");
215                         globalCopyStatus = r.getResultObject(); });
216         
217                 req.send();
218         }
219         */
220 }
221
222
223