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